Submission #69665908
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int H, W;
signed main() {
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; ++i) {
cin >> S[i];
}
int k = 0;
vector<PI> P;
while (true) {
vector<PI> Q;
if (k == 0) {
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (S[i][j] == '.') {
int cnt = 0;
for (int k = 0; k < 4; ++k) {
int ni = i + dy[k];
int nj = j + dx[k];
if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
if (S[ni][nj] == '#') {
cnt++;
}
}
if (cnt == 1) {
Q.push_back({i, j});
}
}
}
}
} else {
for (auto p : P) {
int i = p.first;
int j = p.second;
for (int k = 0; k < 4; ++k) {
int ni = i + dy[k];
int nj = j + dx[k];
if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
if (S[ni][nj] == '#') continue;
int cnt = 0;
for (int l = 0; l < 4; ++l) {
int nni = ni + dy[l];
int nnj = nj + dx[l];
if (nni < 0 || nni >= H || nnj < 0 || nnj >= W) continue;
if (S[nni][nnj] == '#') {
cnt++;
}
}
if (cnt == 1) {
Q.push_back({ni, nj});
}
}
}
}
if (Q.size() == 0) break;
for (auto p : Q) {
S[p.first][p.second] = '#';
}
// cout << "-----" << endl;
// for (int i = 0; i < H; ++i) {
// cout << S[i] << endl;
// }
// cout << "-----" << endl;
P = Q;
k++;
}
int ans = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (S[i][j] == '#') {
ans++;
}
}
}
cout << ans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Ulam-Warburton Automaton |
| User | tsuyosshi |
| Language | C++ 20 (gcc 12.2) |
| Score | 425 |
| Code Size | 3346 Byte |
| Status | AC |
| Exec Time | 21 ms |
| Memory | 6756 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 425 / 425 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3504 KiB |
| 00_sample_01.txt | AC | 1 ms | 3484 KiB |
| 00_sample_02.txt | AC | 1 ms | 3692 KiB |
| 01_test_00.txt | AC | 13 ms | 6004 KiB |
| 01_test_01.txt | AC | 4 ms | 3944 KiB |
| 01_test_02.txt | AC | 5 ms | 3792 KiB |
| 01_test_03.txt | AC | 8 ms | 4704 KiB |
| 01_test_04.txt | AC | 14 ms | 6228 KiB |
| 01_test_05.txt | AC | 8 ms | 4612 KiB |
| 01_test_06.txt | AC | 8 ms | 4400 KiB |
| 01_test_07.txt | AC | 8 ms | 4264 KiB |
| 01_test_08.txt | AC | 17 ms | 6424 KiB |
| 01_test_09.txt | AC | 16 ms | 6756 KiB |
| 01_test_10.txt | AC | 11 ms | 4176 KiB |
| 01_test_11.txt | AC | 12 ms | 4292 KiB |
| 01_test_12.txt | AC | 13 ms | 4612 KiB |
| 01_test_13.txt | AC | 13 ms | 4576 KiB |
| 01_test_14.txt | AC | 13 ms | 4500 KiB |
| 01_test_15.txt | AC | 14 ms | 4936 KiB |
| 01_test_16.txt | AC | 14 ms | 5092 KiB |
| 01_test_17.txt | AC | 16 ms | 5640 KiB |
| 01_test_18.txt | AC | 17 ms | 5716 KiB |
| 01_test_19.txt | AC | 17 ms | 6468 KiB |
| 01_test_20.txt | AC | 13 ms | 3636 KiB |
| 01_test_21.txt | AC | 12 ms | 3740 KiB |
| 01_test_22.txt | AC | 12 ms | 3824 KiB |
| 01_test_23.txt | AC | 12 ms | 3640 KiB |
| 01_test_24.txt | AC | 12 ms | 4040 KiB |
| 01_test_25.txt | AC | 12 ms | 4024 KiB |
| 01_test_26.txt | AC | 12 ms | 4056 KiB |
| 01_test_27.txt | AC | 13 ms | 4644 KiB |
| 01_test_28.txt | AC | 16 ms | 4152 KiB |
| 01_test_29.txt | AC | 21 ms | 6368 KiB |
| 01_test_30.txt | AC | 16 ms | 4740 KiB |
| 01_test_31.txt | AC | 16 ms | 4440 KiB |
| 01_test_32.txt | AC | 16 ms | 5180 KiB |
| 01_test_33.txt | AC | 16 ms | 4988 KiB |
| 01_test_34.txt | AC | 16 ms | 5140 KiB |
| 01_test_35.txt | AC | 17 ms | 5468 KiB |
| 01_test_36.txt | AC | 14 ms | 3696 KiB |