Submission #330217

#TimeUsernameProblemLanguageResultExecution timeMemory
330217casperwangDango Maker (JOI18_dango_maker)C++14
33 / 100
558 ms262148 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int MAXN = 3000; const int MAXM = 3000*3000; int n, m; string mp[MAXN+1], ss; int p[MAXN+1][MAXN+1]; int a, b; int ans; vector <vector<int>> pathA, pathB; int degA[MAXM+1]; int degB[MAXM+1]; bool visA[MAXM+1]; bool visB[MAXM+1]; void DFS(int now) { for (int i : pathB[now]) { if (visA[i]) continue; degA[i]--; visA[i] = 1; ans--; for (int j : pathA[i]) { if (visB[j]) continue; degB[j]--; if (degB[j] == 1) { visB[j] = 1; DFS(j); } } } } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> ss; mp[i] = ' ' + ss; } pathA.pb(vector<int>()); pathB.pb(vector<int>()); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (i >= 3 && mp[i][j] == 'W' && mp[i-1][j] == 'G' && mp[i-2][j] == 'R') { a++; pathA.pb(vector<int>()); p[i][j] = p[i-1][j] = p[i-2][j] = a; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j >= 3 && mp[i][j] == 'W' && mp[i][j-1] == 'G' && mp[i][j-2] == 'R') { b++, pathB.pb(vector<int>()); if (p[i][j]) { pathB[b].pb(p[i][j]); degB[b]++; pathA[p[i][j]].pb(b); degA[p[i][j]]++; } if (p[i][j-1]) { pathB[b].pb(p[i][j-1]); degB[b]++; pathA[p[i][j-1]].pb(b); degA[p[i][j-1]]++; } if (p[i][j-2]) { pathB[b].pb(p[i][j-2]); degB[b]++; pathA[p[i][j-2]].pb(b); degA[p[i][j-2]]++; } } } } ans = a+b; for (int i = 1; i <= b; i++) { if (degB[i] == 1 && !visB[i]) { visB[i] = 1; DFS(i); } } for (int i = 1; i <= b; i++) { if (degB[i] > 1) ans--; } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...