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>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define ppb pop_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
int n,m,g[3005][3005];
int dp[3005][3005][2];
char c;
int can(int i,int j,int o){
if(o)return g[i-1][j]==1&&g[i][j]==2&&g[i+1][j]==3;
else return g[i][j-1]==1&&g[i][j]==2&&g[i][j+1]==3;
}
int main(){
sf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
sf(" %c",&c);
if(c=='R')g[i][j]=1;
if(c=='G')g[i][j]=2;
if(c=='W')g[i][j]=3;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
dp[i][j][0]=dp[i][j][1]=-INF;
}
}
int ans=0;
for(int i=2;i<=n+m;++i){ //process by diagonal
int mx=0;
int X=-1,Y=-1;
for(int x=max(1,i-m);x<=min(n,i-1);++x){
int y=i-x;
for(int a=0;a<2;++a){
if(can(x,y,a)){
dp[x][y][a]=max(mx,dp[x-1][y+1][a])+1;
//put horizontal/vertical, then transition to previous
//mx is if u dont put
}
}
for(int a=0;a<2;++a){
mx=max(mx,dp[x-1][y+1][a]);
//update mx to put horizontal/vertical at previous
}
X=x;Y=y;
}
for(int a=0;a<2;++a){
mx=max(mx,dp[X][Y][a]);
}
ans+=mx;
}
printf("%d\n",ans);
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:42:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | sf("%d%d",&n,&m);
| ^
dango_maker.cpp:45:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | sf(" %c",&c);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |