답안 #591534

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

using namespace std;

using ll = long long;

const int N = 201;

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

void ckmin(int &a, int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 63812 KB Output is correct
2 Correct 25 ms 63864 KB Output is correct
3 Correct 24 ms 63780 KB Output is correct
4 Correct 24 ms 63816 KB Output is correct
5 Correct 24 ms 63844 KB Output is correct
6 Correct 31 ms 63848 KB Output is correct
7 Correct 24 ms 63824 KB Output is correct
8 Correct 25 ms 63888 KB Output is correct
9 Correct 25 ms 63804 KB Output is correct
10 Correct 25 ms 63760 KB Output is correct
11 Correct 24 ms 63792 KB Output is correct
12 Correct 24 ms 63764 KB Output is correct
13 Correct 24 ms 63884 KB Output is correct
14 Correct 27 ms 63800 KB Output is correct
15 Correct 24 ms 63828 KB Output is correct
16 Correct 24 ms 63860 KB Output is correct
17 Correct 25 ms 63824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 63812 KB Output is correct
2 Correct 25 ms 63864 KB Output is correct
3 Correct 24 ms 63780 KB Output is correct
4 Correct 24 ms 63816 KB Output is correct
5 Correct 24 ms 63844 KB Output is correct
6 Correct 31 ms 63848 KB Output is correct
7 Correct 24 ms 63824 KB Output is correct
8 Correct 25 ms 63888 KB Output is correct
9 Correct 25 ms 63804 KB Output is correct
10 Correct 25 ms 63760 KB Output is correct
11 Correct 24 ms 63792 KB Output is correct
12 Correct 24 ms 63764 KB Output is correct
13 Correct 24 ms 63884 KB Output is correct
14 Correct 27 ms 63800 KB Output is correct
15 Correct 24 ms 63828 KB Output is correct
16 Correct 24 ms 63860 KB Output is correct
17 Correct 25 ms 63824 KB Output is correct
18 Incorrect 29 ms 63860 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 63812 KB Output is correct
2 Correct 25 ms 63864 KB Output is correct
3 Correct 24 ms 63780 KB Output is correct
4 Correct 24 ms 63816 KB Output is correct
5 Correct 24 ms 63844 KB Output is correct
6 Correct 31 ms 63848 KB Output is correct
7 Correct 24 ms 63824 KB Output is correct
8 Correct 25 ms 63888 KB Output is correct
9 Correct 25 ms 63804 KB Output is correct
10 Correct 25 ms 63760 KB Output is correct
11 Correct 24 ms 63792 KB Output is correct
12 Correct 24 ms 63764 KB Output is correct
13 Correct 24 ms 63884 KB Output is correct
14 Correct 27 ms 63800 KB Output is correct
15 Correct 24 ms 63828 KB Output is correct
16 Correct 24 ms 63860 KB Output is correct
17 Correct 25 ms 63824 KB Output is correct
18 Correct 57 ms 63800 KB Output is correct
19 Correct 38 ms 63872 KB Output is correct
20 Correct 30 ms 63892 KB Output is correct
21 Correct 39 ms 63872 KB Output is correct
22 Correct 46 ms 63784 KB Output is correct
23 Correct 30 ms 63828 KB Output is correct
24 Correct 28 ms 63768 KB Output is correct
25 Correct 29 ms 63848 KB Output is correct
26 Correct 25 ms 63832 KB Output is correct
27 Correct 29 ms 63792 KB Output is correct
28 Correct 26 ms 63828 KB Output is correct
29 Correct 29 ms 63780 KB Output is correct
30 Correct 27 ms 63888 KB Output is correct
31 Correct 29 ms 63884 KB Output is correct
32 Correct 27 ms 63956 KB Output is correct
33 Correct 30 ms 63748 KB Output is correct
34 Correct 31 ms 63868 KB Output is correct
35 Correct 28 ms 63820 KB Output is correct
36 Correct 26 ms 63860 KB Output is correct
37 Correct 27 ms 63884 KB Output is correct
38 Correct 25 ms 63840 KB Output is correct
39 Correct 28 ms 63832 KB Output is correct
40 Correct 26 ms 63856 KB Output is correct
41 Correct 63 ms 63876 KB Output is correct
42 Correct 40 ms 63824 KB Output is correct
43 Correct 63 ms 63876 KB Output is correct
44 Correct 40 ms 63804 KB Output is correct
45 Correct 65 ms 63824 KB Output is correct
46 Correct 41 ms 63948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 63812 KB Output is correct
2 Correct 25 ms 63864 KB Output is correct
3 Correct 24 ms 63780 KB Output is correct
4 Correct 24 ms 63816 KB Output is correct
5 Correct 24 ms 63844 KB Output is correct
6 Correct 31 ms 63848 KB Output is correct
7 Correct 24 ms 63824 KB Output is correct
8 Correct 25 ms 63888 KB Output is correct
9 Correct 25 ms 63804 KB Output is correct
10 Correct 25 ms 63760 KB Output is correct
11 Correct 24 ms 63792 KB Output is correct
12 Correct 24 ms 63764 KB Output is correct
13 Correct 24 ms 63884 KB Output is correct
14 Correct 27 ms 63800 KB Output is correct
15 Correct 24 ms 63828 KB Output is correct
16 Correct 24 ms 63860 KB Output is correct
17 Correct 25 ms 63824 KB Output is correct
18 Incorrect 29 ms 63860 KB Output isn't correct
19 Halted 0 ms 0 KB -