Submission #886864

#TimeUsernameProblemLanguageResultExecution timeMemory
886864NeroZeinDango Maker (JOI18_dango_maker)C++17
33 / 100
222 ms262144 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif const int N = 3003; char c[N][N]; int used[N][N]; vector<set<int>> g; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> c[i][j]; } } int tmp = 0, num = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m - 2; ++j) { if (c[i][j] == 'R' && c[i][j + 1] == 'G' && c[i][j + 2] == 'W') { tmp++; num++; used[i][j] = used[i][j + 1] = used[i][j + 2] = num; } } } int original = num; g.resize(original + 1); vector<bool> in_que(num + 1); for (int i = 0; i < n - 2; ++i) { for (int j = 0; j < m; ++j) { if (c[i][j] == 'R' && c[i + 1][j] == 'G' && c[i + 2][j] == 'W') { num++; g.push_back({}); for (int k = 0; k < 3; ++k) { if (used[i + k][j]) { g[num].insert(used[i + k][j]); g[used[i + k][j]].insert(num); } } if (g[num].size() == 0) { tmp++; } } } } int ans = tmp; queue<int> que; for (int i = 1; i <= original; ++i) { for (int u : g[i]) { if (g[u].size() == 1) { in_que[i] = true; que.push(i); break; } } } while (!que.empty()) { int v = que.front(); que.pop(); ans--; for (int u : g[v]) { g[u].erase(v); if (g[u].size() == 0) { ans++; } else if (g[u].size() == 1) { assert(!g[u].empty()); int z = *g[u].begin(); if (!in_que[z]) { que.push(*g[u].begin()); assert(z <= original); in_que[z] = true; } } } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...