Submission #958839

#TimeUsernameProblemLanguageResultExecution timeMemory
958839vjudge1Dango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms600 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]; 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'; } } auto isBlue = [&](ll i, ll j) { // 0 <= i < n // 0 <= j < m-2 if (m-2 <= j) return false; return mat[i][j] == '1' && mat[i][j+1] == '2' && mat[i][j+2] == '3'; }; auto isRed = [&](ll i, ll j) { // 0 <= i < n-2 // 0 <= j < m if (n-2 <= i) return false; return mat[i][j] == '1' && mat[i+1][j] == '2' && mat[i+2][j] == '3'; }; ll ans = 0; for (ll sum = 0; sum <= n+m-2; sum++) { ll il = max(0LL, sum-m+1), ir = min(n, sum+1); DSU dsu(ir-il+16); for (ll i = il-5; i < ir+5; i++) { ll j = sum-i; if (0 <= i && i < n && 0 <= j && j < m) { if (isBlue(i, j)) { dsu.makeBlue(j); dsu.join(j+2, j+1); dsu.join(j+1, j); } if (isRed(i, j)) { dsu.makeRed(j); dsu.join(j+2, j+3); dsu.join(j+3, j+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...