제출 #770276

#제출 시각아이디문제언어결과실행 시간메모리
770276gun_ganDango Maker (JOI18_dango_maker)C++17
13 / 100
135 ms248040 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 3005; int N, M; string c[MX]; int h[MX][MX], v[MX][MX]; vector<int> g[MX * MX]; int col[MX * MX]; int w = 0, b = 0; void dfs(int v) { if(col[v]) b++; else w++; assert(col[v] != 2); for(auto u : g[v]) { if(col[u] == 2) { col[u] = col[v] ^ 1; dfs(u); } else { assert(col[u] == (col[v] ^ 1)); } } } int main() { cin.tie(0); ios_base::sync_with_stdio(0); for(int i = 0; i < MX * MX; i++) col[i] = 2; cin >> N >> M; for(int i = 0; i < N; i++) { cin >> c[i]; } // build hori int cnt = 0; for(int i = 0; i < N; i++) { for(int j = 0; j + 2 < M; j++) { if(c[i][j] == 'R' && c[i][j + 1] == 'G' && c[i][j + 2] == 'W') { cnt++; assert(h[i][j] == 0 && h[i][j + 1] == 0 && h[i][j + 2] == 0); h[i][j] = h[i][j + 1] = h[i][j + 2] = cnt; j += 2; } } } // build vert for(int j = 0; j < M; j++) { for(int i = 0; i + 2 < N; i++) { if(c[i][j] == 'R' && c[i + 1][j] == 'G' && c[i + 2][j] == 'W') { cnt++; assert(v[i][j] == 0 && v[i + 1][j] == 0 && v[i + 2][j] == 0); v[i][j] = v[i + 1][j] = v[i + 2][j] = cnt; i += 2; } } } for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { if(h[i][j] && v[i][j]) { g[h[i][j]].push_back(v[i][j]); g[v[i][j]].push_back(h[i][j]); } } } assert(cnt <= 2 * N * M / 3); // traverse graph int ans = 0; for(int i = 1; i <= cnt; i++) { if(col[i] == 2) { col[i] = 0; w = 0, b = 0; dfs(i); ans += max(w, b); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...