Submission #680331

#TimeUsernameProblemLanguageResultExecution timeMemory
680331kakayoshiDango Maker (JOI18_dango_maker)C++14
0 / 100
107 ms221188 KiB
#include <bits/stdc++.h> using namespace std; #define forw(i,a,b) for(ll i=a;i<=b;i++) #define forb(i,a,b) for(ll i=a;i>=b;i--) #define pu push #define pb push_back #define fi first #define se second #define all(a) a.begin(),a.end() #define minimize(a,b) a=min(a,b) #define maximize(a,b) a=max(a,b) typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ll,pair<ll,ll> > plll; const int maxN=3000+5; const ll oo=1e18; const char base[3]={'R','G','W'}; const int tx[2]={1,0}; const int ty[2]={0,1}; bool vis[maxN][maxN],vis1[maxN*maxN]; int n,m,match[maxN*maxN],cnt; char a[maxN][maxN]; vector <int> edge[maxN*maxN]; bool outmap(int x, int y) { if (1<=x && x<=n) if (1<=y && y<=m) return 0; return 1; } bool matching(int u) { for(int v:edge[u]) if (!vis1[v]) { vis1[v]=1; if (!match[v] || matching(match[v])) { match[v]=u; return 1; } } return 0; } void solve() { cin>>n>>m; forw(i,1,n) forw(j,1,m) cin>>a[i][j]; forw(i,1,n) forw(j,1,m) if (a[i][j]==base[0]) forw(p,0,1) { int x=i; int y=j; bool flag=1; forw(k,1,2) { x+=tx[p]; y+=ty[p]; if (outmap(x,y) || a[x][y]!=base[k]) flag=0; } if (!flag) continue; x=i; y=j; cnt++; if (vis[x][y]) { edge[cnt].pb(vis[x][y]); edge[vis[x][y]].pb(cnt); //cout<<cnt<<" "<<vis[x][y]<<endl; } vis[x][y]=cnt; forw(k,1,2) { x+=tx[p]; y+=ty[p]; if (vis[x][y]) { edge[cnt].pb(vis[x][y]); edge[vis[x][y]].pb(cnt); } vis[x][y]=cnt; } } int ans=0; forw(i,1,cnt) { memset(vis1,0,sizeof vis1); ans+=matching(i); } cout<<cnt-ans/2; return; } int main() { ios::sync_with_stdio(); cin.tie(0); //freopen("bruh.inp","r",stdin); //freopen("bruh.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...