답안 #537905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537905 2022-03-15T20:18:05 Z tkwiatkowski Dango Maker (JOI18_dango_maker) C++17
100 / 100
376 ms 84892 KB
/*
	Zadanie: Dango Maker
	Autor: Tomasz Kwiatkowski
*/

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 3e3 + 7;
const int INF = 1e9 + 7;

char color[MAXN][MAXN];
pair<int, int> dp[MAXN][MAXN];

pair<int, int> RGW(int i, int j)
{
	pair<int, int> res = {false, false};
	if (color[i][j] == 'R' && color[i][j+1] == 'G' && color[i][j+2] == 'W')
		res.fi = true;
	if (color[i][j] == 'R' && color[i+1][j] == 'G' && color[i+2][j] == 'W')
		res.se = true;
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j)
			cin >> color[i][j];
	}

	int ans = 0;
	for (int j = 1; j <= m; ++j) {
		pair<int, int> prv = {0, 0};
		for (int i = 1; i <= min(n, j); ++i) {
			auto [h, v] = RGW(i, j - i + 1);
			// printf("[%d, %d]\t", h, v);
			dp[i][j - i + 1].fi = dp[i - 1][j - i + 1 + 1].fi + h;
			dp[i][j - i + 1].se = max(dp[i - 1][j - i + 1 + 1].fi, dp[i - 1][j - i + 1 + 1].se) + v;
			if (i >= 3) {
				dp[i][j - i + 1].fi = max(dp[i][j - i + 1].fi, dp[i - 3][j - i + 1 + 3].se + h);
			}
			// printf("dp[%d][%d] = (%d, %d)\n", i, j - i + 1, dp[i][j - i + 1].fi, dp[i][j - i + 1].se);
			prv = dp[i][j - i + 1];
		}
		ans += max(prv.fi, prv.se);
	}
	for (int i = 2; i <= n; ++i) {
		pair<int, int> prv = {0, 0};
		for (int j = m; j >= max(m - n + i, 1); --j) {
			auto [h, v] = RGW(i + m - j, j);
			// printf("[%d, %d]\t", h, v);
			dp[i + m - j][j].fi = dp[i + m - j - 1][j + 1].fi + h;
			dp[i + m - j][j].se = max(dp[i + m - j - 1][j + 1].fi, dp[i + m - j - 1][j + 1].se)  + v;
			if (i + m - j >= 3) {
				dp[i + m - j][j].fi = max(dp[i + m - j][j].fi, dp[i + m - j - 3][j + 3].se + h);
			}
			// printf("dp[%d][%d] = (%d, %d)\n", i + m - j, j, dp[i + m - j][j].fi, dp[i + m - j][j].se);
			prv = dp[i + m - j][j];
		}
		ans += max(prv.fi, prv.se);
	}

	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 328 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 456 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 328 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 456 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 10 ms 21204 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 8 ms 14424 KB Output is correct
58 Correct 39 ms 15984 KB Output is correct
59 Correct 330 ms 84684 KB Output is correct
60 Correct 317 ms 84760 KB Output is correct
61 Correct 376 ms 84656 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 312 ms 84728 KB Output is correct
64 Correct 316 ms 84696 KB Output is correct
65 Correct 307 ms 84812 KB Output is correct
66 Correct 324 ms 84756 KB Output is correct
67 Correct 342 ms 84892 KB Output is correct
68 Correct 339 ms 84724 KB Output is correct
69 Correct 343 ms 84704 KB Output is correct
70 Correct 33 ms 15980 KB Output is correct
71 Correct 30 ms 16076 KB Output is correct
72 Correct 29 ms 16000 KB Output is correct
73 Correct 38 ms 15988 KB Output is correct
74 Correct 32 ms 16044 KB Output is correct
75 Correct 32 ms 16084 KB Output is correct
76 Correct 31 ms 16028 KB Output is correct
77 Correct 31 ms 16052 KB Output is correct
78 Correct 29 ms 15968 KB Output is correct
79 Correct 29 ms 15980 KB Output is correct
80 Correct 32 ms 15984 KB Output is correct
81 Correct 34 ms 16112 KB Output is correct
82 Correct 35 ms 15984 KB Output is correct
83 Correct 32 ms 16004 KB Output is correct
84 Correct 32 ms 16076 KB Output is correct
85 Correct 29 ms 16072 KB Output is correct
86 Correct 31 ms 15960 KB Output is correct
87 Correct 31 ms 15992 KB Output is correct
88 Correct 34 ms 16032 KB Output is correct
89 Correct 44 ms 16000 KB Output is correct
90 Correct 32 ms 16076 KB Output is correct