답안 #340678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340678 2020-12-28T06:35:26 Z ijxjdjd Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
375 ms 144364 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int MAXN = 205;
const ll INF = (ll)(1e18);

ll dp[MAXN][MAXN][MAXN][2];
bool vis[MAXN][MAXN][MAXN][2];
ll pref[MAXN];
ll suff[MAXN];
ll arr[MAXN];
ll T[MAXN];
int N;
ll calc(int pre, int suf, int tot, int k) {
    if (tot < 0 || pre < 0 || suf > N+2) {
        return INF;
    }
    if (vis[pre][suf][tot][k]){
        return dp[pre][suf][tot][k];
    }
    vis[pre][suf][tot][k] = true;
    if (k == 0 && pre != 0) {
        ll curSide = calc(pre-1, suf, tot-1, k);
        ll otherSide = calc(pre-1, suf, tot-1, k^1);
        ll none = min(calc(pre-1, suf, tot, k) + arr[pre], calc(pre-1, suf, tot, k^1) + suff[suf] + pref[pre]);
        if (curSide + arr[pre] <= T[pre]) {
            none = min(none, curSide + arr[pre]);
        }
        if (otherSide + suff[suf] + pref[pre] <= T[pre]) {
            none = min(none, otherSide + suff[suf] + pref[pre]);
        }
        return dp[pre][suf][tot][k] = none;
    }
    else if (k == 1 && suf != N+2) {
        ll curSide = calc(pre, suf+1, tot-1, k);
        ll otherSide = calc(pre, suf+1, tot-1, k^1);
        ll none = min(calc(pre, suf+1, tot, k) + arr[suf], calc(pre, suf+1, tot, k^1) + suff[suf] + pref[pre]);
        if (curSide + arr[suf] <= T[suf-1]) {
            none = min(none, curSide + arr[suf]);
        }
        if (otherSide + suff[suf] + pref[pre] <= T[suf-1]) {
            none = min(none, otherSide + suff[suf] + pref[pre]);
        }
        return dp[pre][suf][tot][k] = none;
    }
    return dp[pre][suf][tot][k] = INF;
}
int main() {
    int L;
    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        cin >> arr[i+1];
    }
    arr[N+1] = L - arr[N];
    for (int i = N; i >= 1; i--) {
        arr[i] -= arr[i-1];
    }
    for (int i = 0; i < N; i++) {
        cin >> T[i+1];
    }
    for (int i = 1; i <= N+2; i++) {
        pref[i] = pref[i-1] + arr[i];
    }
    for (int i = N+2; i >= 0; i--) {
        suff[i] = arr[i] + suff[i+1];
    }
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXN; k++) {
                dp[i][j][k][0] = INF;
                dp[i][j][k][1] = INF;
            }
        }
    }
    dp[0][N+2][0][0] = 0;
    dp[0][N+2][0][1] = 0;
    vis[0][N+2][0][0] = true;
    vis[0][N+2][0][1] = true;
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        for (int k = 0; k <= N; k++) {
            if (min(calc(i, i+2, k, 0), calc(i, i+2, k, 1)) < INF) {
                ans = max(ans, k);
            }
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 70 ms 135276 KB Output is correct
4 Correct 70 ms 135276 KB Output is correct
5 Correct 71 ms 135276 KB Output is correct
6 Correct 70 ms 135276 KB Output is correct
7 Correct 70 ms 135276 KB Output is correct
8 Correct 69 ms 135276 KB Output is correct
9 Correct 71 ms 135276 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 70 ms 135148 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 77 ms 135276 KB Output is correct
14 Correct 70 ms 135276 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 72 ms 135404 KB Output is correct
17 Correct 72 ms 135276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 70 ms 135276 KB Output is correct
4 Correct 70 ms 135276 KB Output is correct
5 Correct 71 ms 135276 KB Output is correct
6 Correct 70 ms 135276 KB Output is correct
7 Correct 70 ms 135276 KB Output is correct
8 Correct 69 ms 135276 KB Output is correct
9 Correct 71 ms 135276 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 70 ms 135148 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 77 ms 135276 KB Output is correct
14 Correct 70 ms 135276 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 72 ms 135404 KB Output is correct
17 Correct 72 ms 135276 KB Output is correct
18 Correct 69 ms 135276 KB Output is correct
19 Correct 72 ms 135276 KB Output is correct
20 Correct 70 ms 135276 KB Output is correct
21 Correct 72 ms 135276 KB Output is correct
22 Correct 70 ms 135276 KB Output is correct
23 Correct 72 ms 135276 KB Output is correct
24 Correct 70 ms 135276 KB Output is correct
25 Correct 70 ms 135276 KB Output is correct
26 Correct 71 ms 135276 KB Output is correct
27 Correct 71 ms 135404 KB Output is correct
28 Correct 70 ms 135276 KB Output is correct
29 Correct 70 ms 135276 KB Output is correct
30 Correct 70 ms 135276 KB Output is correct
31 Correct 71 ms 135276 KB Output is correct
32 Correct 72 ms 135276 KB Output is correct
33 Correct 71 ms 135276 KB Output is correct
34 Correct 70 ms 135276 KB Output is correct
35 Correct 70 ms 135276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 70 ms 135276 KB Output is correct
4 Correct 70 ms 135276 KB Output is correct
5 Correct 71 ms 135276 KB Output is correct
6 Correct 70 ms 135276 KB Output is correct
7 Correct 70 ms 135276 KB Output is correct
8 Correct 69 ms 135276 KB Output is correct
9 Correct 71 ms 135276 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 70 ms 135148 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 77 ms 135276 KB Output is correct
14 Correct 70 ms 135276 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 72 ms 135404 KB Output is correct
17 Correct 72 ms 135276 KB Output is correct
18 Correct 284 ms 142444 KB Output is correct
19 Correct 173 ms 139756 KB Output is correct
20 Correct 109 ms 137724 KB Output is correct
21 Correct 160 ms 139500 KB Output is correct
22 Correct 206 ms 140652 KB Output is correct
23 Correct 101 ms 137324 KB Output is correct
24 Correct 90 ms 136940 KB Output is correct
25 Correct 100 ms 137324 KB Output is correct
26 Correct 77 ms 136044 KB Output is correct
27 Correct 101 ms 137452 KB Output is correct
28 Correct 88 ms 136812 KB Output is correct
29 Correct 102 ms 137452 KB Output is correct
30 Correct 92 ms 136940 KB Output is correct
31 Correct 99 ms 137324 KB Output is correct
32 Correct 81 ms 136428 KB Output is correct
33 Correct 100 ms 137452 KB Output is correct
34 Correct 77 ms 136044 KB Output is correct
35 Correct 98 ms 137324 KB Output is correct
36 Correct 80 ms 136300 KB Output is correct
37 Correct 103 ms 137452 KB Output is correct
38 Correct 82 ms 136428 KB Output is correct
39 Correct 102 ms 137452 KB Output is correct
40 Correct 85 ms 136556 KB Output is correct
41 Correct 367 ms 144364 KB Output is correct
42 Correct 233 ms 141292 KB Output is correct
43 Correct 366 ms 144108 KB Output is correct
44 Correct 231 ms 141292 KB Output is correct
45 Correct 360 ms 144108 KB Output is correct
46 Correct 231 ms 141292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 135276 KB Output is correct
2 Correct 70 ms 135276 KB Output is correct
3 Correct 70 ms 135276 KB Output is correct
4 Correct 70 ms 135276 KB Output is correct
5 Correct 71 ms 135276 KB Output is correct
6 Correct 70 ms 135276 KB Output is correct
7 Correct 70 ms 135276 KB Output is correct
8 Correct 69 ms 135276 KB Output is correct
9 Correct 71 ms 135276 KB Output is correct
10 Correct 70 ms 135148 KB Output is correct
11 Correct 70 ms 135148 KB Output is correct
12 Correct 71 ms 135276 KB Output is correct
13 Correct 77 ms 135276 KB Output is correct
14 Correct 70 ms 135276 KB Output is correct
15 Correct 70 ms 135276 KB Output is correct
16 Correct 72 ms 135404 KB Output is correct
17 Correct 72 ms 135276 KB Output is correct
18 Correct 69 ms 135276 KB Output is correct
19 Correct 72 ms 135276 KB Output is correct
20 Correct 70 ms 135276 KB Output is correct
21 Correct 72 ms 135276 KB Output is correct
22 Correct 70 ms 135276 KB Output is correct
23 Correct 72 ms 135276 KB Output is correct
24 Correct 70 ms 135276 KB Output is correct
25 Correct 70 ms 135276 KB Output is correct
26 Correct 71 ms 135276 KB Output is correct
27 Correct 71 ms 135404 KB Output is correct
28 Correct 70 ms 135276 KB Output is correct
29 Correct 70 ms 135276 KB Output is correct
30 Correct 70 ms 135276 KB Output is correct
31 Correct 71 ms 135276 KB Output is correct
32 Correct 72 ms 135276 KB Output is correct
33 Correct 71 ms 135276 KB Output is correct
34 Correct 70 ms 135276 KB Output is correct
35 Correct 70 ms 135276 KB Output is correct
36 Correct 284 ms 142444 KB Output is correct
37 Correct 173 ms 139756 KB Output is correct
38 Correct 109 ms 137724 KB Output is correct
39 Correct 160 ms 139500 KB Output is correct
40 Correct 206 ms 140652 KB Output is correct
41 Correct 101 ms 137324 KB Output is correct
42 Correct 90 ms 136940 KB Output is correct
43 Correct 100 ms 137324 KB Output is correct
44 Correct 77 ms 136044 KB Output is correct
45 Correct 101 ms 137452 KB Output is correct
46 Correct 88 ms 136812 KB Output is correct
47 Correct 102 ms 137452 KB Output is correct
48 Correct 92 ms 136940 KB Output is correct
49 Correct 99 ms 137324 KB Output is correct
50 Correct 81 ms 136428 KB Output is correct
51 Correct 100 ms 137452 KB Output is correct
52 Correct 77 ms 136044 KB Output is correct
53 Correct 98 ms 137324 KB Output is correct
54 Correct 80 ms 136300 KB Output is correct
55 Correct 103 ms 137452 KB Output is correct
56 Correct 82 ms 136428 KB Output is correct
57 Correct 102 ms 137452 KB Output is correct
58 Correct 85 ms 136556 KB Output is correct
59 Correct 367 ms 144364 KB Output is correct
60 Correct 233 ms 141292 KB Output is correct
61 Correct 366 ms 144108 KB Output is correct
62 Correct 231 ms 141292 KB Output is correct
63 Correct 360 ms 144108 KB Output is correct
64 Correct 231 ms 141292 KB Output is correct
65 Correct 322 ms 143212 KB Output is correct
66 Correct 295 ms 142956 KB Output is correct
67 Correct 276 ms 142316 KB Output is correct
68 Correct 253 ms 142060 KB Output is correct
69 Correct 318 ms 143212 KB Output is correct
70 Correct 303 ms 142816 KB Output is correct
71 Correct 305 ms 142956 KB Output is correct
72 Correct 312 ms 142956 KB Output is correct
73 Correct 285 ms 142556 KB Output is correct
74 Correct 266 ms 142060 KB Output is correct
75 Correct 295 ms 142700 KB Output is correct
76 Correct 351 ms 143724 KB Output is correct
77 Correct 359 ms 143724 KB Output is correct
78 Correct 263 ms 141924 KB Output is correct
79 Correct 263 ms 142060 KB Output is correct
80 Correct 345 ms 143596 KB Output is correct
81 Correct 270 ms 142188 KB Output is correct
82 Correct 289 ms 142572 KB Output is correct
83 Correct 364 ms 144108 KB Output is correct
84 Correct 303 ms 142828 KB Output is correct
85 Correct 331 ms 143480 KB Output is correct
86 Correct 325 ms 143340 KB Output is correct
87 Correct 299 ms 142700 KB Output is correct
88 Correct 370 ms 144236 KB Output is correct
89 Correct 374 ms 144108 KB Output is correct
90 Correct 298 ms 142828 KB Output is correct
91 Correct 375 ms 144108 KB Output is correct
92 Correct 372 ms 144108 KB Output is correct
93 Correct 357 ms 144108 KB Output is correct