Submission #539430

#TimeUsernameProblemLanguageResultExecution timeMemory
539430AntekbDango Maker (JOI18_dango_maker)C++14
13 / 100
49 ms70876 KiB
#include<bits/stdc++.h> #define st first #define nd second using namespace std; using ll=long long; const int N=3005, M=3e6+5; const ll INF=1e18; vector<int> E[M]; int vis[M], match[M]; int co[N][N], poz[N][N], pio[N][N]; int col=1; bool dfs(int v){ vis[v]=col; for(int u:E[v]){ if(!match[u]){ match[u]=v; return 1; } else{ if(vis[match[u]]!=col && dfs(match[u])){ match[u]=v; return 1; } } } return 0; } int main(){ int n, m; cin>>n>>m; for(int i=1; i<=n; i++){ string s; cin>>s; for(int j=0; j<m; j++){ if(s[j]=='R')co[i][j+1]=1; else if(s[j]=='G')co[i][j+1]=2; else co[i][j+1]=3; } } int wsk1=0, wsk2=0; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(co[i-1][j]==1 && co[i][j]==2 && co[i+1][j]==3){ pio[i][j]=++wsk1; } } } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(co[i][j-1]==1 && co[i][j]==2 && co[i][j+1]==3){ poz[i][j]=++wsk2; } } } for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(pio[i][j] && poz[i-1][j+1])E[pio[i][j]].push_back(poz[i-1][j+1]); if(pio[i][j] && poz[i+1][j-1])E[pio[i][j]].push_back(poz[i+1][j-1]); } } int ans=wsk1+wsk2; for(int i=1; i<=wsk1; i++){ if(dfs(i))ans--; else{ col++; if(dfs(i))ans--; } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...