제출 #300537

#제출 시각아이디문제언어결과실행 시간메모리
300537CSQ31Dango Maker (JOI18_dango_maker)C++14
100 / 100
259 ms10488 KiB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int n,m;
string grid[3001];
bool r[3005];
bool w[3005];
ll dr[3005];
ll dw[3005];
int solve(int n){
	for(int i=1;i<=n;i++){
		dr[i] = dr[i-1];
		dw[i] = dw[i-1];
		if(i>1){
			dr[i] = max(dr[i],dw[i-2]);
			dw[i] = max(dw[i],dr[i-2]);
		}
		if(r[i-1] && w[i])dw[i]++;
		if(w[i-1] && r[i])dr[i]++;
	}
	return max(dr[n],dw[n]);
}
bool ok(int x,int y){return x>=0 && y>=0 && x<n && y<m;}
bool okc(int x,int y,char c){return ok(x,y) && grid[x][y] == c;}
int main()
{
	owo
	ll ans = 0;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>grid[i];
	for(int i=0;i<n+m-1;i++){
		vector<pii>v;
		for(int j=0;j<=i;j++){
			if(okc(j,i-j,'G'))v.pb({j,i-j});
		}
		for(int i=0;i<(int)(v.size());){
			int e = i;
			while(e<(int)(v.size()) && v[e].fi - v[i].fi == e-i)e++;
            r[0] = okc(v[i].fi-1,v[i].se,'R');
            w[0] = okc(v[i].fi,v[i].se+1,'W');
            for(int j=i;j<e;j++){
				r[j-i+1] = okc(v[j].fi,v[j].se-1,'R');
				w[j-i+1] = okc(v[j].fi+1,v[j].se,'W');
			}
			ans+=solve(e-i);
			i = e;
		}
		
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...