Submission #254900

# Submission time Handle Problem Language Result Execution time Memory
254900 2020-07-30T19:57:14 Z imeimi2000 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
443 ms 65024 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long llong;

const llong inf = 1e18;
int n, L;
int X[202], T[202];
llong dp[202][202][202];

int dist(int x, int y) {
    int ret = abs(X[x] - X[y]);
    return min(ret, L - ret);
}

llong get(int x, int y, int c) {
    if (c < 0) return inf;
    if (x < 0 || x > n + 1) return inf;
    if (y < 0 || y > n + 1) return inf;
    if (dp[c][x][y] != -1) return dp[c][x][y];
    llong ret = inf;
    int px = x;
    if (x < y) --px; else ++px;
    ret = min(ret, get(px, y, c) + dist(px, x));
    ret = min(ret, get(y, px, c) + dist(y, x));
    if (get(px, y, c - 1) + dist(px, x) <= T[x]) ret = min(ret, get(px, y, c - 1) + dist(px, x));
    if (get(y, px, c - 1) + dist(y, x) <= T[x]) ret = min(ret, get(y, px, c - 1) + dist(y, x));
    return dp[c][x][y] = ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> L;
    for (int i = 1; i <= n; ++i) cin >> X[i]; X[n + 1] = L;
    for (int i = 1; i <= n; ++i) cin >> T[i]; T[0] = T[n + 1] = -1;
    memset(dp, -1, sizeof(dp));
    dp[0][0][n + 1] = 0;
    dp[0][n + 1][0] = 0;
    for (int i = 1; i <= n; ++i) dp[i][0][n + 1] = dp[i][n + 1][0] = inf;
    for (int ans = n; ans > 0; --ans) {
        for (int i = 1; i <= n; ++i) {
            if (get(i - 1, i, ans) < inf || get(i, i - 1, ans) < inf) {
                printf("%d\n", ans);
                return 0;
            }
        }
    }
    printf("0\n");
    return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:34:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 1; i <= n; ++i) cin >> X[i]; X[n + 1] = L;
     ^~~
ho_t3.cpp:34:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i = 1; i <= n; ++i) cin >> X[i]; X[n + 1] = L;
                                               ^
ho_t3.cpp:35:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 1; i <= n; ++i) cin >> T[i]; T[0] = T[n + 1] = -1;
     ^~~
ho_t3.cpp:35:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (int i = 1; i <= n; ++i) cin >> T[i]; T[0] = T[n + 1] = -1;
                                               ^
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64896 KB Output is correct
2 Correct 32 ms 64896 KB Output is correct
3 Correct 37 ms 64888 KB Output is correct
4 Correct 36 ms 64888 KB Output is correct
5 Correct 37 ms 64888 KB Output is correct
6 Correct 36 ms 64888 KB Output is correct
7 Correct 33 ms 64888 KB Output is correct
8 Correct 37 ms 64888 KB Output is correct
9 Correct 33 ms 64888 KB Output is correct
10 Correct 36 ms 64892 KB Output is correct
11 Correct 37 ms 64888 KB Output is correct
12 Correct 33 ms 64888 KB Output is correct
13 Correct 37 ms 64888 KB Output is correct
14 Correct 33 ms 64888 KB Output is correct
15 Correct 33 ms 64888 KB Output is correct
16 Correct 33 ms 64888 KB Output is correct
17 Correct 33 ms 64888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64896 KB Output is correct
2 Correct 32 ms 64896 KB Output is correct
3 Correct 37 ms 64888 KB Output is correct
4 Correct 36 ms 64888 KB Output is correct
5 Correct 37 ms 64888 KB Output is correct
6 Correct 36 ms 64888 KB Output is correct
7 Correct 33 ms 64888 KB Output is correct
8 Correct 37 ms 64888 KB Output is correct
9 Correct 33 ms 64888 KB Output is correct
10 Correct 36 ms 64892 KB Output is correct
11 Correct 37 ms 64888 KB Output is correct
12 Correct 33 ms 64888 KB Output is correct
13 Correct 37 ms 64888 KB Output is correct
14 Correct 33 ms 64888 KB Output is correct
15 Correct 33 ms 64888 KB Output is correct
16 Correct 33 ms 64888 KB Output is correct
17 Correct 33 ms 64888 KB Output is correct
18 Correct 35 ms 64864 KB Output is correct
19 Correct 36 ms 64888 KB Output is correct
20 Correct 38 ms 64868 KB Output is correct
21 Correct 37 ms 64888 KB Output is correct
22 Correct 33 ms 64888 KB Output is correct
23 Correct 37 ms 64888 KB Output is correct
24 Correct 33 ms 64888 KB Output is correct
25 Correct 40 ms 64888 KB Output is correct
26 Correct 33 ms 64888 KB Output is correct
27 Correct 33 ms 64888 KB Output is correct
28 Correct 33 ms 64896 KB Output is correct
29 Correct 37 ms 64888 KB Output is correct
30 Correct 33 ms 64896 KB Output is correct
31 Correct 33 ms 64888 KB Output is correct
32 Correct 33 ms 64888 KB Output is correct
33 Correct 38 ms 64888 KB Output is correct
34 Correct 34 ms 64888 KB Output is correct
35 Correct 33 ms 64888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64896 KB Output is correct
2 Correct 32 ms 64896 KB Output is correct
3 Correct 37 ms 64888 KB Output is correct
4 Correct 36 ms 64888 KB Output is correct
5 Correct 37 ms 64888 KB Output is correct
6 Correct 36 ms 64888 KB Output is correct
7 Correct 33 ms 64888 KB Output is correct
8 Correct 37 ms 64888 KB Output is correct
9 Correct 33 ms 64888 KB Output is correct
10 Correct 36 ms 64892 KB Output is correct
11 Correct 37 ms 64888 KB Output is correct
12 Correct 33 ms 64888 KB Output is correct
13 Correct 37 ms 64888 KB Output is correct
14 Correct 33 ms 64888 KB Output is correct
15 Correct 33 ms 64888 KB Output is correct
16 Correct 33 ms 64888 KB Output is correct
17 Correct 33 ms 64888 KB Output is correct
18 Correct 259 ms 65016 KB Output is correct
19 Correct 116 ms 64888 KB Output is correct
20 Correct 65 ms 64888 KB Output is correct
21 Correct 113 ms 64888 KB Output is correct
22 Correct 145 ms 64888 KB Output is correct
23 Correct 47 ms 65016 KB Output is correct
24 Correct 66 ms 64888 KB Output is correct
25 Correct 43 ms 64888 KB Output is correct
26 Correct 37 ms 64888 KB Output is correct
27 Correct 44 ms 64888 KB Output is correct
28 Correct 48 ms 64916 KB Output is correct
29 Correct 57 ms 64896 KB Output is correct
30 Correct 55 ms 65016 KB Output is correct
31 Correct 66 ms 64892 KB Output is correct
32 Correct 42 ms 64896 KB Output is correct
33 Correct 58 ms 64864 KB Output is correct
34 Correct 37 ms 64896 KB Output is correct
35 Correct 66 ms 64888 KB Output is correct
36 Correct 43 ms 64888 KB Output is correct
37 Correct 66 ms 64888 KB Output is correct
38 Correct 45 ms 65016 KB Output is correct
39 Correct 71 ms 64896 KB Output is correct
40 Correct 45 ms 64888 KB Output is correct
41 Correct 257 ms 64888 KB Output is correct
42 Correct 219 ms 64908 KB Output is correct
43 Correct 238 ms 64896 KB Output is correct
44 Correct 215 ms 64888 KB Output is correct
45 Correct 253 ms 65016 KB Output is correct
46 Correct 221 ms 64892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 64896 KB Output is correct
2 Correct 32 ms 64896 KB Output is correct
3 Correct 37 ms 64888 KB Output is correct
4 Correct 36 ms 64888 KB Output is correct
5 Correct 37 ms 64888 KB Output is correct
6 Correct 36 ms 64888 KB Output is correct
7 Correct 33 ms 64888 KB Output is correct
8 Correct 37 ms 64888 KB Output is correct
9 Correct 33 ms 64888 KB Output is correct
10 Correct 36 ms 64892 KB Output is correct
11 Correct 37 ms 64888 KB Output is correct
12 Correct 33 ms 64888 KB Output is correct
13 Correct 37 ms 64888 KB Output is correct
14 Correct 33 ms 64888 KB Output is correct
15 Correct 33 ms 64888 KB Output is correct
16 Correct 33 ms 64888 KB Output is correct
17 Correct 33 ms 64888 KB Output is correct
18 Correct 35 ms 64864 KB Output is correct
19 Correct 36 ms 64888 KB Output is correct
20 Correct 38 ms 64868 KB Output is correct
21 Correct 37 ms 64888 KB Output is correct
22 Correct 33 ms 64888 KB Output is correct
23 Correct 37 ms 64888 KB Output is correct
24 Correct 33 ms 64888 KB Output is correct
25 Correct 40 ms 64888 KB Output is correct
26 Correct 33 ms 64888 KB Output is correct
27 Correct 33 ms 64888 KB Output is correct
28 Correct 33 ms 64896 KB Output is correct
29 Correct 37 ms 64888 KB Output is correct
30 Correct 33 ms 64896 KB Output is correct
31 Correct 33 ms 64888 KB Output is correct
32 Correct 33 ms 64888 KB Output is correct
33 Correct 38 ms 64888 KB Output is correct
34 Correct 34 ms 64888 KB Output is correct
35 Correct 33 ms 64888 KB Output is correct
36 Correct 259 ms 65016 KB Output is correct
37 Correct 116 ms 64888 KB Output is correct
38 Correct 65 ms 64888 KB Output is correct
39 Correct 113 ms 64888 KB Output is correct
40 Correct 145 ms 64888 KB Output is correct
41 Correct 47 ms 65016 KB Output is correct
42 Correct 66 ms 64888 KB Output is correct
43 Correct 43 ms 64888 KB Output is correct
44 Correct 37 ms 64888 KB Output is correct
45 Correct 44 ms 64888 KB Output is correct
46 Correct 48 ms 64916 KB Output is correct
47 Correct 57 ms 64896 KB Output is correct
48 Correct 55 ms 65016 KB Output is correct
49 Correct 66 ms 64892 KB Output is correct
50 Correct 42 ms 64896 KB Output is correct
51 Correct 58 ms 64864 KB Output is correct
52 Correct 37 ms 64896 KB Output is correct
53 Correct 66 ms 64888 KB Output is correct
54 Correct 43 ms 64888 KB Output is correct
55 Correct 66 ms 64888 KB Output is correct
56 Correct 45 ms 65016 KB Output is correct
57 Correct 71 ms 64896 KB Output is correct
58 Correct 45 ms 64888 KB Output is correct
59 Correct 257 ms 64888 KB Output is correct
60 Correct 219 ms 64908 KB Output is correct
61 Correct 238 ms 64896 KB Output is correct
62 Correct 215 ms 64888 KB Output is correct
63 Correct 253 ms 65016 KB Output is correct
64 Correct 221 ms 64892 KB Output is correct
65 Correct 286 ms 64888 KB Output is correct
66 Correct 227 ms 64888 KB Output is correct
67 Correct 218 ms 64888 KB Output is correct
68 Correct 198 ms 64888 KB Output is correct
69 Correct 243 ms 64888 KB Output is correct
70 Correct 119 ms 64888 KB Output is correct
71 Correct 262 ms 65016 KB Output is correct
72 Correct 126 ms 64888 KB Output is correct
73 Correct 237 ms 64888 KB Output is correct
74 Correct 112 ms 64888 KB Output is correct
75 Correct 275 ms 64920 KB Output is correct
76 Correct 212 ms 64888 KB Output is correct
77 Correct 323 ms 64888 KB Output is correct
78 Correct 162 ms 65016 KB Output is correct
79 Correct 212 ms 64888 KB Output is correct
80 Correct 228 ms 64888 KB Output is correct
81 Correct 239 ms 64888 KB Output is correct
82 Correct 274 ms 64888 KB Output is correct
83 Correct 443 ms 65020 KB Output is correct
84 Correct 323 ms 64888 KB Output is correct
85 Correct 261 ms 64888 KB Output is correct
86 Correct 312 ms 64892 KB Output is correct
87 Correct 268 ms 65024 KB Output is correct
88 Correct 154 ms 65016 KB Output is correct
89 Correct 270 ms 64888 KB Output is correct
90 Correct 309 ms 64888 KB Output is correct
91 Correct 148 ms 64924 KB Output is correct
92 Correct 290 ms 64896 KB Output is correct
93 Correct 412 ms 65016 KB Output is correct