답안 #591536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591536 2022-07-07T14:45:56 Z piOOE Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
105 ms 127448 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 201;

ll dp[2][N][N][N];
int L[N], R[N], TR[N], TL[N];

void ckmin(ll &a, ll b) {
    if (a == -1 || a > b) {
        a = b;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, p;
    cin >> n >> p;
    for (int i = 0; i < n; ++i) {
        cin >> R[i];
        L[n - i - 1] = p - R[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> TR[i];
        TL[n - i - 1] = TR[i];
    }
    memset(dp, -1, sizeof(dp));
    //0 - in the left, 1 - in the right
    if (R[0] <= TR[0]) {
        dp[1][0][1][1] = R[0];
    } else {
        dp[1][0][1][0] = R[0];
    }
    if (L[0] <= TL[0]) {
        dp[0][1][0][1] = L[0];
    } else {
        dp[0][1][0][0] = L[0];
    }
    for (int sum = 1; sum < n; ++sum) {
        for (int f = 0; f <= sum; ++f) {
            int s = sum - f;
            for (int cnt = 0; cnt <= n; ++cnt) {
                if (dp[0][f][s][cnt] != -1) {
                    assert(f);
                    ll t = dp[0][f][s][cnt];
                    ll dist = L[f] - L[f - 1] + t;
                    ckmin(dp[0][f + 1][s][cnt + (dist <= TL[f])], dist);
                    dist = R[s] + L[f - 1] + t;
                    ckmin(dp[1][f][s + 1][cnt + (dist <= TR[s])], dist);
                }
                if (dp[1][f][s][cnt] != -1) {
                    assert(s);
                    ll t = dp[1][f][s][cnt];
                    ll dist = R[s - 1] + L[f] + t;
                    ckmin(dp[0][f + 1][s][cnt + (dist <= TL[f])], dist);
                    dist = t + R[s] - R[s - 1];
                    ckmin(dp[1][f][s + 1][cnt + (dist <= TR[s])], dist);
                }
            }
        }
    }
    for (int cnt = n; cnt >= 0; --cnt) {
        for (int sum = n; sum > 0; --sum) {
            for (int f = 0; f <= sum; ++f) {
                int s = sum - f;
                if (dp[0][f][s][cnt] != -1 || dp[1][f][s][cnt] != -1) {
                    cout << cnt;
                    return 0;
                }
            }
        }
    }
    cout << 0;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 127416 KB Output is correct
2 Correct 48 ms 127396 KB Output is correct
3 Correct 50 ms 127404 KB Output is correct
4 Correct 50 ms 127332 KB Output is correct
5 Correct 49 ms 127316 KB Output is correct
6 Correct 49 ms 127368 KB Output is correct
7 Correct 48 ms 127348 KB Output is correct
8 Correct 53 ms 127320 KB Output is correct
9 Correct 47 ms 127308 KB Output is correct
10 Correct 47 ms 127432 KB Output is correct
11 Correct 47 ms 127308 KB Output is correct
12 Correct 49 ms 127432 KB Output is correct
13 Correct 48 ms 127364 KB Output is correct
14 Correct 53 ms 127348 KB Output is correct
15 Correct 60 ms 127312 KB Output is correct
16 Correct 47 ms 127352 KB Output is correct
17 Correct 47 ms 127308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 127416 KB Output is correct
2 Correct 48 ms 127396 KB Output is correct
3 Correct 50 ms 127404 KB Output is correct
4 Correct 50 ms 127332 KB Output is correct
5 Correct 49 ms 127316 KB Output is correct
6 Correct 49 ms 127368 KB Output is correct
7 Correct 48 ms 127348 KB Output is correct
8 Correct 53 ms 127320 KB Output is correct
9 Correct 47 ms 127308 KB Output is correct
10 Correct 47 ms 127432 KB Output is correct
11 Correct 47 ms 127308 KB Output is correct
12 Correct 49 ms 127432 KB Output is correct
13 Correct 48 ms 127364 KB Output is correct
14 Correct 53 ms 127348 KB Output is correct
15 Correct 60 ms 127312 KB Output is correct
16 Correct 47 ms 127352 KB Output is correct
17 Correct 47 ms 127308 KB Output is correct
18 Correct 49 ms 127332 KB Output is correct
19 Correct 48 ms 127336 KB Output is correct
20 Correct 57 ms 127332 KB Output is correct
21 Correct 65 ms 127388 KB Output is correct
22 Correct 52 ms 127436 KB Output is correct
23 Correct 47 ms 127360 KB Output is correct
24 Correct 50 ms 127420 KB Output is correct
25 Correct 50 ms 127328 KB Output is correct
26 Correct 48 ms 127436 KB Output is correct
27 Correct 56 ms 127340 KB Output is correct
28 Correct 61 ms 127364 KB Output is correct
29 Correct 49 ms 127336 KB Output is correct
30 Correct 47 ms 127360 KB Output is correct
31 Correct 54 ms 127404 KB Output is correct
32 Correct 55 ms 127404 KB Output is correct
33 Correct 49 ms 127424 KB Output is correct
34 Correct 52 ms 127424 KB Output is correct
35 Correct 47 ms 127368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 127416 KB Output is correct
2 Correct 48 ms 127396 KB Output is correct
3 Correct 50 ms 127404 KB Output is correct
4 Correct 50 ms 127332 KB Output is correct
5 Correct 49 ms 127316 KB Output is correct
6 Correct 49 ms 127368 KB Output is correct
7 Correct 48 ms 127348 KB Output is correct
8 Correct 53 ms 127320 KB Output is correct
9 Correct 47 ms 127308 KB Output is correct
10 Correct 47 ms 127432 KB Output is correct
11 Correct 47 ms 127308 KB Output is correct
12 Correct 49 ms 127432 KB Output is correct
13 Correct 48 ms 127364 KB Output is correct
14 Correct 53 ms 127348 KB Output is correct
15 Correct 60 ms 127312 KB Output is correct
16 Correct 47 ms 127352 KB Output is correct
17 Correct 47 ms 127308 KB Output is correct
18 Correct 82 ms 127364 KB Output is correct
19 Correct 67 ms 127308 KB Output is correct
20 Correct 57 ms 127348 KB Output is correct
21 Correct 78 ms 127424 KB Output is correct
22 Correct 83 ms 127396 KB Output is correct
23 Correct 54 ms 127328 KB Output is correct
24 Correct 53 ms 127404 KB Output is correct
25 Correct 52 ms 127408 KB Output is correct
26 Correct 47 ms 127340 KB Output is correct
27 Correct 59 ms 127444 KB Output is correct
28 Correct 67 ms 127408 KB Output is correct
29 Correct 65 ms 127432 KB Output is correct
30 Correct 60 ms 127432 KB Output is correct
31 Correct 57 ms 127436 KB Output is correct
32 Correct 51 ms 127336 KB Output is correct
33 Correct 62 ms 127428 KB Output is correct
34 Correct 58 ms 127344 KB Output is correct
35 Correct 61 ms 127412 KB Output is correct
36 Correct 55 ms 127304 KB Output is correct
37 Correct 53 ms 127416 KB Output is correct
38 Correct 63 ms 127420 KB Output is correct
39 Correct 60 ms 127340 KB Output is correct
40 Correct 61 ms 127360 KB Output is correct
41 Correct 105 ms 127432 KB Output is correct
42 Correct 83 ms 127428 KB Output is correct
43 Correct 101 ms 127308 KB Output is correct
44 Correct 81 ms 127428 KB Output is correct
45 Correct 104 ms 127400 KB Output is correct
46 Correct 78 ms 127392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 127416 KB Output is correct
2 Correct 48 ms 127396 KB Output is correct
3 Correct 50 ms 127404 KB Output is correct
4 Correct 50 ms 127332 KB Output is correct
5 Correct 49 ms 127316 KB Output is correct
6 Correct 49 ms 127368 KB Output is correct
7 Correct 48 ms 127348 KB Output is correct
8 Correct 53 ms 127320 KB Output is correct
9 Correct 47 ms 127308 KB Output is correct
10 Correct 47 ms 127432 KB Output is correct
11 Correct 47 ms 127308 KB Output is correct
12 Correct 49 ms 127432 KB Output is correct
13 Correct 48 ms 127364 KB Output is correct
14 Correct 53 ms 127348 KB Output is correct
15 Correct 60 ms 127312 KB Output is correct
16 Correct 47 ms 127352 KB Output is correct
17 Correct 47 ms 127308 KB Output is correct
18 Correct 49 ms 127332 KB Output is correct
19 Correct 48 ms 127336 KB Output is correct
20 Correct 57 ms 127332 KB Output is correct
21 Correct 65 ms 127388 KB Output is correct
22 Correct 52 ms 127436 KB Output is correct
23 Correct 47 ms 127360 KB Output is correct
24 Correct 50 ms 127420 KB Output is correct
25 Correct 50 ms 127328 KB Output is correct
26 Correct 48 ms 127436 KB Output is correct
27 Correct 56 ms 127340 KB Output is correct
28 Correct 61 ms 127364 KB Output is correct
29 Correct 49 ms 127336 KB Output is correct
30 Correct 47 ms 127360 KB Output is correct
31 Correct 54 ms 127404 KB Output is correct
32 Correct 55 ms 127404 KB Output is correct
33 Correct 49 ms 127424 KB Output is correct
34 Correct 52 ms 127424 KB Output is correct
35 Correct 47 ms 127368 KB Output is correct
36 Correct 82 ms 127364 KB Output is correct
37 Correct 67 ms 127308 KB Output is correct
38 Correct 57 ms 127348 KB Output is correct
39 Correct 78 ms 127424 KB Output is correct
40 Correct 83 ms 127396 KB Output is correct
41 Correct 54 ms 127328 KB Output is correct
42 Correct 53 ms 127404 KB Output is correct
43 Correct 52 ms 127408 KB Output is correct
44 Correct 47 ms 127340 KB Output is correct
45 Correct 59 ms 127444 KB Output is correct
46 Correct 67 ms 127408 KB Output is correct
47 Correct 65 ms 127432 KB Output is correct
48 Correct 60 ms 127432 KB Output is correct
49 Correct 57 ms 127436 KB Output is correct
50 Correct 51 ms 127336 KB Output is correct
51 Correct 62 ms 127428 KB Output is correct
52 Correct 58 ms 127344 KB Output is correct
53 Correct 61 ms 127412 KB Output is correct
54 Correct 55 ms 127304 KB Output is correct
55 Correct 53 ms 127416 KB Output is correct
56 Correct 63 ms 127420 KB Output is correct
57 Correct 60 ms 127340 KB Output is correct
58 Correct 61 ms 127360 KB Output is correct
59 Correct 105 ms 127432 KB Output is correct
60 Correct 83 ms 127428 KB Output is correct
61 Correct 101 ms 127308 KB Output is correct
62 Correct 81 ms 127428 KB Output is correct
63 Correct 104 ms 127400 KB Output is correct
64 Correct 78 ms 127392 KB Output is correct
65 Correct 104 ms 127444 KB Output is correct
66 Correct 94 ms 127436 KB Output is correct
67 Correct 93 ms 127440 KB Output is correct
68 Correct 81 ms 127444 KB Output is correct
69 Correct 92 ms 127440 KB Output is correct
70 Correct 97 ms 127400 KB Output is correct
71 Correct 92 ms 127444 KB Output is correct
72 Correct 84 ms 127440 KB Output is correct
73 Correct 77 ms 127444 KB Output is correct
74 Correct 84 ms 127440 KB Output is correct
75 Correct 87 ms 127436 KB Output is correct
76 Correct 93 ms 127336 KB Output is correct
77 Correct 99 ms 127440 KB Output is correct
78 Correct 76 ms 127440 KB Output is correct
79 Correct 84 ms 127436 KB Output is correct
80 Correct 93 ms 127448 KB Output is correct
81 Correct 88 ms 127436 KB Output is correct
82 Correct 84 ms 127440 KB Output is correct
83 Correct 105 ms 127380 KB Output is correct
84 Correct 91 ms 127368 KB Output is correct
85 Correct 95 ms 127368 KB Output is correct
86 Correct 89 ms 127360 KB Output is correct
87 Correct 96 ms 127348 KB Output is correct
88 Correct 93 ms 127440 KB Output is correct
89 Correct 100 ms 127440 KB Output is correct
90 Correct 100 ms 127440 KB Output is correct
91 Correct 103 ms 127444 KB Output is correct
92 Correct 100 ms 127416 KB Output is correct
93 Correct 99 ms 127440 KB Output is correct