제출 #892988

#제출 시각아이디문제언어결과실행 시간메모리
892988MinbaevDango Maker (JOI18_dango_maker)C++17
33 / 100
2055 ms600 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}

bool comp(pii a,pii b){
	if(a.f>b.f)return 1;
	else if(a.f<b.f)return 0;
	else{
		if(a.s<b.s)return 1;
		else return 0;
	}
}

void solve(){
	int n,m,k;
	
	cin>>n>>m;
	
	char arr[n+5][n+5];
	
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=m;j++){
			cin>>arr[i][j];
		}
	}
	
	int ans = 0;
	
	for(int j = 1;j<=m;j++){
		int ind = 1,x = 1,y = j;
		vector<vector<int>>dp(max(n+1,m+1),{0,0,0});
		
		while(x<=n&&y>=1){
			dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
			if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
			if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
			x++;y--;ind++;
		}
		ind--;
		ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
		
	}
	
	for(int i = 2;i<=n;i++){
		int ind = 1,x = i,y = m;
		vector<vector<int>>dp(max(n+1,m+1),{0,0,0});
		
		while(x<=n&&y>=1){
			dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
			if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
			if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
			x++;y--;ind++;
		}
		ind--;
		ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
		
	}
	
	
	cout<<ans<<" ";
	//ne spizdil , a adaptiroval


}

 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();

}

컴파일 시 표준 에러 (stderr) 메시지

dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:42:10: warning: unused variable 'k' [-Wunused-variable]
   42 |  int n,m,k;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...