Submission #958842

#TimeUsernameProblemLanguageResultExecution timeMemory
958842vjudge1Dango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; const ll MAXN = 3E3+16; char mat[MAXN][MAXN]; vector <pair <int, int> > th[2*MAXN]; struct DSU { vll par, sz; vll blue, red; ll n; DSU (ll n): par(n), sz(n, 1), blue(n, 0), red(n, 0), n(n) { iota(par.begin(), par.end(), 0); } ll find (ll u) { return (u == par[u] ? u : par[u] = find(par[u])); } void join (ll u, ll v) { u = find(u); v = find(v); if (u == v) return; if (sz[u] > sz[v]) swap(u, v); par[u] = v; sz[v] += sz[u]; blue[v] += blue[u]; red[v] += red[u]; } void makeRed (ll u) { red[find(u)]++; } void makeBlue (ll u) { blue[find(u)]++; } }; int main () { cin.tie(nullptr) -> sync_with_stdio(false); ll n, m; cin >> n >> m; for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { cin >> mat[i][j]; if (mat[i][j] == 'R') mat[i][j] = '1'; if (mat[i][j] == 'G') mat[i][j] = '2'; if (mat[i][j] == 'W') mat[i][j] = '3'; th[i+j].push_back({ i, j }); } } auto isBlue = [&](ll i, ll j) { if (0 <= i && i < n) if (0 <= j && j+2 < m) return mat[i][j] == '1' && mat[i][j+1] == '2' && mat[i][j+2] == '3'; return false; }; auto isRed = [&](ll i, ll j) { if (0 <= i && i+2 < n) if (0 <= j && j < m) return mat[i][j] == '1' && mat[i+1][j] == '2' && mat[i+2][j] == '3'; return false; }; ll ans = 0; for (ll sum = 0; sum <= n+m; sum++) { if (!th[sum].size()) continue; DSU dsu(th[sum].size()+15); int off = 1E9; for (auto [i, j] : th[sum]) off = min(off, j); for (auto [i, j] : th[sum]) { if (isBlue(i, j)) { dsu.makeBlue(j-off); dsu.join(j-off+2, j-off+1); dsu.join(j-off+1, j-off); } if (isRed(i, j)) { dsu.makeRed(j-off); dsu.join(j-off+2, j-off+3); dsu.join(j-off+3, j-off+4); } } for (ll i = 0; i < dsu.n; i++) { if (dsu.par[i] == i) ans += max(dsu.blue[i], dsu.red[i]); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...