답안 #62226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62226 2018-07-27T22:27:37 Z kingpig9 Dango Maker (JOI18_dango_maker) C++11
100 / 100
201 ms 113084 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 3010;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))

void setmax (int &a, int b) {
	if (a < b) {
		a = b;
	}
}

int N, M;
char S[MAXN][MAXN];
int dp[MAXN][3];	//0: none. 1: vert. 2: horiz.

int main() {
	//The biggest hint: GO BY DIAGONALS not by horizontal/vertical.
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		scanf("%s", S[i] + 1);
	}

	int ans = 0;
	for (int sum = 2; sum <= N + M; sum++) {
		//try to choose if you can!
		//1 <= i <= N, 1 <= sum - i <= M
		//1 <= i <= N, sum - M <= i <= sum - 1
		//max(1, sum - M) <= i <= min(N, sum - 1)

		int xmn = max(1, sum - M), xmx = min(N, sum - 1);
		fillchar(dp, -2);
		dp[xmn - 1][0] = 0;

		for (int x = xmn; x <= xmx; x++) {
			int y = sum - x;
			//add one if can
			if (S[x][y] == 'G') {
				//vertical
				if (S[x - 1][y] == 'R' && S[x + 1][y] == 'W') {
					//cur is 1. prev can't be 2.
					dp[x][1] = max(dp[x - 1][0], dp[x - 1][1]) + 1;
				}

				if (S[x][y - 1] == 'R' && S[x][y + 1] == 'W') {
					//cur is 2. prev can't be 1.
					dp[x][2] = max(dp[x - 1][0], dp[x - 1][2]) + 1;
				}
			}

			//otherwise not add one
			dp[x][0] = max({dp[x - 1][0], dp[x - 1][1], dp[x - 1][2]});
		}
		ans += max({dp[xmx][0], dp[xmx][1], dp[xmx][2]});
	}
	printf("%d\n", ans);
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", S[i] + 1);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 5 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 5 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 4 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 4 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 3 ms 736 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 3 ms 744 KB Output is correct
35 Correct 3 ms 752 KB Output is correct
36 Correct 3 ms 752 KB Output is correct
37 Correct 2 ms 756 KB Output is correct
38 Correct 2 ms 760 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 3 ms 776 KB Output is correct
42 Correct 3 ms 780 KB Output is correct
43 Correct 2 ms 780 KB Output is correct
44 Correct 4 ms 780 KB Output is correct
45 Correct 4 ms 784 KB Output is correct
46 Correct 3 ms 788 KB Output is correct
47 Correct 2 ms 796 KB Output is correct
48 Correct 3 ms 796 KB Output is correct
49 Correct 2 ms 800 KB Output is correct
50 Correct 3 ms 804 KB Output is correct
51 Correct 3 ms 804 KB Output is correct
52 Correct 2 ms 812 KB Output is correct
53 Correct 3 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 4 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 5 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 4 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 4 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 732 KB Output is correct
31 Correct 3 ms 732 KB Output is correct
32 Correct 3 ms 736 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 3 ms 744 KB Output is correct
35 Correct 3 ms 752 KB Output is correct
36 Correct 3 ms 752 KB Output is correct
37 Correct 2 ms 756 KB Output is correct
38 Correct 2 ms 760 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 3 ms 776 KB Output is correct
42 Correct 3 ms 780 KB Output is correct
43 Correct 2 ms 780 KB Output is correct
44 Correct 4 ms 780 KB Output is correct
45 Correct 4 ms 784 KB Output is correct
46 Correct 3 ms 788 KB Output is correct
47 Correct 2 ms 796 KB Output is correct
48 Correct 3 ms 796 KB Output is correct
49 Correct 2 ms 800 KB Output is correct
50 Correct 3 ms 804 KB Output is correct
51 Correct 3 ms 804 KB Output is correct
52 Correct 2 ms 812 KB Output is correct
53 Correct 3 ms 816 KB Output is correct
54 Correct 8 ms 820 KB Output is correct
55 Correct 17 ms 9652 KB Output is correct
56 Correct 9 ms 9652 KB Output is correct
57 Correct 11 ms 9652 KB Output is correct
58 Correct 23 ms 9652 KB Output is correct
59 Correct 193 ms 19640 KB Output is correct
60 Correct 201 ms 28480 KB Output is correct
61 Correct 197 ms 37240 KB Output is correct
62 Correct 8 ms 37240 KB Output is correct
63 Correct 191 ms 45736 KB Output is correct
64 Correct 121 ms 54356 KB Output is correct
65 Correct 134 ms 63152 KB Output is correct
66 Correct 144 ms 71948 KB Output is correct
67 Correct 114 ms 80876 KB Output is correct
68 Correct 150 ms 89672 KB Output is correct
69 Correct 138 ms 98468 KB Output is correct
70 Correct 17 ms 98468 KB Output is correct
71 Correct 17 ms 98468 KB Output is correct
72 Correct 19 ms 98468 KB Output is correct
73 Correct 18 ms 98468 KB Output is correct
74 Correct 21 ms 98468 KB Output is correct
75 Correct 19 ms 98468 KB Output is correct
76 Correct 20 ms 99316 KB Output is correct
77 Correct 22 ms 100296 KB Output is correct
78 Correct 20 ms 101296 KB Output is correct
79 Correct 21 ms 102400 KB Output is correct
80 Correct 19 ms 103268 KB Output is correct
81 Correct 20 ms 104252 KB Output is correct
82 Correct 18 ms 105228 KB Output is correct
83 Correct 21 ms 106208 KB Output is correct
84 Correct 21 ms 107188 KB Output is correct
85 Correct 22 ms 108284 KB Output is correct
86 Correct 19 ms 109276 KB Output is correct
87 Correct 20 ms 110180 KB Output is correct
88 Correct 20 ms 111236 KB Output is correct
89 Correct 19 ms 112104 KB Output is correct
90 Correct 17 ms 113084 KB Output is correct