Submission #554593

# Submission time Handle Problem Language Result Execution time Memory
554593 2022-04-28T20:59:46 Z rainboy JOI15_cardgame2 (JOI15_cardgame2) C
100 / 100
258 ms 4276 KB
#include <stdio.h>
#include <string.h>

#define N	500

int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int xx[N], yy[N], vv[N], dp[N + 1][N + 1], dq[N + 1][N + 1], dp_[N + 1][N + 1], dq_[N + 1][N + 1];
	int n, i, j, k, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &vv[i]);
	ans = 0;
	for (k = 2; k <= n + 1; k++) {
		for (i = 0; i < k; i++) {
			memset(dp_[i], -1, k * sizeof *dp_[i]);
			memset(dq_[i], -1, k * sizeof *dq_[i]);
		}
		if (k == 2) {
			dp_[1][0] = vv[0];
			if (n >= 3)
				dq_[0][1] = vv[2];
		} else
			for (i = 0; i + 1 < k; i++)
				for (j = 0; j + 1 < k; j++) {
					int x;

					if ((x = dp[i][j]) != -1) {
						if (xx[j] == xx[i] || yy[j] == yy[i])
							dp_[k - 1][i] = max(dp_[k - 1][i], x + vv[i]);
						if (k < n && (xx[j] == xx[k] || yy[j] == yy[k]))
							dq_[i][k - 1] = max(dq_[i][k - 1], x + vv[k]);
					}
					if ((x = dq[i][j]) != -1) {
						if (xx[k - 1] == xx[i] || yy[k - 1] == yy[i])
							dp_[j][i] = max(dp_[j][i], x + vv[i]);
						if (k < n && (xx[k - 1] == xx[k] || yy[k - 1] == yy[k]))
							dq_[i][j] = max(dq_[i][j], x + vv[k]);
					}
				}
		for (i = 0; i < k; i++)
			for (j = 0; j < k; j++) {
				dp[i][j] = dp_[i][j], dq[i][j] = dq_[i][j];
				ans = max(ans, max(dp[i][j], dq[i][j]));
			}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

cardgame2.c: In function 'main':
cardgame2.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
cardgame2.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%d%d", &xx[i], &yy[i], &vv[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 292 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 676 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 292 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 676 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 151 ms 4184 KB Output is correct
45 Correct 160 ms 4188 KB Output is correct
46 Correct 143 ms 4160 KB Output is correct
47 Correct 153 ms 4144 KB Output is correct
48 Correct 140 ms 4172 KB Output is correct
49 Correct 144 ms 4224 KB Output is correct
50 Correct 158 ms 4168 KB Output is correct
51 Correct 150 ms 4240 KB Output is correct
52 Correct 149 ms 4136 KB Output is correct
53 Correct 143 ms 4216 KB Output is correct
54 Correct 140 ms 4276 KB Output is correct
55 Correct 142 ms 4176 KB Output is correct
56 Correct 145 ms 4144 KB Output is correct
57 Correct 140 ms 4172 KB Output is correct
58 Correct 149 ms 4152 KB Output is correct
59 Correct 154 ms 4104 KB Output is correct
60 Correct 140 ms 4144 KB Output is correct
61 Correct 147 ms 4108 KB Output is correct
62 Correct 146 ms 4144 KB Output is correct
63 Correct 258 ms 4212 KB Output is correct
64 Correct 198 ms 4192 KB Output is correct
65 Correct 178 ms 4244 KB Output is correct
66 Correct 172 ms 4164 KB Output is correct
67 Correct 164 ms 4180 KB Output is correct