Submission #376559

# Submission time Handle Problem Language Result Execution time Memory
376559 2021-03-11T17:12:55 Z astoria Dango Maker (JOI18_dango_maker) C++14
100 / 100
399 ms 53868 KB
#include "bits/stdc++.h"
using namespace std;

const int N=3005,M=3005;
//vector<pair<pair<int,int>,int> > g[N][M][2]; //j=0,i=1;
bool is[N][M][2];
bool vis[N][M][2];

pair<int,int> dfs(int x, int y, int k){ //first = dp at this level, second = dp at below level.
	if(vis[x][y][k]) return {0,0};
	vis[x][y][k] = 1;
	
	pair<int,int> an={0,0};
	
	int tk;
	if(k==0) tk=1;
	else tk=0;
	
	if(is[x][y][tk]){
		pair<int,int> their = dfs(x,y,tk);
		an.first += their.first; an.second += their.second;
	}
	if(is[x-1][y+1][tk]){
		pair<int,int> their = dfs(x-1,y+1,tk);
		an.first += their.first; an.second += their.second;
	}
	if(is[x+1][y-1][tk]){
		pair<int,int> their = dfs(x+1,y-1,tk);
		an.first += their.first; an.second += their.second;
	}
	
	pair<int,int> ret;
	ret.second = an.first; //dp at below level
	ret.first = max(an.second+1,an.first);
	return ret;
	
	/*pair<int,int> an;
	if(k==0) an={1,0};
	else an={0,1};
	for(auto ii : g[x][y][k]){
		pair<int,int> their = dfs(ii.first.first,ii.first.second,ii.second);
		an.first += their.first; an.second += their.second;
	}
	return an;*/
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	char grid[n+5][m+5];
	
	for(int i=0; i<=n+1; i++){
		for(int j=0; j<=m+1; j++){
			grid[i][j]='p';
		}
	}
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin>>grid[i][j];
		}
	}
	
	
	memset(is,0,sizeof(is));
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(grid[i][j]!='G') continue;
			
			if(grid[i][j-1]=='R'&&grid[i][j+1]=='W'){
				is[i][j][0]=1;
			}
			if(grid[i-1][j]=='R'&&grid[i+1][j]=='W'){
				is[i][j][1]=1;
			}
		}
	}
	/*
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(!is[i][j][0]) continue;
			if(is[i][j][1]){
				g[i][j][0].push_back({{i,j},1});
			}
			if(is[i-1][j+1][1]){
				g[i][j][0].push_back({{i-1,j+1},1});
			}
			if(is[i+1][j-1][1]){
				g[i][j][0].push_back({{i+1,j-1},1});
			}
		}
	}
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(!is[i][j][1]) continue;
			if(is[i][j][0]){
				g[i][j][1].push_back({{i,j},0});
			}
			if(is[i-1][j+1][0]){
				g[i][j][1].push_back({{i-1,j+1},0});
			}
			if(is[i+1][j-1][0]){
				g[i][j][1].push_back({{i+1,j-1},0});
			}
		}
	}*/
	//cout<<"HEY"<<endl;
	memset(vis,0,sizeof(vis));
	int tot=0;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(is[i][j][0]&&!vis[i][j][0]){
				pair<int,int> an = dfs(i,j,0);
				tot += max(an.first,an.second);
			}
			if(is[i][j][1]&&!vis[i][j][1]){
				pair<int,int> an = dfs(i,j,1);
				tot += max(an.first,an.second);
			}
		}
	}
	
	cout<<tot;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 35692 KB Output is correct
2 Correct 20 ms 35692 KB Output is correct
3 Correct 19 ms 35692 KB Output is correct
4 Correct 20 ms 35692 KB Output is correct
5 Correct 20 ms 35692 KB Output is correct
6 Correct 20 ms 35692 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 20 ms 35692 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 19 ms 35692 KB Output is correct
11 Correct 19 ms 35692 KB Output is correct
12 Correct 20 ms 35692 KB Output is correct
13 Correct 20 ms 35692 KB Output is correct
14 Correct 20 ms 35692 KB Output is correct
15 Correct 20 ms 35692 KB Output is correct
16 Correct 20 ms 35692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 35692 KB Output is correct
2 Correct 20 ms 35692 KB Output is correct
3 Correct 19 ms 35692 KB Output is correct
4 Correct 20 ms 35692 KB Output is correct
5 Correct 20 ms 35692 KB Output is correct
6 Correct 20 ms 35692 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 20 ms 35692 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 19 ms 35692 KB Output is correct
11 Correct 19 ms 35692 KB Output is correct
12 Correct 20 ms 35692 KB Output is correct
13 Correct 20 ms 35692 KB Output is correct
14 Correct 20 ms 35692 KB Output is correct
15 Correct 20 ms 35692 KB Output is correct
16 Correct 20 ms 35692 KB Output is correct
17 Correct 20 ms 35692 KB Output is correct
18 Correct 20 ms 35712 KB Output is correct
19 Correct 21 ms 35712 KB Output is correct
20 Correct 21 ms 35692 KB Output is correct
21 Correct 20 ms 35692 KB Output is correct
22 Correct 22 ms 35692 KB Output is correct
23 Correct 20 ms 35712 KB Output is correct
24 Correct 20 ms 35692 KB Output is correct
25 Correct 20 ms 35692 KB Output is correct
26 Correct 19 ms 35692 KB Output is correct
27 Correct 20 ms 35692 KB Output is correct
28 Correct 20 ms 35692 KB Output is correct
29 Correct 20 ms 35732 KB Output is correct
30 Correct 20 ms 35692 KB Output is correct
31 Correct 20 ms 35704 KB Output is correct
32 Correct 21 ms 35692 KB Output is correct
33 Correct 20 ms 35692 KB Output is correct
34 Correct 23 ms 35692 KB Output is correct
35 Correct 20 ms 35692 KB Output is correct
36 Correct 20 ms 35692 KB Output is correct
37 Correct 20 ms 35692 KB Output is correct
38 Correct 20 ms 35692 KB Output is correct
39 Correct 20 ms 35692 KB Output is correct
40 Correct 20 ms 35692 KB Output is correct
41 Correct 20 ms 35692 KB Output is correct
42 Correct 20 ms 35692 KB Output is correct
43 Correct 20 ms 35692 KB Output is correct
44 Correct 20 ms 35692 KB Output is correct
45 Correct 21 ms 35692 KB Output is correct
46 Correct 21 ms 35692 KB Output is correct
47 Correct 20 ms 35692 KB Output is correct
48 Correct 21 ms 35692 KB Output is correct
49 Correct 21 ms 35692 KB Output is correct
50 Correct 20 ms 35692 KB Output is correct
51 Correct 21 ms 35692 KB Output is correct
52 Correct 20 ms 35692 KB Output is correct
53 Correct 20 ms 35692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 35692 KB Output is correct
2 Correct 20 ms 35692 KB Output is correct
3 Correct 19 ms 35692 KB Output is correct
4 Correct 20 ms 35692 KB Output is correct
5 Correct 20 ms 35692 KB Output is correct
6 Correct 20 ms 35692 KB Output is correct
7 Correct 20 ms 35692 KB Output is correct
8 Correct 20 ms 35692 KB Output is correct
9 Correct 20 ms 35692 KB Output is correct
10 Correct 19 ms 35692 KB Output is correct
11 Correct 19 ms 35692 KB Output is correct
12 Correct 20 ms 35692 KB Output is correct
13 Correct 20 ms 35692 KB Output is correct
14 Correct 20 ms 35692 KB Output is correct
15 Correct 20 ms 35692 KB Output is correct
16 Correct 20 ms 35692 KB Output is correct
17 Correct 20 ms 35692 KB Output is correct
18 Correct 20 ms 35712 KB Output is correct
19 Correct 21 ms 35712 KB Output is correct
20 Correct 21 ms 35692 KB Output is correct
21 Correct 20 ms 35692 KB Output is correct
22 Correct 22 ms 35692 KB Output is correct
23 Correct 20 ms 35712 KB Output is correct
24 Correct 20 ms 35692 KB Output is correct
25 Correct 20 ms 35692 KB Output is correct
26 Correct 19 ms 35692 KB Output is correct
27 Correct 20 ms 35692 KB Output is correct
28 Correct 20 ms 35692 KB Output is correct
29 Correct 20 ms 35732 KB Output is correct
30 Correct 20 ms 35692 KB Output is correct
31 Correct 20 ms 35704 KB Output is correct
32 Correct 21 ms 35692 KB Output is correct
33 Correct 20 ms 35692 KB Output is correct
34 Correct 23 ms 35692 KB Output is correct
35 Correct 20 ms 35692 KB Output is correct
36 Correct 20 ms 35692 KB Output is correct
37 Correct 20 ms 35692 KB Output is correct
38 Correct 20 ms 35692 KB Output is correct
39 Correct 20 ms 35692 KB Output is correct
40 Correct 20 ms 35692 KB Output is correct
41 Correct 20 ms 35692 KB Output is correct
42 Correct 20 ms 35692 KB Output is correct
43 Correct 20 ms 35692 KB Output is correct
44 Correct 20 ms 35692 KB Output is correct
45 Correct 21 ms 35692 KB Output is correct
46 Correct 21 ms 35692 KB Output is correct
47 Correct 20 ms 35692 KB Output is correct
48 Correct 21 ms 35692 KB Output is correct
49 Correct 21 ms 35692 KB Output is correct
50 Correct 20 ms 35692 KB Output is correct
51 Correct 21 ms 35692 KB Output is correct
52 Correct 20 ms 35692 KB Output is correct
53 Correct 20 ms 35692 KB Output is correct
54 Correct 20 ms 35692 KB Output is correct
55 Correct 20 ms 35684 KB Output is correct
56 Correct 21 ms 35692 KB Output is correct
57 Correct 21 ms 35692 KB Output is correct
58 Correct 48 ms 37612 KB Output is correct
59 Correct 253 ms 53356 KB Output is correct
60 Correct 253 ms 53484 KB Output is correct
61 Correct 254 ms 53392 KB Output is correct
62 Correct 20 ms 35692 KB Output is correct
63 Correct 245 ms 52716 KB Output is correct
64 Correct 349 ms 53868 KB Output is correct
65 Correct 347 ms 53740 KB Output is correct
66 Correct 399 ms 53868 KB Output is correct
67 Correct 194 ms 53356 KB Output is correct
68 Correct 191 ms 53356 KB Output is correct
69 Correct 199 ms 53356 KB Output is correct
70 Correct 54 ms 37740 KB Output is correct
71 Correct 54 ms 37740 KB Output is correct
72 Correct 54 ms 37740 KB Output is correct
73 Correct 52 ms 37740 KB Output is correct
74 Correct 54 ms 37740 KB Output is correct
75 Correct 53 ms 37792 KB Output is correct
76 Correct 54 ms 37868 KB Output is correct
77 Correct 54 ms 37740 KB Output is correct
78 Correct 54 ms 37740 KB Output is correct
79 Correct 54 ms 37888 KB Output is correct
80 Correct 55 ms 37740 KB Output is correct
81 Correct 54 ms 37740 KB Output is correct
82 Correct 53 ms 37868 KB Output is correct
83 Correct 54 ms 37740 KB Output is correct
84 Correct 53 ms 37740 KB Output is correct
85 Correct 56 ms 37740 KB Output is correct
86 Correct 54 ms 37740 KB Output is correct
87 Correct 53 ms 37740 KB Output is correct
88 Correct 55 ms 37888 KB Output is correct
89 Correct 53 ms 37740 KB Output is correct
90 Correct 52 ms 37740 KB Output is correct