답안 #442058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442058 2021-07-07T00:47:31 Z idontreallyknow Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
127 ms 135384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define SZ(x) ((int)((x).size()))
#define debug(x) cerr << #x << " = " << x << '\n'
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}
const int mx = 205;
ll n, l, dp[mx][mx][mx][2], inf = (ll)1e17+5;
pii p[mx];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> l;
    for (int q = 1; q <= n; q++) cin >> p[q].fi;
    for (int q = 1; q <= n; q++) cin >> p[q].se;
    p[n+1] = {l,-1};
    for (int q = 0; q < mx; q++) 
        for (int w = 0; w < mx; w++) 
            for (int e = 0; e < mx; e++) 
                dp[q][w][e][0] = dp[q][w][e][1] = inf;
    for (int q = 0; q <= n; q++) {
        for (int w = n+1; w > q; w--) {
            if (q == 0 && w == n+1) {
                dp[q][w][0][0] = dp[q][w][0][1] = 0;
                continue;
            }
            for (int e = 0; e < mx; e++) {
                if (q == 0) {
                    chkmin(dp[q][w][e][1], dp[q][w+1][e][1]+p[w+1].fi-p[w].fi);
                    if (e > 0 && dp[q][w+1][e-1][1]+p[w+1].fi-p[w].fi <= p[w].se) {
                        chkmin(dp[q][w][e][1], dp[q][w+1][e-1][1]+p[w+1].fi-p[w].fi);
                    }
                    chkmin(dp[q][w][e][0], dp[q][w][e][1]+l-p[w].fi);
                } else if (w == n+1) {
                    chkmin(dp[q][w][e][0], dp[q-1][w][e][0]+p[q].fi-p[q-1].fi);
                    if (e > 0 && dp[q-1][w][e-1][0]+p[q].fi-p[q-1].fi <= p[q].se) {
                        chkmin(dp[q][w][e][0], dp[q-1][w][e-1][0]+p[q].fi-p[q-1].fi);
                    }
                    chkmin(dp[q][w][e][1], dp[q][w][e][0]+p[q].fi);
                } else {
                    chkmin(dp[q][w][e][0], dp[q-1][w][e][0]+p[q].fi-p[q-1].fi);
                    chkmin(dp[q][w][e][0], dp[q-1][w][e][1]+l-p[w].fi+p[q].fi);
                    chkmin(dp[q][w][e][1], dp[q][w+1][e][1]+p[w+1].fi-p[w].fi);
                    chkmin(dp[q][w][e][1], dp[q][w+1][e][0]+p[q].fi+l-p[w].fi);
                    if (e > 0) {
                        if (dp[q-1][w][e-1][0]+p[q].fi-p[q-1].fi <= p[q].se) {
                            chkmin(dp[q][w][e][0], dp[q-1][w][e-1][0]+p[q].fi-p[q-1].fi);
                        }
                        if (dp[q-1][w][e-1][1]+l-p[w].fi+p[q].fi <= p[q].se) {
                            chkmin(dp[q][w][e][0], dp[q-1][w][e-1][1]+l-p[w].fi+p[q].fi);
                        }
                        if (dp[q][w+1][e-1][1]+p[w+1].fi-p[w].fi <= p[w].se) {
                            chkmin(dp[q][w][e][1], dp[q][w+1][e-1][1]+p[w+1].fi-p[w].fi);
                        }
                        if (dp[q][w+1][e-1][0]+p[q].fi+l-p[w].fi <= p[w].se) {
                            chkmin(dp[q][w][e][1], dp[q][w+1][e-1][0]+p[q].fi+l-p[w].fi);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int q = 0; q < mx; q++) 
        for (int w = 0; w < mx; w++)
            for (int e = 0; e < mx; e++)
                for (int r = 0; r < 2; r++)
                    if (dp[q][w][e][r] != inf) ans = max(ans, e);
    cout << ans << '\n';
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 135096 KB Output is correct
2 Correct 78 ms 135108 KB Output is correct
3 Correct 77 ms 135160 KB Output is correct
4 Correct 76 ms 135108 KB Output is correct
5 Correct 77 ms 135048 KB Output is correct
6 Correct 79 ms 135144 KB Output is correct
7 Correct 76 ms 135152 KB Output is correct
8 Correct 78 ms 135108 KB Output is correct
9 Correct 78 ms 135104 KB Output is correct
10 Correct 79 ms 135100 KB Output is correct
11 Correct 78 ms 135144 KB Output is correct
12 Correct 76 ms 135128 KB Output is correct
13 Correct 77 ms 135384 KB Output is correct
14 Correct 76 ms 135112 KB Output is correct
15 Correct 77 ms 135060 KB Output is correct
16 Correct 79 ms 135072 KB Output is correct
17 Correct 78 ms 135164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 135096 KB Output is correct
2 Correct 78 ms 135108 KB Output is correct
3 Correct 77 ms 135160 KB Output is correct
4 Correct 76 ms 135108 KB Output is correct
5 Correct 77 ms 135048 KB Output is correct
6 Correct 79 ms 135144 KB Output is correct
7 Correct 76 ms 135152 KB Output is correct
8 Correct 78 ms 135108 KB Output is correct
9 Correct 78 ms 135104 KB Output is correct
10 Correct 79 ms 135100 KB Output is correct
11 Correct 78 ms 135144 KB Output is correct
12 Correct 76 ms 135128 KB Output is correct
13 Correct 77 ms 135384 KB Output is correct
14 Correct 76 ms 135112 KB Output is correct
15 Correct 77 ms 135060 KB Output is correct
16 Correct 79 ms 135072 KB Output is correct
17 Correct 78 ms 135164 KB Output is correct
18 Correct 78 ms 135248 KB Output is correct
19 Correct 78 ms 135196 KB Output is correct
20 Correct 80 ms 135148 KB Output is correct
21 Correct 77 ms 135080 KB Output is correct
22 Correct 75 ms 135060 KB Output is correct
23 Correct 77 ms 135152 KB Output is correct
24 Correct 76 ms 135104 KB Output is correct
25 Correct 78 ms 135048 KB Output is correct
26 Correct 77 ms 135068 KB Output is correct
27 Correct 76 ms 135092 KB Output is correct
28 Correct 77 ms 135108 KB Output is correct
29 Correct 76 ms 135176 KB Output is correct
30 Correct 76 ms 135124 KB Output is correct
31 Correct 85 ms 135120 KB Output is correct
32 Correct 76 ms 135108 KB Output is correct
33 Correct 77 ms 135164 KB Output is correct
34 Correct 79 ms 135236 KB Output is correct
35 Correct 78 ms 135072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 135096 KB Output is correct
2 Correct 78 ms 135108 KB Output is correct
3 Correct 77 ms 135160 KB Output is correct
4 Correct 76 ms 135108 KB Output is correct
5 Correct 77 ms 135048 KB Output is correct
6 Correct 79 ms 135144 KB Output is correct
7 Correct 76 ms 135152 KB Output is correct
8 Correct 78 ms 135108 KB Output is correct
9 Correct 78 ms 135104 KB Output is correct
10 Correct 79 ms 135100 KB Output is correct
11 Correct 78 ms 135144 KB Output is correct
12 Correct 76 ms 135128 KB Output is correct
13 Correct 77 ms 135384 KB Output is correct
14 Correct 76 ms 135112 KB Output is correct
15 Correct 77 ms 135060 KB Output is correct
16 Correct 79 ms 135072 KB Output is correct
17 Correct 78 ms 135164 KB Output is correct
18 Correct 109 ms 135172 KB Output is correct
19 Correct 98 ms 135172 KB Output is correct
20 Correct 92 ms 135132 KB Output is correct
21 Correct 95 ms 135108 KB Output is correct
22 Correct 105 ms 135076 KB Output is correct
23 Correct 108 ms 135176 KB Output is correct
24 Correct 84 ms 135088 KB Output is correct
25 Correct 85 ms 135168 KB Output is correct
26 Correct 80 ms 135084 KB Output is correct
27 Correct 85 ms 135168 KB Output is correct
28 Correct 82 ms 135156 KB Output is correct
29 Correct 86 ms 135064 KB Output is correct
30 Correct 83 ms 135108 KB Output is correct
31 Correct 86 ms 135088 KB Output is correct
32 Correct 81 ms 135120 KB Output is correct
33 Correct 91 ms 135236 KB Output is correct
34 Correct 80 ms 135140 KB Output is correct
35 Correct 85 ms 135080 KB Output is correct
36 Correct 80 ms 135108 KB Output is correct
37 Correct 86 ms 135160 KB Output is correct
38 Correct 89 ms 135228 KB Output is correct
39 Correct 89 ms 135216 KB Output is correct
40 Correct 83 ms 135164 KB Output is correct
41 Correct 115 ms 135088 KB Output is correct
42 Correct 103 ms 135156 KB Output is correct
43 Correct 114 ms 135292 KB Output is correct
44 Correct 105 ms 135168 KB Output is correct
45 Correct 127 ms 135176 KB Output is correct
46 Correct 119 ms 135108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 135096 KB Output is correct
2 Correct 78 ms 135108 KB Output is correct
3 Correct 77 ms 135160 KB Output is correct
4 Correct 76 ms 135108 KB Output is correct
5 Correct 77 ms 135048 KB Output is correct
6 Correct 79 ms 135144 KB Output is correct
7 Correct 76 ms 135152 KB Output is correct
8 Correct 78 ms 135108 KB Output is correct
9 Correct 78 ms 135104 KB Output is correct
10 Correct 79 ms 135100 KB Output is correct
11 Correct 78 ms 135144 KB Output is correct
12 Correct 76 ms 135128 KB Output is correct
13 Correct 77 ms 135384 KB Output is correct
14 Correct 76 ms 135112 KB Output is correct
15 Correct 77 ms 135060 KB Output is correct
16 Correct 79 ms 135072 KB Output is correct
17 Correct 78 ms 135164 KB Output is correct
18 Correct 78 ms 135248 KB Output is correct
19 Correct 78 ms 135196 KB Output is correct
20 Correct 80 ms 135148 KB Output is correct
21 Correct 77 ms 135080 KB Output is correct
22 Correct 75 ms 135060 KB Output is correct
23 Correct 77 ms 135152 KB Output is correct
24 Correct 76 ms 135104 KB Output is correct
25 Correct 78 ms 135048 KB Output is correct
26 Correct 77 ms 135068 KB Output is correct
27 Correct 76 ms 135092 KB Output is correct
28 Correct 77 ms 135108 KB Output is correct
29 Correct 76 ms 135176 KB Output is correct
30 Correct 76 ms 135124 KB Output is correct
31 Correct 85 ms 135120 KB Output is correct
32 Correct 76 ms 135108 KB Output is correct
33 Correct 77 ms 135164 KB Output is correct
34 Correct 79 ms 135236 KB Output is correct
35 Correct 78 ms 135072 KB Output is correct
36 Correct 109 ms 135172 KB Output is correct
37 Correct 98 ms 135172 KB Output is correct
38 Correct 92 ms 135132 KB Output is correct
39 Correct 95 ms 135108 KB Output is correct
40 Correct 105 ms 135076 KB Output is correct
41 Correct 108 ms 135176 KB Output is correct
42 Correct 84 ms 135088 KB Output is correct
43 Correct 85 ms 135168 KB Output is correct
44 Correct 80 ms 135084 KB Output is correct
45 Correct 85 ms 135168 KB Output is correct
46 Correct 82 ms 135156 KB Output is correct
47 Correct 86 ms 135064 KB Output is correct
48 Correct 83 ms 135108 KB Output is correct
49 Correct 86 ms 135088 KB Output is correct
50 Correct 81 ms 135120 KB Output is correct
51 Correct 91 ms 135236 KB Output is correct
52 Correct 80 ms 135140 KB Output is correct
53 Correct 85 ms 135080 KB Output is correct
54 Correct 80 ms 135108 KB Output is correct
55 Correct 86 ms 135160 KB Output is correct
56 Correct 89 ms 135228 KB Output is correct
57 Correct 89 ms 135216 KB Output is correct
58 Correct 83 ms 135164 KB Output is correct
59 Correct 115 ms 135088 KB Output is correct
60 Correct 103 ms 135156 KB Output is correct
61 Correct 114 ms 135292 KB Output is correct
62 Correct 105 ms 135168 KB Output is correct
63 Correct 127 ms 135176 KB Output is correct
64 Correct 119 ms 135108 KB Output is correct
65 Correct 111 ms 135068 KB Output is correct
66 Correct 110 ms 135196 KB Output is correct
67 Correct 106 ms 135236 KB Output is correct
68 Correct 116 ms 135096 KB Output is correct
69 Correct 112 ms 135176 KB Output is correct
70 Correct 109 ms 135308 KB Output is correct
71 Correct 116 ms 135208 KB Output is correct
72 Correct 112 ms 135152 KB Output is correct
73 Correct 108 ms 135108 KB Output is correct
74 Correct 105 ms 135136 KB Output is correct
75 Correct 111 ms 135128 KB Output is correct
76 Correct 118 ms 135188 KB Output is correct
77 Correct 115 ms 135172 KB Output is correct
78 Correct 105 ms 135112 KB Output is correct
79 Correct 110 ms 135080 KB Output is correct
80 Correct 117 ms 135172 KB Output is correct
81 Correct 111 ms 135084 KB Output is correct
82 Correct 112 ms 135128 KB Output is correct
83 Correct 119 ms 135172 KB Output is correct
84 Correct 115 ms 135112 KB Output is correct
85 Correct 118 ms 135236 KB Output is correct
86 Correct 113 ms 135068 KB Output is correct
87 Correct 111 ms 135108 KB Output is correct
88 Correct 119 ms 135108 KB Output is correct
89 Correct 117 ms 135172 KB Output is correct
90 Correct 116 ms 135268 KB Output is correct
91 Correct 117 ms 135112 KB Output is correct
92 Correct 120 ms 135072 KB Output is correct
93 Correct 122 ms 135080 KB Output is correct