Submission #1083930

#TimeUsernameProblemLanguageResultExecution timeMemory
1083930May27_thDango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms452 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() void Solve(void) { int N, M; cin >> N >> M; vector<vector<char>> g(N + 1, vector<char> (M + 1)); auto isDangoRow = [&](int i, int j) { return (g[i][j - 2] == 'R' && g[i][j - 1] == 'G' && g[i][j] == 'W'); }; auto isDangoCol = [&](int i, int j) { return (g[i - 2][j] == 'R' && g[i - 1][j] == 'G' && g[i][j] == 'W'); }; map<pair<int, int>, int> lab; vector<vector<int>> G(N * M + 3); vector<bool> used(N * M + 3, false); int cnt = 0; for (int i = 1; i <= N; i ++) { for (int j = 1; j <= M; j ++) { cin >> g[i][j]; if (j >= 3 && isDangoRow(i, j)) lab[mp(i, j)] = ++ cnt; if (i >= 3 && isDangoCol(i, j)) { lab[mp(-i, j)] = ++ cnt; if (j >= 3 && isDangoRow(i, j)) { G[lab[mp(-i, j)]].pb(lab[mp(i, j)]); G[lab[mp(i, j)]].pb(lab[mp(-i, j)]); } if (i > 1 && j >= 2 && j + 1 <= M && isDangoRow(i - 1, j + 1)) { G[lab[mp(-i, j)]].pb(lab[mp(i - 1, j + 1)]); G[lab[mp(i - 1, j + 1)]].pb(lab[mp(-i, j)]); } if (i > 2 && j >= 1 && j + 2 <= M && isDangoRow(i - 2, j + 2)) { G[lab[mp(-i, j)]].pb(lab[mp(i - 2, j + 2)]); G[lab[mp(i - 2, j + 2)]].pb(lab[mp(-i, j)]); } } } } vector<pair<int, int>> v; for (int i = 1; i <= N; i ++) { for (int j = 1; j <= M; j ++) { if (j >= 3 && isDangoRow(i, j)) { // cout << "Row " << i << " " << j << "\n"; int V = lab[mp(i, j)]; v.pb(mp((int)G[V].size(), V)); } if (i >= 3 && isDangoCol(i, j)) { // cout << "Col " << i << " " << j << "\n"; int V = lab[mp(-i, j)]; v.pb(mp((int)G[V].size(), V)); } } } sort(all(v)); int ans = 0; for (auto [d, V] : v) { // cout << V << "\n"; if (used[V]) continue; ans ++; used[V] = true; for (auto U : G[V]) { used[U] = true; } } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int Tests = 1; // cin >> Tests; while (Tests --) { Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...