#include <bits/stdc++.h>
//qwerty47924692
using namespace std;
using ll = long long;
const ll N=3005;
const string br="617283";
#define sz(a)(ll)a.size()
#define f first
#define s second
ll dp[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[N];
vector<ll>l;
ll was[N],pr[N],used[N];
void dfs(ll v,ll k=1){
used[v]=1;
k^=1;
if(k==1)l.push_back(v);
for(ll to:g[v]){
if(used[to])continue;
dfs(to,k);
}
}ll try_kuhn(ll v){
if(was[v])return 0;
for(ll to:g[v]){
if(!pr[to]||try_kuhn(pr[to])){
pr[to]=v;
return 1;
}
}return 0;
}ll kuhn(){
ll ans=0;
for(ll i:l){
for(ll j:l)was[j]=0;
ans+=try_kuhn(i);
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
vector<dango>a;
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);
}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);
}
}
}
for(ll i=0;i<a.size();i++){
for(ll j=i+1;j<a.size();j++){
if(equ(a[i],a[j])){
g[i+1].push_back(j+1);
g[j+1].push_back(i+1);
}
}
}
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... |