제출 #704530

#제출 시각아이디문제언어결과실행 시간메모리
704530KenIsGeniusDango Maker (JOI18_dango_maker)C++17
0 / 100
103 ms262144 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) (x).begin(), (x).end() #define ll long long using namespace std; #ifdef LOCAL #define WOSAOJI freopen("in.txt", "r", stdin); #else #define WOSAOJI ios_base::sync_with_stdio(0), cin.tie(0); #endif #define chmax(a, b) (a) = (a) > (b) ? (a) : (b) #define chmin(a, b) (a) = (a) < (b) ? (a) : (b) int n, m, cnt; char c[3005][3005]; int a[3005][3005]; vector<int> adj[18000005]; int match[18000005]; void add_edge(int a, int b) { adj[a].pb(b); adj[b].pb(a); } bool crow(int i, int j) { int ok = 1; ok &= (c[i][j - 2] == 'R'); ok &= (c[i][j - 1] == 'G'); ok &= (c[i][j ] == 'W'); return ok; } bool col(int i, int j) { int ok = 1; ok &= (c[i - 2][j] == 'R'); ok &= (c[i - 1][j] == 'G'); ok &= (c[i ][j] == 'W'); return ok; } void dfs(int x, int v) { match[x] = v; for (int i : adj[x]) { if (match[i] == v) { dfs(i, v ^ 1); return; } } } signed main() { WOSAOJI cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (j >= 3 and crow(i, j)) { cnt++; a[i][j] = a[i][j - 1] = a[i][j - 2] = cnt; } } } for (int i = 3; i <= n; i++) { for (int j = 1; j <= m; j++) { if (col(i, j)) { cnt++; if (a[i - 2][j]) add_edge(a[i - 2][j], cnt); if (a[i - 1][j]) add_edge(a[i - 1][j], cnt); if (a[i ][j]) add_edge(a[i ][j], cnt); } } } for (int i = 1; i <= cnt; i++) { if (!match[i]) dfs(i, 1); } int ans = 0; for (int i = 1; i <= cnt; i++) { ans += match[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...