This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=3e3+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
char c[N][N];
ll dp[N][3],n,m,T[N][N],ans;
vector<ll> D[2*N];
bool valid(ll xa,ll ya,ll xb,ll yb){
if(xa>xb)swap(xa,xb);
if(ya>yb)swap(ya,yb);
ll xm=(xa+xb)/2,ym=(ya+yb)/2;
if(xa<0||xb>=n||ya<0||yb>=m||c[xm][ym]!='G')return 0;
if(ya==yb){
return ((c[xa][ym]=='R'&&c[xb][ym]=='W'));
}else{
return ((c[xm][ya]=='R'&&c[xm][yb]=='W'));
}
}
ll CAL(ll id){
memset(dp,0,sizeof(dp));
REP(i,SZ(D[id])){
dp[i+1][0]=max(dp[i][0],max(dp[i][1],dp[i][2]));
if(D[id][i]&1)dp[i+1][1]=max(dp[i][0],dp[i][1])+1;
if(D[id][i]&2)dp[i+1][2]=max(dp[i][0],dp[i][2])+1;
}
return max(dp[SZ(D[id])][0],max(dp[SZ(D[id])][1],dp[SZ(D[id])][2]));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
REP(i,n)REP(j,m){
cin>>c[i][j];
}
REP(i,n)REP(j,m){
ll nd=i*m+j;
if(c[i][j]=='G'){
if(valid(i-1,j,i+1,j))T[i][j]|=1;
if(valid(i,j-1,i,j+1))T[i][j]|=2;
}
D[i+j].pb(T[i][j]);
}
REP(i,n+m-1){
ans+=CAL(i);
}
cout<<ans<<"\n";
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:56:6: warning: unused variable 'nd' [-Wunused-variable]
56 | ll nd=i*m+j;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |