Submission #227907

# Submission time Handle Problem Language Result Execution time Memory
227907 2020-04-29T08:28:20 Z dvdg6566 Dango Maker (JOI18_dango_maker) C++14
100 / 100
648 ms 75444 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 3010;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
int N,M;
string S;
int done[MAXN][MAXN];
int G[MAXN][MAXN];
ll a;
int dp[MAXN][2];
vi V[MAXN];
int dpmem[MAXN][2];
 
int vert(pi x){
	return G[x.f-1][x.s]==1&&G[x.f+1][x.s]==3;
}
 
int hori(pi x){
	return G[x.f][x.s-1]==1&&G[x.f][x.s+1]==3;
}
 
int ask(int x, int p){
	if(x<0)return -1;
	if(dp[x][p]!=0)return dp[x][p];
	if(dpmem[x][p]!=1)return max(ask(x-1,p),ask(x-2,p^1));
	dp[x][p]=max(ask(x-1,p),ask(x-2,p^1))+1;
	dp[x][p]=max(dp[x][p],1);
	// cout<<x<<' '<<p<<' '<<dp[x][p]<<'\n';
	return dp[x][p];
}
ll ans;
 
int main(){
	cin>>N>>M;
	for (int i=1;i<=N;++i){
		cin>>S;
		for (int j=1;j<=M;++j){
			if(S[j-1]=='R')G[i+1][j+1]=1;
			if(S[j-1]=='G')G[i+1][j+1]=2;
			if(S[j-1]=='W')G[i+1][j+1]=3;			
		}
	}
	for (int i=2;i<=N+1;++i)for(int j=2;j<=M+1;++j){
		if(done[i][j]||G[i][j]!=2)continue;
		int t=1;
		pi cur = mp(i,j);
		if(!vert(cur)&&!hori(cur))continue;
		while(1){
			pi nxt=mp(cur.f+1,cur.s-1);
			done[cur.f][cur.s]=1;
			if(G[nxt.f][nxt.s]!=2)break;
			if(!vert(nxt)&&!hori(nxt))break;
			cur=nxt;++t;
		}
		// cout<<t<<'\n';
		cur=mp(i,j);
		for(int x=0;x<=t;++x)dpmem[x][0]=dpmem[x][1]=dp[x][0]=dp[x][1]=0;
		for (int x=0;x<t;++x){
			pi curr = mp(cur.f+x,cur.s-x);
			if(vert(curr))dpmem[x][0]=1;
			if(hori(curr))dpmem[x][1]=1;
			// cout<<dpmem[x][0]<<' '<<dpmem[x][1]<<'\n';
		}
		ans+=max(ask(t-1,0), ask(t-1,1));
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 484 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 484 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 4 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 4 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 5 ms 512 KB Output is correct
38 Correct 5 ms 512 KB Output is correct
39 Correct 5 ms 512 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 5 ms 512 KB Output is correct
43 Correct 5 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 5 ms 512 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
54 Correct 5 ms 512 KB Output is correct
55 Correct 12 ms 12928 KB Output is correct
56 Correct 6 ms 512 KB Output is correct
57 Correct 15 ms 15616 KB Output is correct
58 Correct 76 ms 17144 KB Output is correct
59 Correct 632 ms 75260 KB Output is correct
60 Correct 636 ms 75128 KB Output is correct
61 Correct 610 ms 75256 KB Output is correct
62 Correct 5 ms 512 KB Output is correct
63 Correct 594 ms 75128 KB Output is correct
64 Correct 648 ms 75392 KB Output is correct
65 Correct 626 ms 75384 KB Output is correct
66 Correct 625 ms 75444 KB Output is correct
67 Correct 540 ms 55848 KB Output is correct
68 Correct 557 ms 55972 KB Output is correct
69 Correct 544 ms 61536 KB Output is correct
70 Correct 76 ms 17212 KB Output is correct
71 Correct 74 ms 17272 KB Output is correct
72 Correct 74 ms 17272 KB Output is correct
73 Correct 74 ms 17300 KB Output is correct
74 Correct 77 ms 17304 KB Output is correct
75 Correct 79 ms 17248 KB Output is correct
76 Correct 74 ms 17248 KB Output is correct
77 Correct 75 ms 17272 KB Output is correct
78 Correct 74 ms 17272 KB Output is correct
79 Correct 80 ms 17272 KB Output is correct
80 Correct 80 ms 17272 KB Output is correct
81 Correct 74 ms 17272 KB Output is correct
82 Correct 75 ms 17316 KB Output is correct
83 Correct 72 ms 17248 KB Output is correct
84 Correct 78 ms 17272 KB Output is correct
85 Correct 76 ms 17272 KB Output is correct
86 Correct 73 ms 17188 KB Output is correct
87 Correct 75 ms 17272 KB Output is correct
88 Correct 81 ms 17248 KB Output is correct
89 Correct 72 ms 17272 KB Output is correct
90 Correct 75 ms 17272 KB Output is correct