답안 #373172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373172 2021-03-03T15:41:26 Z morato Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
171 ms 132204 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 205;
const long long LINF = 9e18;

int v[N], n, m;
long long t[N], dp[N][N][N][2]; // l, r, qtd] = t min

inline long long dist(int a, int b) {
	if (a > b) return m - a + b;
	return b - a;
}

inline void minself(long long &a, long long b) {
	a = min(a, b);
}

inline int ant(int x) {
	return (x + n - 1) % n;
}

inline int nxt(int x) {
	return (x + 1) % n;
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	t[0] = -1;
	n++;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				for (int a = 0; a <= 1; a++) {
					dp[i][j][k][a] = LINF;
				}
			}
		}
	}
	// dp[ l ][ r ][ qtd ][ estou na ponta da esquerda ou direita ] = tempo minimo pra pegar o intervalo [l, r]
	dp[0][0][0][0] = 0;
	for (int tam = 0; tam < n; tam++) {
		for (int l = 0; l < n; l++) {
			int r = (l + tam) % n;
			for (int k = 0; k <= tam	; k++) {
				if (min(dp[l][r][k][0], dp[l][r][k][1]) == LINF || nxt(r) == l) continue;
				//cout << l << "(" << nxt(l) << ") " << r << "(" << nxt(r) << ") " << k << '\n';
				// vou da esquerda para a esquerda
				long long cost = dp[l][r][k][0] + dist(v[ant(l)], v[l]);
				minself(dp[ant(l)][r][k + (t[ant(l)] >= cost)][0], cost);
				// vou da esquerda para a direita
				cost = dp[l][r][k][0] + dist(v[l], v[nxt(r)]);
				minself(dp[l][nxt(r)][k + (t[nxt(r)] >= cost)][1], cost);
				// vou da direita para a direita
				cost = dp[l][r][k][1] + dist(v[r], v[nxt(r)]);
				minself(dp[l][nxt(r)][k + (t[nxt(r)] >= cost)][1], cost);
				// vou da direita para a esquerda
				cost = dp[l][r][k][1] + dist(v[ant(l)], v[r]);
				minself(dp[ant(l)][r][k + (t[ant(l)] >= cost)][0], cost);
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k <= n; k++) {
				if (min(dp[i][j][k][0], dp[i][j][k][1]) < LINF) {
					ans = max(ans, 1ll * k);
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 1004 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1280 KB Output is correct
34 Correct 1 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 124 ms 106232 KB Output is correct
19 Correct 72 ms 64620 KB Output is correct
20 Correct 31 ms 34668 KB Output is correct
21 Correct 68 ms 61036 KB Output is correct
22 Correct 81 ms 78956 KB Output is correct
23 Correct 42 ms 29564 KB Output is correct
24 Correct 18 ms 23168 KB Output is correct
25 Correct 28 ms 28908 KB Output is correct
26 Correct 8 ms 11244 KB Output is correct
27 Correct 30 ms 30188 KB Output is correct
28 Correct 17 ms 21612 KB Output is correct
29 Correct 28 ms 30828 KB Output is correct
30 Correct 20 ms 24384 KB Output is correct
31 Correct 27 ms 28908 KB Output is correct
32 Correct 12 ms 15340 KB Output is correct
33 Correct 26 ms 28908 KB Output is correct
34 Correct 8 ms 10476 KB Output is correct
35 Correct 27 ms 28396 KB Output is correct
36 Correct 12 ms 13676 KB Output is correct
37 Correct 28 ms 30188 KB Output is correct
38 Correct 16 ms 16748 KB Output is correct
39 Correct 25 ms 31468 KB Output is correct
40 Correct 14 ms 18540 KB Output is correct
41 Correct 171 ms 130796 KB Output is correct
42 Correct 68 ms 88300 KB Output is correct
43 Correct 151 ms 130980 KB Output is correct
44 Correct 65 ms 87276 KB Output is correct
45 Correct 164 ms 130924 KB Output is correct
46 Correct 73 ms 88300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 1004 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 1 ms 1280 KB Output is correct
34 Correct 1 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
36 Correct 124 ms 106232 KB Output is correct
37 Correct 72 ms 64620 KB Output is correct
38 Correct 31 ms 34668 KB Output is correct
39 Correct 68 ms 61036 KB Output is correct
40 Correct 81 ms 78956 KB Output is correct
41 Correct 42 ms 29564 KB Output is correct
42 Correct 18 ms 23168 KB Output is correct
43 Correct 28 ms 28908 KB Output is correct
44 Correct 8 ms 11244 KB Output is correct
45 Correct 30 ms 30188 KB Output is correct
46 Correct 17 ms 21612 KB Output is correct
47 Correct 28 ms 30828 KB Output is correct
48 Correct 20 ms 24384 KB Output is correct
49 Correct 27 ms 28908 KB Output is correct
50 Correct 12 ms 15340 KB Output is correct
51 Correct 26 ms 28908 KB Output is correct
52 Correct 8 ms 10476 KB Output is correct
53 Correct 27 ms 28396 KB Output is correct
54 Correct 12 ms 13676 KB Output is correct
55 Correct 28 ms 30188 KB Output is correct
56 Correct 16 ms 16748 KB Output is correct
57 Correct 25 ms 31468 KB Output is correct
58 Correct 14 ms 18540 KB Output is correct
59 Correct 171 ms 130796 KB Output is correct
60 Correct 68 ms 88300 KB Output is correct
61 Correct 151 ms 130980 KB Output is correct
62 Correct 65 ms 87276 KB Output is correct
63 Correct 164 ms 130924 KB Output is correct
64 Correct 73 ms 88300 KB Output is correct
65 Correct 128 ms 118160 KB Output is correct
66 Correct 116 ms 108480 KB Output is correct
67 Correct 114 ms 103916 KB Output is correct
68 Correct 112 ms 95852 KB Output is correct
69 Correct 128 ms 116844 KB Output is correct
70 Correct 132 ms 112108 KB Output is correct
71 Correct 117 ms 113260 KB Output is correct
72 Correct 139 ms 114540 KB Output is correct
73 Correct 98 ms 106240 KB Output is correct
74 Correct 126 ms 99308 KB Output is correct
75 Correct 106 ms 109676 KB Output is correct
76 Correct 161 ms 125676 KB Output is correct
77 Correct 136 ms 125676 KB Output is correct
78 Correct 106 ms 97008 KB Output is correct
79 Correct 110 ms 100460 KB Output is correct
80 Correct 166 ms 123116 KB Output is correct
81 Correct 118 ms 101632 KB Output is correct
82 Correct 101 ms 107372 KB Output is correct
83 Correct 141 ms 130796 KB Output is correct
84 Correct 105 ms 112108 KB Output is correct
85 Correct 118 ms 121836 KB Output is correct
86 Correct 116 ms 119404 KB Output is correct
87 Correct 119 ms 109676 KB Output is correct
88 Correct 168 ms 132076 KB Output is correct
89 Correct 153 ms 132076 KB Output is correct
90 Correct 84 ms 110828 KB Output is correct
91 Correct 169 ms 132204 KB Output is correct
92 Correct 150 ms 132076 KB Output is correct
93 Correct 101 ms 129516 KB Output is correct