제출 #241659

#제출 시각아이디문제언어결과실행 시간메모리
241659dsjongDango Maker (JOI18_dango_maker)C++14
100 / 100
940 ms53628 KiB
#include <bits/stdc++.h>
using namespace std;
char a[3005][3005];
int type[3005][3005];
int dp[3005][4];
int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int r, c;
	cin>>r>>c;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			cin>>a[i][j];
		}
	}
	memset(type, 0, sizeof type);
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			if(a[i][j]=='G'){
				if(a[i-1][j]=='R' && a[i+1][j]=='W') type[i][j]+=1;
				if(a[i][j-1]=='R' && a[i][j+1]=='W') type[i][j]+=2;
			}
		}
	}
	int ans=0;
	vector<int>v;
	for(int i=2;i<=r+c;i++){
		int x, y;
		if(i<=c) x=1, y=i-1;
		else x=i-c, y=c;
		v.clear();
		while(x<=r && y>=1){
			v.push_back(type[x][y]);
			//cout<<x<<" "<<y<<endl;
			x++, y--;
		}
		int n=v.size();
		dp[0][0]=dp[0][1]=dp[0][2]=0;
		for(int i=0;i<n;i++){
			dp[i+1][0]=max({dp[i][0], dp[i][1], dp[i][2]});
			dp[i+1][1]=0;
			dp[i+1][2]=0;
			if(v[i]==1 || v[i]==3) dp[i+1][1]=max(dp[i][1], dp[i][0])+1;
			if(v[i]==2 || v[i]==3) dp[i+1][2]=max(dp[i][2], dp[i][0])+1;
		}
		ans+=max({dp[n][0], dp[n][1], dp[n][2]});
		//cout<<ans<<endl;
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...