Submission #216345

# Submission time Handle Problem Language Result Execution time Memory
216345 2020-03-27T07:25:06 Z dolphingarlic Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
334 ms 505268 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;

const int INF = 1e9;

inline void mn(int &A, int B) { A = min(A, B); }

int a[401], t[401], dp[401][401][401][2];
// dp[i][j][k][l] = Min time if visited range = [i, j] with k stamps collected. l = Currently at i

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, p;
    cin >> n >> p;
    FOR(i, 0, n) {
        cin >> a[i];
        a[i + n + 1] = a[i];
    }
    FOR(i, 0, n) {
        cin >> t[i];
        t[i + n + 1] = t[i];
    }
    
    memset(dp, 0x3f, sizeof(dp));
    dp[n][n][0][0] = 0;
    int ans = 0;
    FOR(range, 0, n + 1) FOR(i, n - range, n + 1) FOR(k, 0, range + 1) FOR(l, 0, 2) {
        int j = i + range, curr = (l ? i : j);
        if (dp[i][j][k][l] > INF) continue;
        
        if (j < 2 * n - 1) {
            int dist = min(p - abs(a[curr] - a[j + 1]), abs(a[curr] - a[j + 1])) + dp[i][j][k][l];
            mn(dp[i][j + 1][k + (dist <= t[j + 1])][0], dist);
        }

        if (i) {
            int dist = min(p - abs(a[curr] - a[i - 1]), abs(a[curr] - a[i - 1])) + dp[i][j][k][l];
            mn(dp[i - 1][j][k + (dist <= t[i - 1])][1], dist);
        }
        ans = max(ans, k);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 249 ms 505080 KB Output is correct
2 Correct 248 ms 505080 KB Output is correct
3 Correct 260 ms 505080 KB Output is correct
4 Correct 249 ms 505080 KB Output is correct
5 Correct 249 ms 505080 KB Output is correct
6 Correct 253 ms 505112 KB Output is correct
7 Correct 254 ms 505080 KB Output is correct
8 Correct 249 ms 505084 KB Output is correct
9 Correct 254 ms 505080 KB Output is correct
10 Correct 254 ms 505080 KB Output is correct
11 Correct 250 ms 505080 KB Output is correct
12 Correct 249 ms 505080 KB Output is correct
13 Correct 255 ms 505080 KB Output is correct
14 Correct 255 ms 505080 KB Output is correct
15 Correct 249 ms 505080 KB Output is correct
16 Correct 248 ms 505072 KB Output is correct
17 Correct 263 ms 505080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 505080 KB Output is correct
2 Correct 248 ms 505080 KB Output is correct
3 Correct 260 ms 505080 KB Output is correct
4 Correct 249 ms 505080 KB Output is correct
5 Correct 249 ms 505080 KB Output is correct
6 Correct 253 ms 505112 KB Output is correct
7 Correct 254 ms 505080 KB Output is correct
8 Correct 249 ms 505084 KB Output is correct
9 Correct 254 ms 505080 KB Output is correct
10 Correct 254 ms 505080 KB Output is correct
11 Correct 250 ms 505080 KB Output is correct
12 Correct 249 ms 505080 KB Output is correct
13 Correct 255 ms 505080 KB Output is correct
14 Correct 255 ms 505080 KB Output is correct
15 Correct 249 ms 505080 KB Output is correct
16 Correct 248 ms 505072 KB Output is correct
17 Correct 263 ms 505080 KB Output is correct
18 Correct 248 ms 505080 KB Output is correct
19 Correct 249 ms 505080 KB Output is correct
20 Correct 254 ms 505080 KB Output is correct
21 Correct 250 ms 505080 KB Output is correct
22 Correct 250 ms 505040 KB Output is correct
23 Correct 257 ms 505080 KB Output is correct
24 Correct 248 ms 505080 KB Output is correct
25 Correct 257 ms 505132 KB Output is correct
26 Correct 247 ms 505080 KB Output is correct
27 Correct 246 ms 505080 KB Output is correct
28 Correct 251 ms 505008 KB Output is correct
29 Correct 247 ms 505080 KB Output is correct
30 Correct 253 ms 505208 KB Output is correct
31 Correct 257 ms 505080 KB Output is correct
32 Correct 257 ms 505080 KB Output is correct
33 Correct 254 ms 505268 KB Output is correct
34 Correct 261 ms 505056 KB Output is correct
35 Correct 251 ms 505080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 505080 KB Output is correct
2 Correct 248 ms 505080 KB Output is correct
3 Correct 260 ms 505080 KB Output is correct
4 Correct 249 ms 505080 KB Output is correct
5 Correct 249 ms 505080 KB Output is correct
6 Correct 253 ms 505112 KB Output is correct
7 Correct 254 ms 505080 KB Output is correct
8 Correct 249 ms 505084 KB Output is correct
9 Correct 254 ms 505080 KB Output is correct
10 Correct 254 ms 505080 KB Output is correct
11 Correct 250 ms 505080 KB Output is correct
12 Correct 249 ms 505080 KB Output is correct
13 Correct 255 ms 505080 KB Output is correct
14 Correct 255 ms 505080 KB Output is correct
15 Correct 249 ms 505080 KB Output is correct
16 Correct 248 ms 505072 KB Output is correct
17 Correct 263 ms 505080 KB Output is correct
18 Correct 281 ms 505080 KB Output is correct
19 Correct 267 ms 505116 KB Output is correct
20 Correct 265 ms 505080 KB Output is correct
21 Correct 268 ms 505080 KB Output is correct
22 Correct 290 ms 505048 KB Output is correct
23 Correct 276 ms 505096 KB Output is correct
24 Correct 256 ms 505056 KB Output is correct
25 Correct 263 ms 505064 KB Output is correct
26 Correct 261 ms 505044 KB Output is correct
27 Correct 271 ms 505056 KB Output is correct
28 Correct 263 ms 505080 KB Output is correct
29 Correct 276 ms 505112 KB Output is correct
30 Correct 264 ms 505080 KB Output is correct
31 Correct 261 ms 505056 KB Output is correct
32 Correct 266 ms 505056 KB Output is correct
33 Correct 270 ms 505080 KB Output is correct
34 Correct 264 ms 505080 KB Output is correct
35 Correct 286 ms 505080 KB Output is correct
36 Correct 254 ms 505080 KB Output is correct
37 Correct 268 ms 505056 KB Output is correct
38 Correct 261 ms 505104 KB Output is correct
39 Correct 260 ms 505080 KB Output is correct
40 Correct 265 ms 505100 KB Output is correct
41 Correct 315 ms 505080 KB Output is correct
42 Correct 259 ms 505056 KB Output is correct
43 Correct 321 ms 505108 KB Output is correct
44 Correct 268 ms 505060 KB Output is correct
45 Correct 331 ms 505156 KB Output is correct
46 Correct 275 ms 505080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 505080 KB Output is correct
2 Correct 248 ms 505080 KB Output is correct
3 Correct 260 ms 505080 KB Output is correct
4 Correct 249 ms 505080 KB Output is correct
5 Correct 249 ms 505080 KB Output is correct
6 Correct 253 ms 505112 KB Output is correct
7 Correct 254 ms 505080 KB Output is correct
8 Correct 249 ms 505084 KB Output is correct
9 Correct 254 ms 505080 KB Output is correct
10 Correct 254 ms 505080 KB Output is correct
11 Correct 250 ms 505080 KB Output is correct
12 Correct 249 ms 505080 KB Output is correct
13 Correct 255 ms 505080 KB Output is correct
14 Correct 255 ms 505080 KB Output is correct
15 Correct 249 ms 505080 KB Output is correct
16 Correct 248 ms 505072 KB Output is correct
17 Correct 263 ms 505080 KB Output is correct
18 Correct 248 ms 505080 KB Output is correct
19 Correct 249 ms 505080 KB Output is correct
20 Correct 254 ms 505080 KB Output is correct
21 Correct 250 ms 505080 KB Output is correct
22 Correct 250 ms 505040 KB Output is correct
23 Correct 257 ms 505080 KB Output is correct
24 Correct 248 ms 505080 KB Output is correct
25 Correct 257 ms 505132 KB Output is correct
26 Correct 247 ms 505080 KB Output is correct
27 Correct 246 ms 505080 KB Output is correct
28 Correct 251 ms 505008 KB Output is correct
29 Correct 247 ms 505080 KB Output is correct
30 Correct 253 ms 505208 KB Output is correct
31 Correct 257 ms 505080 KB Output is correct
32 Correct 257 ms 505080 KB Output is correct
33 Correct 254 ms 505268 KB Output is correct
34 Correct 261 ms 505056 KB Output is correct
35 Correct 251 ms 505080 KB Output is correct
36 Correct 281 ms 505080 KB Output is correct
37 Correct 267 ms 505116 KB Output is correct
38 Correct 265 ms 505080 KB Output is correct
39 Correct 268 ms 505080 KB Output is correct
40 Correct 290 ms 505048 KB Output is correct
41 Correct 276 ms 505096 KB Output is correct
42 Correct 256 ms 505056 KB Output is correct
43 Correct 263 ms 505064 KB Output is correct
44 Correct 261 ms 505044 KB Output is correct
45 Correct 271 ms 505056 KB Output is correct
46 Correct 263 ms 505080 KB Output is correct
47 Correct 276 ms 505112 KB Output is correct
48 Correct 264 ms 505080 KB Output is correct
49 Correct 261 ms 505056 KB Output is correct
50 Correct 266 ms 505056 KB Output is correct
51 Correct 270 ms 505080 KB Output is correct
52 Correct 264 ms 505080 KB Output is correct
53 Correct 286 ms 505080 KB Output is correct
54 Correct 254 ms 505080 KB Output is correct
55 Correct 268 ms 505056 KB Output is correct
56 Correct 261 ms 505104 KB Output is correct
57 Correct 260 ms 505080 KB Output is correct
58 Correct 265 ms 505100 KB Output is correct
59 Correct 315 ms 505080 KB Output is correct
60 Correct 259 ms 505056 KB Output is correct
61 Correct 321 ms 505108 KB Output is correct
62 Correct 268 ms 505060 KB Output is correct
63 Correct 331 ms 505156 KB Output is correct
64 Correct 275 ms 505080 KB Output is correct
65 Correct 277 ms 505080 KB Output is correct
66 Correct 281 ms 505256 KB Output is correct
67 Correct 261 ms 505064 KB Output is correct
68 Correct 263 ms 505080 KB Output is correct
69 Correct 287 ms 505248 KB Output is correct
70 Correct 271 ms 505048 KB Output is correct
71 Correct 268 ms 505080 KB Output is correct
72 Correct 278 ms 505104 KB Output is correct
73 Correct 270 ms 505124 KB Output is correct
74 Correct 289 ms 505080 KB Output is correct
75 Correct 272 ms 505028 KB Output is correct
76 Correct 305 ms 505080 KB Output is correct
77 Correct 271 ms 505228 KB Output is correct
78 Correct 297 ms 505128 KB Output is correct
79 Correct 261 ms 505080 KB Output is correct
80 Correct 300 ms 505084 KB Output is correct
81 Correct 259 ms 505080 KB Output is correct
82 Correct 334 ms 505080 KB Output is correct
83 Correct 265 ms 505084 KB Output is correct
84 Correct 306 ms 505072 KB Output is correct
85 Correct 292 ms 505080 KB Output is correct
86 Correct 290 ms 505028 KB Output is correct
87 Correct 280 ms 505080 KB Output is correct
88 Correct 310 ms 505056 KB Output is correct
89 Correct 270 ms 505132 KB Output is correct
90 Correct 269 ms 505080 KB Output is correct
91 Correct 268 ms 505056 KB Output is correct
92 Correct 282 ms 505128 KB Output is correct
93 Correct 266 ms 505044 KB Output is correct