Submission #714133

#TimeUsernameProblemLanguageResultExecution timeMemory
714133089487Dango Maker (JOI18_dango_maker)C++14
13 / 100
48 ms70952 KiB
#include<bits/stdc++.h> #define int long long #define quick ios::sync_with_stdio(0);cin.tie(0); #define rep(x,a,b) for(int x=a;x<=b;x++) #define repd(x,a,b) for(int x=a;x>=b;x--) #define lowbit(x) (x&-x) #define sz(x) (int)(x.size()) #define F first #define S second #define all(x) x.begin(),x.end() #define mp make_pair #define eb emplace_back using namespace std; typedef pair<int,int> pii; void debug(){ cout<<"\n"; } template <class T,class ... U > void debug(T a, U ... b){ cout<<a<<" ",debug(b...); } const int N=3e3+7; const int INF=1e18; char c[N][N]; int col[N][N]; int row[N][N]; const int M=3e6+7; vector<int> v3[M]; int color[N]; int w; int b; void add_edge(int a,int b){ v3[a].eb(b); v3[b].eb(a); } void dfs(int x,int pnt=1){ if(color[x]) return; color[x]=pnt; if(pnt==1) w++; else b++; for(int i:v3[x]){ dfs(i,-pnt); } } signed main(){ quick int n,m; cin>>n>>m; rep(i,1,n){ rep(j,1,m) cin>>c[i][j]; } int Cc=0; int Cr=0; rep(i,1,n){ rep(j,1,m){ if(j+2<=m&&c[i][j]=='R'&&c[i][j+1]=='G'&&c[i][j+2]=='W'){ ++Cc; rep(jx,j,j+2){ col[i][jx]=Cc; } } if(i+2<=n&&c[i][j]=='R'&&c[i+1][j]=='G'&&c[i+2][j]=='W'){ ++Cr; rep(ix,i,i+2){ row[ix][j]=Cr; } } } } rep(i,1,n){ rep(j,1,m){ if(col[i][j]&&row[i][j]){ add_edge(col[i][j],row[i][j]+Cc); } } } int n2=Cc+Cr; int ans=0; rep(i,1,n2){ if(!color[i]){ b=w=0; dfs(i,1); ans+=max(b,w); } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...