답안 #541050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541050 2022-03-22T07:26:39 Z Cookie197 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
158 ms 130124 KB
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

#define ll long long
#define mp make_pair
#define pii pair<ll,ll>
#define inf (ll)1e15
#define endl "\n"
#define out(x) cout<< #x << " = " << x << endl

int n;
ll L,X[206],T[206];
ll dp[206][206][206][2]; // 已經看過區間(i,j),拿到了k個stamp,目前人在最左或最右,的最小時間

int goleft(int x){
    return x-1 ? x-1:n;
}
int goright(int x){
    return x==n ? 1:x+1;
}
ll dist(int i,int j){
    if (i<j) return X[j] - X[i];
    return X[j] - X[i] + L;
}
void chmin(ll &a, ll b){
    a = min(a,b);
}
signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    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=1;i<=n;i++) for (int j=1;j<=n;j++) for (int k=0;k<=n;k++) dp[i][j][k][0] = dp[i][j][k][1] = inf;

    
    if (X[1] <= T[1]) dp[1][1][1][0] = dp[1][1][1][1] = X[1];
    else dp[1][1][0][0] = dp[1][1][0][1] = X[1];
    if (L-X[n] <= T[n]) dp[n][n][1][0] = dp[n][n][1][1] = L-X[n];
    else dp[n][n][0][0] = dp[n][n][0][1] = L-X[n];

    for (int d=0;d<n;d++) for (int i=1;i<=n;i++) for (int k=0;k<=d+1;k++){
        int j = i+d > n ? i+d-n : i+d;

        ll nowtime = dp[i][j][k][0];
        if (nowtime + dist(goleft(i), i) <= T[goleft(i)]){
            chmin(dp[goleft(i)][j][k+1][0],  nowtime + dist(goleft(i), i));
        }
        else chmin(dp[goleft(i)][j][k][0],  nowtime + dist(goleft(i), i));
 
        if (nowtime + dist(i,goright(j)) <= T[goright(j)]){
            chmin(dp[i][goright(j)][k+1][1], nowtime + dist(i, goright(j)));
        }
        else chmin(dp[i][goright(j)][k][1], nowtime + dist(i, goright(j)));
 
        
        nowtime = dp[i][j][k][1];
        if (nowtime + dist(goleft(i), j) <= T[goleft(i)]){
            chmin(dp[goleft(i)][j][k+1][0], nowtime + dist(goleft(i), j));
        }
        else chmin(dp[goleft(i)][j][k][0], nowtime + dist(goleft(i), j));
 
        if (nowtime + dist(j, goright(j)) <= T[goright(j)]){
            chmin(dp[i][goright(j)][k+1][1], nowtime + dist(j, goright(j)));
        }
        else chmin(dp[i][goright(j)][k][1], nowtime + dist(j, goright(j)));
    }

    /*for (int i=1;i<=n;i++) for (int j=1;j<=n;j++){
        int d = j-i < 0 ? j-i+n : j-i;
        for (int k=0;k<=d;k++) ;//cout<<i<<"  "<<j<<"  "<<k<<"   "<<dp[i][j][k][0]<<" "<<dp[i][j][k][1]<<endl;
    }*/
    int best = 0;
    for (int k=0;k<n;k++){
        for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {
            int d = j-i < 0 ? j-i+n : j-i;
            if (k>d) continue;
            if (dp[i][j][k][0] < inf || dp[i][j][k][1] < inf) best = k;
        }
    }
    // 全部可選的特判?
    for (int i=1;i<=n;i++){
        if (dp[i][goleft(i)][n][0] < inf || dp[i][goleft(i)][n][1] < inf) best = n;
        if (dp[i][goright(i)][n][0] < inf || dp[i][goright(i)][n][1] < inf) best = n;
    }
    cout<<best<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 712 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 968 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 548 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 968 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 968 KB Output is correct
35 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 101 ms 104324 KB Output is correct
19 Correct 57 ms 63004 KB Output is correct
20 Correct 25 ms 33504 KB Output is correct
21 Correct 49 ms 59468 KB Output is correct
22 Correct 67 ms 77320 KB Output is correct
23 Correct 22 ms 28372 KB Output is correct
24 Correct 16 ms 22228 KB Output is correct
25 Correct 20 ms 27880 KB Output is correct
26 Correct 7 ms 10580 KB Output is correct
27 Correct 22 ms 28992 KB Output is correct
28 Correct 16 ms 20692 KB Output is correct
29 Correct 28 ms 29632 KB Output is correct
30 Correct 17 ms 23252 KB Output is correct
31 Correct 22 ms 27860 KB Output is correct
32 Correct 10 ms 14536 KB Output is correct
33 Correct 21 ms 27792 KB Output is correct
34 Correct 6 ms 9812 KB Output is correct
35 Correct 19 ms 27272 KB Output is correct
36 Correct 8 ms 12836 KB Output is correct
37 Correct 23 ms 29096 KB Output is correct
38 Correct 10 ms 15828 KB Output is correct
39 Correct 26 ms 30328 KB Output is correct
40 Correct 13 ms 17620 KB Output is correct
41 Correct 125 ms 128844 KB Output is correct
42 Correct 78 ms 86532 KB Output is correct
43 Correct 131 ms 128908 KB Output is correct
44 Correct 80 ms 85440 KB Output is correct
45 Correct 136 ms 128820 KB Output is correct
46 Correct 81 ms 86584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 720 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 712 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 968 KB Output is correct
26 Correct 1 ms 972 KB Output is correct
27 Correct 1 ms 548 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 968 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 968 KB Output is correct
35 Correct 1 ms 972 KB Output is correct
36 Correct 101 ms 104324 KB Output is correct
37 Correct 57 ms 63004 KB Output is correct
38 Correct 25 ms 33504 KB Output is correct
39 Correct 49 ms 59468 KB Output is correct
40 Correct 67 ms 77320 KB Output is correct
41 Correct 22 ms 28372 KB Output is correct
42 Correct 16 ms 22228 KB Output is correct
43 Correct 20 ms 27880 KB Output is correct
44 Correct 7 ms 10580 KB Output is correct
45 Correct 22 ms 28992 KB Output is correct
46 Correct 16 ms 20692 KB Output is correct
47 Correct 28 ms 29632 KB Output is correct
48 Correct 17 ms 23252 KB Output is correct
49 Correct 22 ms 27860 KB Output is correct
50 Correct 10 ms 14536 KB Output is correct
51 Correct 21 ms 27792 KB Output is correct
52 Correct 6 ms 9812 KB Output is correct
53 Correct 19 ms 27272 KB Output is correct
54 Correct 8 ms 12836 KB Output is correct
55 Correct 23 ms 29096 KB Output is correct
56 Correct 10 ms 15828 KB Output is correct
57 Correct 26 ms 30328 KB Output is correct
58 Correct 13 ms 17620 KB Output is correct
59 Correct 125 ms 128844 KB Output is correct
60 Correct 78 ms 86532 KB Output is correct
61 Correct 131 ms 128908 KB Output is correct
62 Correct 80 ms 85440 KB Output is correct
63 Correct 136 ms 128820 KB Output is correct
64 Correct 81 ms 86584 KB Output is correct
65 Correct 111 ms 116244 KB Output is correct
66 Correct 103 ms 106572 KB Output is correct
67 Correct 98 ms 101892 KB Output is correct
68 Correct 91 ms 94092 KB Output is correct
69 Correct 116 ms 115020 KB Output is correct
70 Correct 106 ms 110156 KB Output is correct
71 Correct 106 ms 111396 KB Output is correct
72 Correct 109 ms 112616 KB Output is correct
73 Correct 98 ms 104304 KB Output is correct
74 Correct 92 ms 97356 KB Output is correct
75 Correct 104 ms 107836 KB Output is correct
76 Correct 125 ms 123712 KB Output is correct
77 Correct 129 ms 123716 KB Output is correct
78 Correct 90 ms 95160 KB Output is correct
79 Correct 97 ms 98600 KB Output is correct
80 Correct 134 ms 121192 KB Output is correct
81 Correct 99 ms 99624 KB Output is correct
82 Correct 104 ms 105428 KB Output is correct
83 Correct 128 ms 128820 KB Output is correct
84 Correct 107 ms 110140 KB Output is correct
85 Correct 120 ms 119972 KB Output is correct
86 Correct 121 ms 117420 KB Output is correct
87 Correct 109 ms 107848 KB Output is correct
88 Correct 132 ms 130116 KB Output is correct
89 Correct 158 ms 130124 KB Output is correct
90 Correct 109 ms 109032 KB Output is correct
91 Correct 135 ms 130112 KB Output is correct
92 Correct 136 ms 130116 KB Output is correct
93 Correct 127 ms 127496 KB Output is correct