Submission #69672968
Source Code Expand
// Problem: 'D - Ulam-Warburton Automaton' // Contest: 'AtCoder - UNIQUE VISION Programming Contest 2024 Autumn (AtCoder Beginner Contest 425)' // URL: 'https://atcoder.jp/contests/abc425/tasks/abc425_d' // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by competitive-companion.el (https://github.com/luishgh/competitive-companion.el) #include <bits/stdc++.h> using namespace std; #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' typedef long long ll; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; vector<vector<int>> d; vector<vector<bool>> vis, bl; vector<vector<int>> g; int h, w; queue<pair<int, int>> q; queue<pair<int, int>> q2; const vector<pair<int, int>> moves = { {-1, 0}, {+1, 0}, {0,-1}, {0, +1} }; void bfs() { while (q.size() or q2.size()) { while (q.size()) { auto [x, y] = q.front(); q.pop(); if (vis[x][y]) continue; vis[x][y] = true; for (auto [dx, dy] : moves) { int wx = x + dx, wy = y + dy; if (wx < 0 or wx >= h or wy < 0 or wy >= w) continue; if (d[wx][wy] < d[x][y] + 1) continue; if (d[x][y] + 1 == d[wx][wy]) { // cerr << x+1 << ' ' << y+1 << " BLOCKS " << wx+ 1<< ' ' << wy+1 << endl; bl[wx][wy] = true; } else { bl[wx][wy] = false; d[wx][wy] = d[x][y] + 1; q2.emplace(wx, wy); } } } while (q2.size()) { auto [x, y] = q2.front(); q2.pop(); if (!bl[x][y]) q.emplace(x, y); // else cerr << x << ' ' << y << endl; } } } int main() {_; cin >> h >> w; g = vector(h, vector<int>(w)); d = vector(h, vector<int>(w)); vis = vector(h, vector<bool>(w)); bl = vector(h, vector<bool>(w)); for (int i = 0; i < h; i++) { string line; cin >> line; for (int j = 0; j < w; j++) { if (line[j] == '#') { g[i][j] = 1; q.emplace(i, j); d[i][j] = 0; } else g[i][j] = 0, d[i][j] = INF; } } bfs(); ll ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // if (!vis[i*h + j]) cerr << '.'; // else cerr << '#'; if (vis[i][j]) ans++; } // cerr << endl; } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Ulam-Warburton Automaton |
User | luishgh |
Language | C++ 20 (gcc 12.2) |
Score | 425 |
Code Size | 2373 Byte |
Status | AC |
Exec Time | 31 ms |
Memory | 28068 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 | 3448 KiB |
00_sample_01.txt | AC | 1 ms | 3604 KiB |
00_sample_02.txt | AC | 1 ms | 3392 KiB |
01_test_00.txt | AC | 11 ms | 6448 KiB |
01_test_01.txt | AC | 6 ms | 5336 KiB |
01_test_02.txt | AC | 8 ms | 6404 KiB |
01_test_03.txt | AC | 10 ms | 6784 KiB |
01_test_04.txt | AC | 12 ms | 7032 KiB |
01_test_05.txt | AC | 12 ms | 7572 KiB |
01_test_06.txt | AC | 13 ms | 7536 KiB |
01_test_07.txt | AC | 12 ms | 7512 KiB |
01_test_08.txt | AC | 13 ms | 6788 KiB |
01_test_09.txt | AC | 13 ms | 6876 KiB |
01_test_10.txt | AC | 7 ms | 6080 KiB |
01_test_11.txt | AC | 8 ms | 6112 KiB |
01_test_12.txt | AC | 9 ms | 6256 KiB |
01_test_13.txt | AC | 9 ms | 6132 KiB |
01_test_14.txt | AC | 9 ms | 6084 KiB |
01_test_15.txt | AC | 10 ms | 6140 KiB |
01_test_16.txt | AC | 10 ms | 6192 KiB |
01_test_17.txt | AC | 11 ms | 6372 KiB |
01_test_18.txt | AC | 11 ms | 6336 KiB |
01_test_19.txt | AC | 12 ms | 6652 KiB |
01_test_20.txt | AC | 8 ms | 5656 KiB |
01_test_21.txt | AC | 8 ms | 6272 KiB |
01_test_22.txt | AC | 9 ms | 5676 KiB |
01_test_23.txt | AC | 9 ms | 5652 KiB |
01_test_24.txt | AC | 9 ms | 5740 KiB |
01_test_25.txt | AC | 9 ms | 5672 KiB |
01_test_26.txt | AC | 9 ms | 5640 KiB |
01_test_27.txt | AC | 10 ms | 5640 KiB |
01_test_28.txt | AC | 15 ms | 12508 KiB |
01_test_29.txt | AC | 30 ms | 28068 KiB |
01_test_30.txt | AC | 19 ms | 15452 KiB |
01_test_31.txt | AC | 23 ms | 15160 KiB |
01_test_32.txt | AC | 31 ms | 17960 KiB |
01_test_33.txt | AC | 27 ms | 15664 KiB |
01_test_34.txt | AC | 23 ms | 14052 KiB |
01_test_35.txt | AC | 21 ms | 12856 KiB |
01_test_36.txt | AC | 9 ms | 6224 KiB |