Submission #1090095

#TimeUsernameProblemLanguageResultExecution timeMemory
1090095ivan_alexeevDango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms460 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #ifdef lisie_bimbi #else #define endl '\n' #endif typedef long long ll; const ll inf = 1'000'000'000'000'000'000; using namespace std; #pragma GCC optimize("O3") #pragma GCC target("avx,avx2,bmi2,fma,popcnt") //#define int long long int n, m; vector<vector<int>> z; bool get(int x, int y, bool f){ if((x >= 0) && (x < n) && (y >= 0) && (y < m)){ }else{ return 0; } if(f){ if(x + 2 < n){ return ((z[x][y] == 0) && (z[x + 1][y] == 1) && (z[x + 2][y] == 2)); }else{ return 0; } }else{ if(y + 2 < m){ return ((z[x][y] == 0) && (z[x][y + 1] == 1) && (z[x][y + 2] == 2)); }else{ return 0; } } } vector<vector<int>> v; int kl(int a, int b){ return a * m + b; } vector<int> used; int lox[2]; void dfs(int u, int type){ lox[type]++; used[u] = 1; for(auto i : v[u]){ if(!used[i]){ dfs(i, type ^ 1); } } } void solve(){ cin >> n >> m; z.resize(n, vector<int>(m)); for(int i = 0; i < n; i++){ string s; cin >> s; for(int j = 0; j < m; j++){ if(s[j] == 'R'){ z[i][j] = 0; }else if(s[j] == 'G'){ z[i][j] = 1; }else{ z[i][j] = 2; } } } v.resize(n * m * 2); vector<int> h(n * m * 2); for(int x = 0; x < n; x++){ for(int y = 0; y < m; y++){ if(get(x, y, 1)){ h[kl(x, y)] = 1; for(int k = 0; k < 3; k++){ if(get(x + k, y - k, 0)){ v[kl(x, y)].push_back(kl(x + k, y - k) + n * m); } } } } } for(int x = 0; x < n; x++){ for(int y = 0; y < m; y++){ if(get(x, y, 0)){ h[kl(x, y) + n * m] = 1; for(int k = 0; k < 3; k++){ if(get(x - k, y + k, 1)){ v[kl(x, y) + n * m].push_back(kl(x - k, y + k)); } } } } } used.resize(n * m * 2); int ans = 0; for(int i = 0; i < n * m * 2; i++){ if(h[i] && !used[i]){ lox[0] = 0; lox[1] = 0; dfs(i, 0); ans += max(lox[0], lox[1]); } } cout << ans << endl; } signed main(){ #ifdef lisie_bimbi freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else cin.tie(nullptr)->sync_with_stdio(false); #endif cout << setprecision(5) << fixed; int _ = 1; //cin >> t; while(_--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...