답안 #411706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411706 2021-05-25T18:33:34 Z nichke Dango Maker (JOI18_dango_maker) C++14
100 / 100
669 ms 56780 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int ans;
int n, m, diag;
char ar[6005][6005];
int dp[6005][3];
bool valid[6005][6005][2];

int calc(int row, int prev) {
	if (row > n) return 0;
	if (dp[row][prev] != -1) return dp[row][prev];
	int ans = calc(row + 1, 0);
	if (!prev) {
		if (valid[row][diag - row][1]) ans = max(ans, 1 + calc(row + 1, 1));
		if (valid[row][diag - row][2]) ans = max(ans, 1 + calc(row + 1, 2));
	}
	if (prev == 1) {
		if (valid[row][diag - row][1]) ans = max(ans, 1 + calc(row + 1, 1));
	}
	if (prev == 2) {
		if (valid[row][diag - row][2]) ans = max(ans, 1 + calc(row + 1, 2));
	}
	return dp[row][prev] = ans;
}

signed 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 >> ar[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			valid[i][j][1] = (i < n && i > 1 && ar[i][j] == 'G' && ar[i - 1][j] == 'R' && ar[i + 1][j] == 'W');
			valid[i][j][2] = (j < m && j > 1 && ar[i][j] == 'G' && ar[i][j - 1] == 'R' && ar[i][j + 1] == 'W');
		}
	}
	for (int i = 2; i <= n + m; i++) {
		memset(dp, -1, sizeof dp); diag = i;
		ans += calc(1, 0);
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

dango_maker.cpp: In function 'long long int _Z4calcxx.part.0(long long int, long long int)':
dango_maker.cpp:18:31: warning: array subscript 2 is above array bounds of 'bool [2]' [-Warray-bounds]
   18 |   if (valid[row][diag - row][2]) ans = max(ans, 1 + calc(row + 1, 2));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
dango_maker.cpp:24:31: warning: array subscript 2 is above array bounds of 'bool [2]' [-Warray-bounds]
   24 |   if (valid[row][diag - row][2]) ans = max(ans, 1 + calc(row + 1, 2));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:41:17: warning: array subscript 2 is above array bounds of 'bool [2]' [-Warray-bounds]
   41 |    valid[i][j][2] = (j < m && j > 1 && ar[i][j] == 'G' && ar[i][j - 1] == 'R' && ar[i][j + 1] == 'W');
      |    ~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 452 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 2 ms 508 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 452 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 452 KB Output is correct
36 Correct 1 ms 452 KB Output is correct
37 Correct 1 ms 456 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 452 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 448 KB Output is correct
51 Correct 2 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 2 ms 444 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 452 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 2 ms 508 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 452 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 452 KB Output is correct
36 Correct 1 ms 452 KB Output is correct
37 Correct 1 ms 456 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 452 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 448 KB Output is correct
51 Correct 2 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 18 ms 460 KB Output is correct
55 Correct 187 ms 24776 KB Output is correct
56 Correct 16 ms 556 KB Output is correct
57 Correct 81 ms 16836 KB Output is correct
58 Correct 63 ms 12432 KB Output is correct
59 Correct 592 ms 56780 KB Output is correct
60 Correct 572 ms 56592 KB Output is correct
61 Correct 546 ms 56688 KB Output is correct
62 Correct 15 ms 460 KB Output is correct
63 Correct 551 ms 55884 KB Output is correct
64 Correct 636 ms 56740 KB Output is correct
65 Correct 669 ms 56704 KB Output is correct
66 Correct 659 ms 56708 KB Output is correct
67 Correct 612 ms 56620 KB Output is correct
68 Correct 595 ms 56704 KB Output is correct
69 Correct 634 ms 56704 KB Output is correct
70 Correct 64 ms 12452 KB Output is correct
71 Correct 63 ms 12452 KB Output is correct
72 Correct 64 ms 12460 KB Output is correct
73 Correct 75 ms 12424 KB Output is correct
74 Correct 64 ms 12436 KB Output is correct
75 Correct 65 ms 12452 KB Output is correct
76 Correct 65 ms 12332 KB Output is correct
77 Correct 64 ms 12340 KB Output is correct
78 Correct 80 ms 12452 KB Output is correct
79 Correct 65 ms 12432 KB Output is correct
80 Correct 65 ms 12356 KB Output is correct
81 Correct 64 ms 12452 KB Output is correct
82 Correct 62 ms 12356 KB Output is correct
83 Correct 73 ms 12356 KB Output is correct
84 Correct 66 ms 12456 KB Output is correct
85 Correct 67 ms 12524 KB Output is correct
86 Correct 63 ms 12356 KB Output is correct
87 Correct 63 ms 12332 KB Output is correct
88 Correct 65 ms 12432 KB Output is correct
89 Correct 66 ms 12356 KB Output is correct
90 Correct 70 ms 12448 KB Output is correct