#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define endl '\n'
#define ld long double
vector<tuple<int,int,int>> hd={{-1,1,1},{0,2,0},{1,1,1},{1,-1,1},{0,-2,0},{-1,-1,1}},
vd={{-2,0,1},{-1,1,0},{1,1,0},{2,0,1},{1,-1,0},{-1,-1,0}};
signed main(){
int h,w;cin>>h>>w;
vector<vector<int>> m(h+2, vector<int>(w+2, 1));
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
char c;cin>>c;
if(c=='R')m[i][j]=0;
else if(c=='G')m[i][j]=1;
else m[i][j]=2;
}
}
auto dfs=[&](auto && dfs, vector<vector<bool>> st) -> int{
int cand=0;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(!st[i][j] or m[i][j]!=1)continue;
if((st[i][j-1] and st[i][j+1]) and((m[i][j-1]==0 and m[i][j+1]==2) or (m[i][j+1]==0 and m[i][j-1]==2))){
vector<vector<bool>> nw(st.begin(),st.end());
nw[i][j-1]=0,nw[i][j]=0,nw[i][j+1]=0;
cand=max(cand, dfs(dfs,nw)+1);
//~ printf("%lld %lld, hori\n",i,j);
}
if((st[i-1][j] and st[i+1][j]) and ((m[i-1][j]==0 and m[i+1][j]==2) or (m[i+1][j]==0 and m[i-1][j]==2))){
vector<vector<bool>> nw(st.begin(),st.end());
nw[i-1][j]=0,nw[i][j]=0,nw[i+1][j]=0;
cand=max(cand, dfs(dfs, nw)+1);
//~ printf("%lld %lld, vert\n",i,j);
}
}
}
return cand;
};
vector<vector<bool>> temp(h+2, vector<bool>(w+2, 1));
cout<<dfs(dfs, temp);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |