Submission #254689

#TimeUsernameProblemLanguageResultExecution timeMemory
254689egekabasDango Maker (JOI18_dango_maker)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; int n, m; int a[3009][3009]; int l1[3009][3009]; int u1[3009][3009]; pii b1[3009][3009]; pii b2[3009][3009]; int vis[3009][3009]; int st; int dfs(pii x){ if(x.ff == 1e9){ st = 1; return 0; } if(x.ff == -1) return 0; if(vis[x.ff][x.ss]) return 0; vis[x.ff][x.ss] = 1; int ret = 1; ret += dfs(b1[x.ff][x.ss])+dfs(b2[x.ff][x.ss]); return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n >> m; string s; for(int i = 0; i < n; ++i){ cin >> s; for(int j = 0; j < m; ++j){ switch(s[j]){ case 'R': a[i][j] = 1; break; case 'G': a[i][j] = 2; break; case 'W': a[i][j] = 3; break; } } } for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j){ if(a[i][j] == 1){ l1[i][j+1] = 1; u1[i+1][j] = 1; } b1[i][j] = {-1, -1}; b2[i][j] = {-1, -1}; } for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j){ if(a[i][j] != 2) continue; if(l1[i][j] && u1[i][j] && a[i+1][j] == 3 && a[i][j+1] == 3){ b1[i+1][j] = {i, j+1}; b2[i][j+1] = {i+1, j}; } else if(l1[i][j]) b2[i][j+1] = {1e9, 1e9}; else if(u1[i][j]) b1[i+1][j] = {1e9, 1e9}; } int ans = 0; for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) if(vis[i][j] == 0 && a[i][j] == 3){ st = 0; ans += dfs({i, j})-1+st; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...