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>
using namespace std;
typedef long long ll;
#define ii pair <int, int>
#define rep(i,n) for(int i = 0; i <n; i++)
#define pb push_back
#define f first
#define s second
#define debug(x) cout<<#x<<' '<<x<<endl;
int n,m;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
char a[n+5][m+5];
rep(i,n)rep(j,m){
cin>>a[i][j];
}
vector<int> adj[(n*m/3+5)],vs[n+5][m+5];
bool vis[(n*m/3+5)]={};
int nd=0;
rep(i,n)rep(j,m){
if(a[i][j]!='R')continue;
if(i<n-2&&a[i+1][j]=='G'&&a[i+2][j]=='W'){
for(auto it: vs[i][j]){
adj[it].pb(nd);
adj[nd].pb(it);
}
vs[i][j].pb(nd);
for(auto it: vs[i+1][j]){
adj[it].pb(nd);
adj[nd].pb(it);
}
for(auto it: vs[i+2][j]){
adj[it].pb(nd);
adj[nd].pb(it);
}
vs[i+1][j].pb(nd);
vs[i+2][j].pb(nd);
nd++;
}
if(j<m-2&&a[i][j+1]=='G'&&a[i][j+2]=='W'){
for(auto it: vs[i][j]){
adj[it].pb(nd);
adj[nd].pb(it);
}
vs[i][j].pb(nd);
for(auto it: vs[i][j+1]){
adj[it].pb(nd);
adj[nd].pb(it);
}
for(auto it: vs[i][j+2]){
adj[it].pb(nd);
adj[nd].pb(it);
}
vs[i][j+1].pb(nd);
vs[i][j+2].pb(nd);
nd++;
}
//cout<<i<<' '<<j<<' '<<nd<<endl;
}
vector<ii> v;
rep(i,nd){
v.pb({adj[i].size(),i});
}
sort(v.begin(), v.end());
int ans=0;
for(auto it: v){
if(vis[it.s])continue;
//cout<<it.s<<endl;
for(auto tt: adj[it.s]){
vis[tt]=true;
//debug(tt);
}
ans++;
}
//cout<<nd<<endl;
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |