Submission #591535

# Submission time Handle Problem Language Result Execution time Memory
591535 2022-07-07T14:45:25 Z piOOE Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
105 ms 127468 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);
                    int t = dp[0][f][s][cnt];
                    int 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);
                    int t = dp[1][f][s][cnt];
                    int 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;
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 127308 KB Output is correct
2 Correct 49 ms 127316 KB Output is correct
3 Correct 48 ms 127340 KB Output is correct
4 Correct 47 ms 127352 KB Output is correct
5 Correct 46 ms 127432 KB Output is correct
6 Correct 48 ms 127308 KB Output is correct
7 Correct 58 ms 127368 KB Output is correct
8 Correct 47 ms 127328 KB Output is correct
9 Correct 46 ms 127428 KB Output is correct
10 Correct 47 ms 127400 KB Output is correct
11 Correct 52 ms 127408 KB Output is correct
12 Correct 49 ms 127344 KB Output is correct
13 Correct 48 ms 127312 KB Output is correct
14 Correct 53 ms 127376 KB Output is correct
15 Correct 51 ms 127380 KB Output is correct
16 Correct 47 ms 127432 KB Output is correct
17 Correct 48 ms 127364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 127308 KB Output is correct
2 Correct 49 ms 127316 KB Output is correct
3 Correct 48 ms 127340 KB Output is correct
4 Correct 47 ms 127352 KB Output is correct
5 Correct 46 ms 127432 KB Output is correct
6 Correct 48 ms 127308 KB Output is correct
7 Correct 58 ms 127368 KB Output is correct
8 Correct 47 ms 127328 KB Output is correct
9 Correct 46 ms 127428 KB Output is correct
10 Correct 47 ms 127400 KB Output is correct
11 Correct 52 ms 127408 KB Output is correct
12 Correct 49 ms 127344 KB Output is correct
13 Correct 48 ms 127312 KB Output is correct
14 Correct 53 ms 127376 KB Output is correct
15 Correct 51 ms 127380 KB Output is correct
16 Correct 47 ms 127432 KB Output is correct
17 Correct 48 ms 127364 KB Output is correct
18 Incorrect 48 ms 127376 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 127308 KB Output is correct
2 Correct 49 ms 127316 KB Output is correct
3 Correct 48 ms 127340 KB Output is correct
4 Correct 47 ms 127352 KB Output is correct
5 Correct 46 ms 127432 KB Output is correct
6 Correct 48 ms 127308 KB Output is correct
7 Correct 58 ms 127368 KB Output is correct
8 Correct 47 ms 127328 KB Output is correct
9 Correct 46 ms 127428 KB Output is correct
10 Correct 47 ms 127400 KB Output is correct
11 Correct 52 ms 127408 KB Output is correct
12 Correct 49 ms 127344 KB Output is correct
13 Correct 48 ms 127312 KB Output is correct
14 Correct 53 ms 127376 KB Output is correct
15 Correct 51 ms 127380 KB Output is correct
16 Correct 47 ms 127432 KB Output is correct
17 Correct 48 ms 127364 KB Output is correct
18 Correct 85 ms 127380 KB Output is correct
19 Correct 66 ms 127432 KB Output is correct
20 Correct 56 ms 127344 KB Output is correct
21 Correct 66 ms 127312 KB Output is correct
22 Correct 74 ms 127384 KB Output is correct
23 Correct 53 ms 127320 KB Output is correct
24 Correct 50 ms 127384 KB Output is correct
25 Correct 55 ms 127328 KB Output is correct
26 Correct 52 ms 127444 KB Output is correct
27 Correct 54 ms 127384 KB Output is correct
28 Correct 53 ms 127380 KB Output is correct
29 Correct 57 ms 127336 KB Output is correct
30 Correct 54 ms 127308 KB Output is correct
31 Correct 55 ms 127436 KB Output is correct
32 Correct 52 ms 127468 KB Output is correct
33 Correct 54 ms 127436 KB Output is correct
34 Correct 48 ms 127388 KB Output is correct
35 Correct 58 ms 127396 KB Output is correct
36 Correct 56 ms 127348 KB Output is correct
37 Correct 52 ms 127312 KB Output is correct
38 Correct 50 ms 127332 KB Output is correct
39 Correct 54 ms 127308 KB Output is correct
40 Correct 52 ms 127324 KB Output is correct
41 Correct 105 ms 127308 KB Output is correct
42 Correct 73 ms 127308 KB Output is correct
43 Correct 92 ms 127348 KB Output is correct
44 Correct 66 ms 127388 KB Output is correct
45 Correct 90 ms 127328 KB Output is correct
46 Correct 71 ms 127308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 127308 KB Output is correct
2 Correct 49 ms 127316 KB Output is correct
3 Correct 48 ms 127340 KB Output is correct
4 Correct 47 ms 127352 KB Output is correct
5 Correct 46 ms 127432 KB Output is correct
6 Correct 48 ms 127308 KB Output is correct
7 Correct 58 ms 127368 KB Output is correct
8 Correct 47 ms 127328 KB Output is correct
9 Correct 46 ms 127428 KB Output is correct
10 Correct 47 ms 127400 KB Output is correct
11 Correct 52 ms 127408 KB Output is correct
12 Correct 49 ms 127344 KB Output is correct
13 Correct 48 ms 127312 KB Output is correct
14 Correct 53 ms 127376 KB Output is correct
15 Correct 51 ms 127380 KB Output is correct
16 Correct 47 ms 127432 KB Output is correct
17 Correct 48 ms 127364 KB Output is correct
18 Incorrect 48 ms 127376 KB Output isn't correct
19 Halted 0 ms 0 KB -