# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666513 | manizare | Dango Maker (JOI18_dango_maker) | C++14 | 105 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std ;
const int maxn = 3012 , maxq =1e7 + 100 , inf = 1e9 + 100 , mod = 1e9 + 7 ;
char c[maxn][maxn] ;
vector <int> G[maxq] ;
vector <int> vec[maxn][maxn] ;
int ans[2] ;
bool mark[maxq] ;
void dfs(int v , int k){
mark[v] = 1;
ans[k]++;
for(int i = 0 ; i < G[v].size() ; i++){
int u = G[v][i] ;
if(mark[u] == 1)continue ;
dfs(u , k^1);
}
}
signed main(){
int n , m ;
cin >> n >> m ;
for(int i = 1; i <= n ; i++){
for(int j = 1; j <= m ; j++){
cin >> c[i][j] ;
}
}
int cnt = 0 ;
for(int i =1 ; i <= n ; i++){
for(int j = 1; j <= m ; j++){
if(i <= (n-2) && c[i][j] == 'R' && c[i+1][j] == 'G' && c[i+2][j] == 'W'){
cnt++;
vec[i][j].pb(cnt);
vec[i+1][j].pb(cnt);
vec[i+2][j].pb(cnt);
}
if(j <= (m-2) && c[i][j] == 'R' && c[i][j+1] == 'G' && c[i][j+2] == 'W'){
cnt++;
vec[i][j].pb(cnt);
vec[i][j+1].pb(cnt);
vec[i][j+2].pb(cnt);
}
}
}
for(int i =1 ; i<= n ; i++){
for(int j = 1; j <= m ; j++){
if(vec[i][j].size() == 2){
int v = vec[i][j][0] , u = vec[i][j][1] ;
G[v].pb(u);
G[u].pb(v);
}
}
}
int ans1 = 0 ;
for(int i = 1 ;i <= cnt ; i++){
if(mark[i] == 1)continue ;
dfs(i , 0);
ans1 += max(ans[1] , ans[0]);
ans[0] = ans[1] =0 ;
}
cout << ans1 << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |