# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709716 | Baytoro | Dango Maker (JOI18_dango_maker) | C++17 | 626 ms | 18076 KiB |
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;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=2e9,mod=1e9+7,N=2e5+10;
int dp[3005][5];
char c[3005][3005];
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>c[i][j];
}
}
int ans=0;
for(int s=2;s<=n+m;s++){
int res=0;
for(int i=1;i<=m;i++) dp[i][1]=dp[i][2]=0;
for(int i=1;i<=m;i++){
int j=s-i;
if(j<1 || j>n) continue;
dp[i][1]=max(dp[i-1][1],dp[i-1][2]);
if(i>3)
dp[i][2]=max(dp[i-1][2],dp[i-3][1]);
if(j>2 && c[j-2][i]=='R' && c[j-1][i]=='G' && c[j][i]=='W')
dp[i][1]=max(dp[i-1][2],dp[i-1][1])+1;
if(i>2 && c[j][i-2]=='R' && c[j][i-1]=='G' && c[j][i]=='W')
dp[i][2]=max(dp[i-1][2],dp[i-3][1])+1;
res=max(res,max(dp[i][1],dp[i][2]));
}
ans+=res;
}
cout<<ans;
}
main(){
//fopn("cbarn");
//ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
//cout<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |