Submission #89219

# Submission time Handle Problem Language Result Execution time Memory
89219 2018-12-11T01:56:00 Z sjhuang26 Dango Maker (JOI18_dango_maker) C++14
100 / 100
678 ms 138552 KB
#include<iostream>
#include<string>
using namespace std;
// N, M <= 3000
int N,M,d[3][3000],a[3000][3000];
bool fv[3000][3000]={},fh[3000][3000]={};
int main(){
	cin>>N>>M;
	for(int i=0;i<N;++i){
		string in;cin>>ws>>in;
		for(int j=0;j<M;++j){
			if(in[j]=='R')a[i][j]=0;
			if(in[j]=='G')a[i][j]=1;
			if(in[j]=='W')a[i][j]=2;
		}
	}
	// vertical
	for(int i=0;i<N-2;++i){
		for(int j=0;j<M;++j){
			if(a[i][j]==0&&a[i+1][j]==1&&a[i+2][j]==2)fv[i][j]=1;
		}
	}
	// horizontal
	for(int i=0;i<N;++i){
		for(int j=0;j<M-2;++j){
			if(a[i][j]==0&&a[i][j+1]==1&&a[i][j+2]==2)fh[i][j]=1;
		}
	}
	int ans=0;
	for(int i=0;i<N;++i){
		int j=i,k=0,m=0;
		while(j!=-1&&k!=M){
			d[0][m]=d[1][m]=d[2][m]=0;
			if(m>0){
				if(fh[j][k])d[0][m]=d[0][m-1]+1;
				else if(fv[j][k])d[0][m]=d[2][m-1]+1;
				d[0][m]=max(d[0][m],d[0][m-1]);
			}else{
				d[0][m]=fh[j][k]||fv[j][k];
			}
			if(m>0){
				if(fv[j][k])d[1][m]=d[2][m-1]+1;
				d[1][m]=max(d[1][m],d[0][m-1]);
			}else{
				d[1][m]=fv[j][k];
			}
			if(m>0){
				if(fv[j][k])d[2][m]=d[2][m-1]+1;
				d[2][m]=max(d[2][m],d[1][m-1]);
			}else{
				d[2][m]=fv[j][k];
			}
			--j;++k;++m;
		}
		ans+=d[0][m-1];
	}
	// nearly duplicated code 
	for(int i=1;i<M;++i){
		int j=N-1,k=i,m=0;
		while(j!=-1&&k!=M){
			d[0][m]=d[1][m]=d[2][m]=0;
			if(m>0){
				if(fh[j][k])d[0][m]=d[0][m-1]+1;
				else if(fv[j][k])d[0][m]=d[2][m-1]+1;
				d[0][m]=max(d[0][m],d[0][m-1]);
			}else{
				d[0][m]=fh[j][k]||fv[j][k];
			}
			if(m>0){
				if(fv[j][k])d[1][m]=d[2][m-1]+1;
				d[1][m]=max(d[1][m],d[0][m-1]);
			}else{
				d[1][m]=fv[j][k];
			}
			if(m>0){
				if(fv[j][k])d[2][m]=d[2][m-1]+1;
				d[2][m]=max(d[2][m],d[1][m-1]);
			}else{
				d[2][m]=fv[j][k];
			}
			--j;++k;++m;
		}
		ans+=d[0][m-1];
	}
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 792 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 2 ms 812 KB Output is correct
21 Correct 2 ms 836 KB Output is correct
22 Correct 2 ms 836 KB Output is correct
23 Correct 2 ms 836 KB Output is correct
24 Correct 2 ms 836 KB Output is correct
25 Correct 2 ms 836 KB Output is correct
26 Correct 2 ms 836 KB Output is correct
27 Correct 2 ms 840 KB Output is correct
28 Correct 2 ms 844 KB Output is correct
29 Correct 2 ms 848 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 856 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 864 KB Output is correct
34 Correct 2 ms 868 KB Output is correct
35 Correct 2 ms 872 KB Output is correct
36 Correct 2 ms 876 KB Output is correct
37 Correct 2 ms 884 KB Output is correct
38 Correct 2 ms 884 KB Output is correct
39 Correct 2 ms 888 KB Output is correct
40 Correct 2 ms 892 KB Output is correct
41 Correct 2 ms 896 KB Output is correct
42 Correct 2 ms 900 KB Output is correct
43 Correct 2 ms 904 KB Output is correct
44 Correct 2 ms 928 KB Output is correct
45 Correct 2 ms 928 KB Output is correct
46 Correct 2 ms 928 KB Output is correct
47 Correct 2 ms 928 KB Output is correct
48 Correct 2 ms 928 KB Output is correct
49 Correct 2 ms 928 KB Output is correct
50 Correct 2 ms 932 KB Output is correct
51 Correct 2 ms 936 KB Output is correct
52 Correct 2 ms 940 KB Output is correct
53 Correct 2 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 616 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Correct 2 ms 704 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 744 KB Output is correct
11 Correct 2 ms 752 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 784 KB Output is correct
15 Correct 2 ms 788 KB Output is correct
16 Correct 2 ms 792 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 2 ms 812 KB Output is correct
21 Correct 2 ms 836 KB Output is correct
22 Correct 2 ms 836 KB Output is correct
23 Correct 2 ms 836 KB Output is correct
24 Correct 2 ms 836 KB Output is correct
25 Correct 2 ms 836 KB Output is correct
26 Correct 2 ms 836 KB Output is correct
27 Correct 2 ms 840 KB Output is correct
28 Correct 2 ms 844 KB Output is correct
29 Correct 2 ms 848 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 856 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 864 KB Output is correct
34 Correct 2 ms 868 KB Output is correct
35 Correct 2 ms 872 KB Output is correct
36 Correct 2 ms 876 KB Output is correct
37 Correct 2 ms 884 KB Output is correct
38 Correct 2 ms 884 KB Output is correct
39 Correct 2 ms 888 KB Output is correct
40 Correct 2 ms 892 KB Output is correct
41 Correct 2 ms 896 KB Output is correct
42 Correct 2 ms 900 KB Output is correct
43 Correct 2 ms 904 KB Output is correct
44 Correct 2 ms 928 KB Output is correct
45 Correct 2 ms 928 KB Output is correct
46 Correct 2 ms 928 KB Output is correct
47 Correct 2 ms 928 KB Output is correct
48 Correct 2 ms 928 KB Output is correct
49 Correct 2 ms 928 KB Output is correct
50 Correct 2 ms 932 KB Output is correct
51 Correct 2 ms 936 KB Output is correct
52 Correct 2 ms 940 KB Output is correct
53 Correct 2 ms 956 KB Output is correct
54 Correct 2 ms 956 KB Output is correct
55 Correct 17 ms 13472 KB Output is correct
56 Correct 3 ms 13472 KB Output is correct
57 Correct 17 ms 17248 KB Output is correct
58 Correct 78 ms 17248 KB Output is correct
59 Correct 671 ms 63632 KB Output is correct
60 Correct 678 ms 72648 KB Output is correct
61 Correct 668 ms 81444 KB Output is correct
62 Correct 3 ms 81444 KB Output is correct
63 Correct 661 ms 89972 KB Output is correct
64 Correct 495 ms 98660 KB Output is correct
65 Correct 476 ms 107476 KB Output is correct
66 Correct 494 ms 116380 KB Output is correct
67 Correct 456 ms 116380 KB Output is correct
68 Correct 454 ms 123472 KB Output is correct
69 Correct 495 ms 138552 KB Output is correct
70 Correct 56 ms 138552 KB Output is correct
71 Correct 59 ms 138552 KB Output is correct
72 Correct 53 ms 138552 KB Output is correct
73 Correct 57 ms 138552 KB Output is correct
74 Correct 52 ms 138552 KB Output is correct
75 Correct 57 ms 138552 KB Output is correct
76 Correct 57 ms 138552 KB Output is correct
77 Correct 55 ms 138552 KB Output is correct
78 Correct 53 ms 138552 KB Output is correct
79 Correct 53 ms 138552 KB Output is correct
80 Correct 55 ms 138552 KB Output is correct
81 Correct 58 ms 138552 KB Output is correct
82 Correct 58 ms 138552 KB Output is correct
83 Correct 56 ms 138552 KB Output is correct
84 Correct 56 ms 138552 KB Output is correct
85 Correct 55 ms 138552 KB Output is correct
86 Correct 58 ms 138552 KB Output is correct
87 Correct 55 ms 138552 KB Output is correct
88 Correct 59 ms 138552 KB Output is correct
89 Correct 61 ms 138552 KB Output is correct
90 Correct 57 ms 138552 KB Output is correct