Submission #502453

#TimeUsernameProblemLanguageResultExecution timeMemory
502453zoriankaDango Maker (JOI18_dango_maker)C++17
100 / 100
1321 ms244096 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC optimize("fast-math") //#pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; using ll = long long; vector<vector<int>> L; vector<int> matched; vector<int> used; vector<bool> da; int cnt = 1; int sz = 0; int szR = 0; bool dfs(int v) { if (used[v] == cnt) return false; used[v] = cnt; for (int u : L[v]) { auto &m = matched[u]; if (matched[u] == -1 || dfs(m)) { matched[u] = v; da[v] = true; return true; } } return false; } void solve() { int n, m; cin >> n >> m; vector<string> d(n); vector<vector<int>> comp(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < n - 2; i++) for (int j = 0; j < m; j++) { if (d[i][j] == 'R' && d[i + 1][j] == 'G' && d[i + 2][j] == 'W') { comp[i][j] = comp[i + 1][j] = comp[i + 2][j] = sz++; } } L.resize(sz); for (int i = 0; i < n; i++) { for (int j = 0; j < m - 2; j++) { if (d[i][j] == 'R' && d[i][j + 1] == 'G' && d[i][j + 2] == 'W') { int cur = szR++; for (int dj = 0; dj < 3; dj++) { if (comp[i][j + dj] != -1) { L[comp[i][j + dj]].push_back(cur); } } } } } matched.resize(szR, -1); used.resize(sz); da.resize(sz); for (int v = 0; v < sz; v++) { if (L[v].empty()) continue; int u = L[v][0]; if (matched[u] == -1) { matched[u] = v; da[v] = true; } } for (int v = 0; v < sz; v++) { if (!da[v] && dfs(v)) cnt++; } int ans = 0; for (int v = 0; v < sz; v++) ans += da[v]; cout << sz + szR - ans; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...