#include <bits/stdc++.h>
//qwerty47924692
using namespace std;
using ll = long long;
const ll N=3005;
const ll M=N*N/3;
const string br="617283";
#define sz(a)(ll)a.size()
#define f first
#define s second
ll dp[N][N],pos[N][N];
char c[N][N];
ll n,m;
struct dango{
vector<pair<ll,ll>>v;
};
bool equ(dango a,dango b){
for(auto i:a.v){
for(auto j:b.v){
if(i==j)return 1;
}
}
return 0;
}
vector<ll>g[M];
vector<ll>l;
ll was[M],pr[M];
void dfs(ll v,ll k){
was[v]=1;
k^=1;
if(k==1)l.push_back(v);
for(ll to:g[v]){
if(was[to])continue;
dfs(to,k);
}
}ll try_kuhn(ll v){
if(was[v])return 0;
was[v]=1;
for(ll to:g[v]){
if(!pr[to]||try_kuhn(pr[to])){
pr[to]=v;
return 1;
}
}return 0;
}
vector<dango>a;
ll kuhn(){
ll ans=0;
for(ll i:l){
for(ll j=1;j<=a.size();j++)was[j]=0;
ans+=try_kuhn(i);
}
return ans;
}ll ans=0,used[N][N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
cin>>c[i][j];
}
}for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
if(c[i][j]=='R'&&c[i][j+1]=='G'&&c[i][j+2]=='W'){
vector<pair<ll,ll>>v={make_pair(i,j),make_pair(i,j+1),make_pair(i,j+2)};
dango x;
x.v=v;
a.push_back(x);
l.push_back(a.size());
}if(c[i][j]=='R'&&c[i+1][j]=='G'&&c[i+2][j]=='W'){
vector<pair<ll,ll>>v;
v={{i,j},{i+1,j},{i+2,j}};
dango x;
x.v=v;
a.push_back(x);
ll n=a.size();
pos[i][j]=pos[i+1][j]=pos[i+2][j]=n;
}
}
}
for(ll i=0;i<l.size();i++){
ll u=l[i];
// cout<<u<<' ';
for(auto j:a[u-1].v){
ll x=pos[j.f][j.s];
if(!x)continue;
g[u].push_back(x);
g[x].push_back(u);
}
}
cout<<a.size()-kuhn();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |