답안 #373178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373178 2021-03-03T15:45:01 Z Leonardo_Paes Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
148 ms 67692 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2+10;
const int inf = 1e9;
int dp[maxn][maxn][maxn][2], x[maxn], t[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, l;
    cin >> n >> l;
    for(int i=1; i<=n; i++) cin >> x[i];
    for(int i=1; i<=n; i++) cin >> t[i];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                dp[i][j][k][0] = dp[i][j][k][1] = inf;
            }
        }
    }
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    auto prv = [&](int x){
        if(x-1 < 1) return n;
        return x-1;
    };
    auto nxt = [&](int x){
        if(x+1 > n) return 1;
        return x+1;
    };
    auto d = [&](int a, int b){
        if(a > b) swap(a, b);
        return min(x[b] - x[a], l - x[b] + x[a]);
    };
    auto min_self = [&](int &a, int &b){
        a = min(a, b);
    };
    for(int len=0; len<n; len++){
        for(int i=0; i<=n; i++){
            for(int k=0; k<=len; k++){
                int j = (i + len)%(n+1);
                //l -> l
                int tt = dp[i][j][k][0] + d(prv(i), i);
                min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
                //r -> l
                tt = dp[i][j][k][1] + d(prv(i), j);
                min_self(dp[prv(i)][j][k+(tt <= t[prv(i)])][0], tt);
                //l -> r
                tt = dp[i][j][k][0] + d(i, nxt(j));
                min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
                //r -> r
                tt = dp[i][j][k][1] + d(j, nxt(j));
                min_self(dp[i][nxt(j)][k+(tt <= t[nxt(j)])][1], tt);
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                for(int q : {0, 1}){
                    if(dp[i][j][k][q] != inf) ans = max(ans, k);
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 748 KB Output is correct
30 Correct 1 ms 896 KB Output is correct
31 Correct 1 ms 748 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 107 ms 54252 KB Output is correct
19 Correct 56 ms 33132 KB Output is correct
20 Correct 27 ms 17772 KB Output is correct
21 Correct 52 ms 31340 KB Output is correct
22 Correct 73 ms 40556 KB Output is correct
23 Correct 21 ms 15340 KB Output is correct
24 Correct 18 ms 11884 KB Output is correct
25 Correct 20 ms 14828 KB Output is correct
26 Correct 6 ms 5868 KB Output is correct
27 Correct 21 ms 15468 KB Output is correct
28 Correct 15 ms 11116 KB Output is correct
29 Correct 24 ms 15852 KB Output is correct
30 Correct 17 ms 12524 KB Output is correct
31 Correct 21 ms 14828 KB Output is correct
32 Correct 9 ms 7916 KB Output is correct
33 Correct 21 ms 14828 KB Output is correct
34 Correct 6 ms 5484 KB Output is correct
35 Correct 20 ms 14572 KB Output is correct
36 Correct 8 ms 7020 KB Output is correct
37 Correct 21 ms 15468 KB Output is correct
38 Correct 10 ms 8684 KB Output is correct
39 Correct 23 ms 16108 KB Output is correct
40 Correct 12 ms 9648 KB Output is correct
41 Correct 144 ms 66924 KB Output is correct
42 Correct 70 ms 45292 KB Output is correct
43 Correct 142 ms 67052 KB Output is correct
44 Correct 85 ms 44780 KB Output is correct
45 Correct 144 ms 66924 KB Output is correct
46 Correct 85 ms 45292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 1 ms 620 KB Output is correct
20 Correct 1 ms 620 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 748 KB Output is correct
24 Correct 1 ms 748 KB Output is correct
25 Correct 1 ms 748 KB Output is correct
26 Correct 1 ms 748 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 748 KB Output is correct
30 Correct 1 ms 896 KB Output is correct
31 Correct 1 ms 748 KB Output is correct
32 Correct 1 ms 748 KB Output is correct
33 Correct 1 ms 748 KB Output is correct
34 Correct 1 ms 748 KB Output is correct
35 Correct 1 ms 748 KB Output is correct
36 Correct 107 ms 54252 KB Output is correct
37 Correct 56 ms 33132 KB Output is correct
38 Correct 27 ms 17772 KB Output is correct
39 Correct 52 ms 31340 KB Output is correct
40 Correct 73 ms 40556 KB Output is correct
41 Correct 21 ms 15340 KB Output is correct
42 Correct 18 ms 11884 KB Output is correct
43 Correct 20 ms 14828 KB Output is correct
44 Correct 6 ms 5868 KB Output is correct
45 Correct 21 ms 15468 KB Output is correct
46 Correct 15 ms 11116 KB Output is correct
47 Correct 24 ms 15852 KB Output is correct
48 Correct 17 ms 12524 KB Output is correct
49 Correct 21 ms 14828 KB Output is correct
50 Correct 9 ms 7916 KB Output is correct
51 Correct 21 ms 14828 KB Output is correct
52 Correct 6 ms 5484 KB Output is correct
53 Correct 20 ms 14572 KB Output is correct
54 Correct 8 ms 7020 KB Output is correct
55 Correct 21 ms 15468 KB Output is correct
56 Correct 10 ms 8684 KB Output is correct
57 Correct 23 ms 16108 KB Output is correct
58 Correct 12 ms 9648 KB Output is correct
59 Correct 144 ms 66924 KB Output is correct
60 Correct 70 ms 45292 KB Output is correct
61 Correct 142 ms 67052 KB Output is correct
62 Correct 85 ms 44780 KB Output is correct
63 Correct 144 ms 66924 KB Output is correct
64 Correct 85 ms 45292 KB Output is correct
65 Correct 127 ms 60476 KB Output is correct
66 Correct 111 ms 55552 KB Output is correct
67 Correct 104 ms 53228 KB Output is correct
68 Correct 95 ms 49132 KB Output is correct
69 Correct 125 ms 59884 KB Output is correct
70 Correct 115 ms 57324 KB Output is correct
71 Correct 119 ms 57964 KB Output is correct
72 Correct 119 ms 58732 KB Output is correct
73 Correct 107 ms 54252 KB Output is correct
74 Correct 99 ms 50920 KB Output is correct
75 Correct 112 ms 56044 KB Output is correct
76 Correct 140 ms 64236 KB Output is correct
77 Correct 135 ms 64364 KB Output is correct
78 Correct 97 ms 49644 KB Output is correct
79 Correct 98 ms 51308 KB Output is correct
80 Correct 133 ms 63084 KB Output is correct
81 Correct 108 ms 51948 KB Output is correct
82 Correct 110 ms 54892 KB Output is correct
83 Correct 145 ms 66944 KB Output is correct
84 Correct 114 ms 57324 KB Output is correct
85 Correct 130 ms 62444 KB Output is correct
86 Correct 125 ms 61164 KB Output is correct
87 Correct 111 ms 56044 KB Output is correct
88 Correct 146 ms 67564 KB Output is correct
89 Correct 144 ms 67564 KB Output is correct
90 Correct 113 ms 56684 KB Output is correct
91 Correct 148 ms 67692 KB Output is correct
92 Correct 145 ms 67564 KB Output is correct
93 Correct 138 ms 66156 KB Output is correct