Submission #891746

# Submission time Handle Problem Language Result Execution time Memory
891746 2023-12-23T22:36:39 Z Hakiers Dango Maker (JOI18_dango_maker) C++17
100 / 100
196 ms 75860 KB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 3e3 + 7;
char tab[MAXN][MAXN];
vector<pair<int, int>> diagonal[MAXN<<1][2]; //horizontal 0, vertical 1
int res;
int n, m;

void checkHorizontal(int y, int x, int id){
	if(tab[y][x] != 'R') return;
	else if(tab[y][x+1] != 'G') return;
	else if(tab[y][x+2] != 'W') return;
	int act = 1;
	
	//cout << "y " << y << " x " << x << "\n";
	
	if(diagonal[id][0].size())
		act = max(act, diagonal[id][0].back().second + 1);
	if(diagonal[id][1].size())
		act = max(act, diagonal[id][1].back().second + 1);
	
	diagonal[id][0].push_back({x, act});
}

void checkVertical(int y, int x, int id){
	if(tab[y][x] != 'R') return;
	else if(tab[y+1][x] != 'G') return;
	else if(tab[y+2][x] != 'W') return;
	int act = 1;
	
	//cout << "y " << y << " x " << x << "\n";
	
	if(diagonal[id][1].size())
		act = max(act, diagonal[id][1].back().second + 1);
	
	int it = int(diagonal[id][0].size())-1;
	
	while(it >= 0){
		if(diagonal[id][0][it].first + 3 <= x){
			act = max(act, diagonal[id][0][it].second + 1);
			break;
		}
		it--;
	}
	
	diagonal[id][1].push_back({x, act});
}

void addres(int id){
	int best = 0;
	if(diagonal[id][0].size())
		best = max(best, diagonal[id][0].back().second);
	if(diagonal[id][1].size())
		best = max(best, diagonal[id][1].back().second);
	res += best;
}

void solve(){
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; 0 <= (i-j) && j <= m; j++){
			if(j + 2 <= m)
				checkHorizontal((i-j+1), j, i);
			if((i-j+1)+2 <= n) 
				checkVertical((i-j+1), j, i);
		}
		addres(i);
	}
	
	
	
	for(int j = 2; j <= m; j++){
		for(int i = n; (n-i) + j <= m && i >= 1; i--){
			if((n-i) + j + 2 <= m)
				checkHorizontal(i, (n-i) + j, n+j);
			if(i+2 <= n) 
				checkVertical(i, (n-i) + j, n+j);
		}
		addres(n+j);
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> tab[i][j];
			
	solve();
	cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2696 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2696 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 0 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 0 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 1 ms 2648 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2696 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 0 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 0 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 0 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 1 ms 2648 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 2 ms 9560 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 23 ms 6656 KB Output is correct
59 Correct 195 ms 25832 KB Output is correct
60 Correct 196 ms 26084 KB Output is correct
61 Correct 196 ms 25684 KB Output is correct
62 Correct 1 ms 2648 KB Output is correct
63 Correct 186 ms 25420 KB Output is correct
64 Correct 192 ms 75860 KB Output is correct
65 Correct 193 ms 75860 KB Output is correct
66 Correct 193 ms 75860 KB Output is correct
67 Correct 159 ms 50028 KB Output is correct
68 Correct 151 ms 49768 KB Output is correct
69 Correct 158 ms 48208 KB Output is correct
70 Correct 23 ms 12636 KB Output is correct
71 Correct 23 ms 12884 KB Output is correct
72 Correct 22 ms 12624 KB Output is correct
73 Correct 22 ms 12636 KB Output is correct
74 Correct 23 ms 12704 KB Output is correct
75 Correct 24 ms 12636 KB Output is correct
76 Correct 24 ms 12628 KB Output is correct
77 Correct 23 ms 12628 KB Output is correct
78 Correct 24 ms 12636 KB Output is correct
79 Correct 23 ms 12628 KB Output is correct
80 Correct 23 ms 12888 KB Output is correct
81 Correct 26 ms 12752 KB Output is correct
82 Correct 22 ms 12624 KB Output is correct
83 Correct 22 ms 12632 KB Output is correct
84 Correct 23 ms 12636 KB Output is correct
85 Correct 22 ms 12636 KB Output is correct
86 Correct 23 ms 12624 KB Output is correct
87 Correct 23 ms 12628 KB Output is correct
88 Correct 23 ms 12488 KB Output is correct
89 Correct 22 ms 12624 KB Output is correct
90 Correct 23 ms 12628 KB Output is correct