Submission #1284521

#TimeUsernameProblemLanguageResultExecution timeMemory
1284521WH8Dango Maker (JOI18_dango_maker)C++20
0 / 100
1 ms572 KiB
#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
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;
		}
	}
	int ans=0;
	vector<int> layer(h+w, 0);
	for(int l=2;l<h+w;l++){
		vector<array<int,3>> dp(w+2, {0, 0, 0});
		for(int y=(l>h+1?l-h:1);y<=w;y++){
			int x=l-y; 
			if(x <= 0)break;
			//~ cout<<x<<" "<<y<<endl;
			if(m[x][y-1]==0 and m[x][y]==1 and m[x][y+1]==2){
				dp[x][1]=max({dp[x+1][0], dp[x+1][1]})+1;
			}
			if(m[x-1][y]==0 and m[x][y]==1 and m[x+1][y]==2){
				dp[x][2]=max({dp[x+1][0], dp[x+1][2]})+1;
			}
			dp[x][0]=max({dp[x+1][0],dp[x+1][1], dp[x+1][2]}); 
			layer[l]=max({layer[l], dp[x][0],dp[x][1],dp[x][2]});
		}
		ans+=layer[l];
		//~ printf("layer %lld, cont %lld\n", l, layer[l]);
	}
	cout<<ans;
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...