답안 #757890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757890 2023-06-13T21:43:26 Z jasmin Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
104 ms 145332 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N=210;
int dp[N][N][N][2];

const int INF=1e18;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, tot;
    cin >> n >> tot;

    vector<int> x(n+2);
    x[0]=0; x[n+1]=tot;
    for(int i=1; i<=n; i++){
        cin >> x[i];
    }

    vector<int> t(n+2);
    t[0]=-1; t[n+1]=-1;
    for(int i=1; i<=n; i++){
        cin >> t[i];
    }


    //initialize
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int x=0; x<2; x++){
                    dp[i][j][k][x]=INF;
                }
            }
        }
    }
    dp[0][0][0][0]=0;
    dp[0][0][0][1]=0;

    for(int l=0; l<n; l++){
        for(int r=0; r<n; r++){
            if(l+r>=n) continue;

            for(int c=0; c<n; c++){

                for(int loc=0; loc<2; loc++){
                    if(dp[l][r][c][loc]==INF) continue;

                    int cor;
                    if(loc==0){
                        cor = x[n+1-l];
                    }
                    else{
                        cor = x[r];
                    }

                    //walk right
                    int distright = 0;
                    if(loc==0){
                        distright = (tot-cor) + x[r+1];
                    }
                    else{
                        distright = x[r+1] - cor;
                    }

                    dp[l][r+1][c][1] = min(dp[l][r+1][c][1], dp[l][r][c][loc] + distright);
                    //dp[l][r+1][c][0] = min(dp[l][r+1][c][0], dp[l][r][c][loc] + 2*distright);
                    if( dp[l][r][c][loc] + distright <= t[r+1] ){

                        dp[l][r+1][c+1][1] = min( dp[l][r+1][c+1][1], dp[l][r][c][loc] + distright );
                        //dp[l][r+1][c+1][0] = min( dp[l][r+1][c+1][0], dp[l][r][c][loc] + 2*distright);
                    }


                    //walk left
                    int distleft=0;
                    if(loc==0){
                        distleft = cor - x[n+1 - (l+1)];
                    }
                    else{
                        distleft = tot - x[n+1 - (l+1)] + cor;
                    }

                    dp[l+1][r][c][0] = min(dp[l+1][r][c][0], dp[l][r][c][loc] + distleft);
                    //dp[l+1][r][c][1] = min(dp[l+1][r][c][1], dp[l][r][c][loc] + 2*distleft);
                    if( dp[l][r][c][loc] + distleft <= t[n+1-(l+1)]){

                        dp[l+1][r][c+1][0] = min(dp[l+1][r][c+1][0], dp[l][r][c][loc] + distleft);
                        //dp[l+1][r][c+1][1] = min(dp[l+1][r][c+1][1], dp[l][r][c][loc] + 2*distleft);
                    }

                }

            }
        }
    }

    //finding the largest one
    int ans=0;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                //cout << i << " " << j << " " << k <<  ": " << dp[i][j][k][0] << ", " << dp[i][j][k][1] << "\n";

                for(int x=0; x<2; x++){


                    if(dp[i][j][k][x] != INF){
                        ans = max(ans, k);
                    }

                }
            }
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 145268 KB Output is correct
2 Correct 65 ms 145264 KB Output is correct
3 Correct 57 ms 145184 KB Output is correct
4 Correct 58 ms 145176 KB Output is correct
5 Correct 56 ms 145228 KB Output is correct
6 Correct 59 ms 145248 KB Output is correct
7 Correct 60 ms 145168 KB Output is correct
8 Correct 73 ms 145196 KB Output is correct
9 Correct 57 ms 145268 KB Output is correct
10 Correct 59 ms 145216 KB Output is correct
11 Correct 72 ms 145264 KB Output is correct
12 Correct 75 ms 145216 KB Output is correct
13 Correct 62 ms 145224 KB Output is correct
14 Correct 57 ms 145184 KB Output is correct
15 Correct 57 ms 145228 KB Output is correct
16 Correct 58 ms 145228 KB Output is correct
17 Correct 60 ms 145228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 145268 KB Output is correct
2 Correct 65 ms 145264 KB Output is correct
3 Correct 57 ms 145184 KB Output is correct
4 Correct 58 ms 145176 KB Output is correct
5 Correct 56 ms 145228 KB Output is correct
6 Correct 59 ms 145248 KB Output is correct
7 Correct 60 ms 145168 KB Output is correct
8 Correct 73 ms 145196 KB Output is correct
9 Correct 57 ms 145268 KB Output is correct
10 Correct 59 ms 145216 KB Output is correct
11 Correct 72 ms 145264 KB Output is correct
12 Correct 75 ms 145216 KB Output is correct
13 Correct 62 ms 145224 KB Output is correct
14 Correct 57 ms 145184 KB Output is correct
15 Correct 57 ms 145228 KB Output is correct
16 Correct 58 ms 145228 KB Output is correct
17 Correct 60 ms 145228 KB Output is correct
18 Correct 63 ms 145236 KB Output is correct
19 Correct 59 ms 145264 KB Output is correct
20 Correct 57 ms 145264 KB Output is correct
21 Correct 58 ms 145236 KB Output is correct
22 Correct 59 ms 145220 KB Output is correct
23 Correct 57 ms 145216 KB Output is correct
24 Correct 56 ms 145264 KB Output is correct
25 Correct 58 ms 145228 KB Output is correct
26 Correct 59 ms 145212 KB Output is correct
27 Correct 61 ms 145332 KB Output is correct
28 Correct 65 ms 145276 KB Output is correct
29 Correct 59 ms 145256 KB Output is correct
30 Correct 57 ms 145192 KB Output is correct
31 Correct 57 ms 145188 KB Output is correct
32 Correct 56 ms 145228 KB Output is correct
33 Correct 56 ms 145204 KB Output is correct
34 Correct 57 ms 145172 KB Output is correct
35 Correct 57 ms 145196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 145268 KB Output is correct
2 Correct 65 ms 145264 KB Output is correct
3 Correct 57 ms 145184 KB Output is correct
4 Correct 58 ms 145176 KB Output is correct
5 Correct 56 ms 145228 KB Output is correct
6 Correct 59 ms 145248 KB Output is correct
7 Correct 60 ms 145168 KB Output is correct
8 Correct 73 ms 145196 KB Output is correct
9 Correct 57 ms 145268 KB Output is correct
10 Correct 59 ms 145216 KB Output is correct
11 Correct 72 ms 145264 KB Output is correct
12 Correct 75 ms 145216 KB Output is correct
13 Correct 62 ms 145224 KB Output is correct
14 Correct 57 ms 145184 KB Output is correct
15 Correct 57 ms 145228 KB Output is correct
16 Correct 58 ms 145228 KB Output is correct
17 Correct 60 ms 145228 KB Output is correct
18 Correct 95 ms 145296 KB Output is correct
19 Correct 72 ms 145244 KB Output is correct
20 Correct 63 ms 145180 KB Output is correct
21 Correct 71 ms 145184 KB Output is correct
22 Correct 82 ms 145264 KB Output is correct
23 Correct 68 ms 145228 KB Output is correct
24 Correct 72 ms 145176 KB Output is correct
25 Correct 70 ms 145288 KB Output is correct
26 Correct 59 ms 145240 KB Output is correct
27 Correct 68 ms 145204 KB Output is correct
28 Correct 60 ms 145288 KB Output is correct
29 Correct 66 ms 145204 KB Output is correct
30 Correct 60 ms 145260 KB Output is correct
31 Correct 62 ms 145232 KB Output is correct
32 Correct 59 ms 145184 KB Output is correct
33 Correct 63 ms 145224 KB Output is correct
34 Correct 60 ms 145196 KB Output is correct
35 Correct 61 ms 145260 KB Output is correct
36 Correct 59 ms 145268 KB Output is correct
37 Correct 63 ms 145188 KB Output is correct
38 Correct 58 ms 145276 KB Output is correct
39 Correct 63 ms 145268 KB Output is correct
40 Correct 63 ms 145268 KB Output is correct
41 Correct 91 ms 145208 KB Output is correct
42 Correct 73 ms 145280 KB Output is correct
43 Correct 92 ms 145288 KB Output is correct
44 Correct 71 ms 145292 KB Output is correct
45 Correct 90 ms 145168 KB Output is correct
46 Correct 70 ms 145200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 145268 KB Output is correct
2 Correct 65 ms 145264 KB Output is correct
3 Correct 57 ms 145184 KB Output is correct
4 Correct 58 ms 145176 KB Output is correct
5 Correct 56 ms 145228 KB Output is correct
6 Correct 59 ms 145248 KB Output is correct
7 Correct 60 ms 145168 KB Output is correct
8 Correct 73 ms 145196 KB Output is correct
9 Correct 57 ms 145268 KB Output is correct
10 Correct 59 ms 145216 KB Output is correct
11 Correct 72 ms 145264 KB Output is correct
12 Correct 75 ms 145216 KB Output is correct
13 Correct 62 ms 145224 KB Output is correct
14 Correct 57 ms 145184 KB Output is correct
15 Correct 57 ms 145228 KB Output is correct
16 Correct 58 ms 145228 KB Output is correct
17 Correct 60 ms 145228 KB Output is correct
18 Correct 63 ms 145236 KB Output is correct
19 Correct 59 ms 145264 KB Output is correct
20 Correct 57 ms 145264 KB Output is correct
21 Correct 58 ms 145236 KB Output is correct
22 Correct 59 ms 145220 KB Output is correct
23 Correct 57 ms 145216 KB Output is correct
24 Correct 56 ms 145264 KB Output is correct
25 Correct 58 ms 145228 KB Output is correct
26 Correct 59 ms 145212 KB Output is correct
27 Correct 61 ms 145332 KB Output is correct
28 Correct 65 ms 145276 KB Output is correct
29 Correct 59 ms 145256 KB Output is correct
30 Correct 57 ms 145192 KB Output is correct
31 Correct 57 ms 145188 KB Output is correct
32 Correct 56 ms 145228 KB Output is correct
33 Correct 56 ms 145204 KB Output is correct
34 Correct 57 ms 145172 KB Output is correct
35 Correct 57 ms 145196 KB Output is correct
36 Correct 95 ms 145296 KB Output is correct
37 Correct 72 ms 145244 KB Output is correct
38 Correct 63 ms 145180 KB Output is correct
39 Correct 71 ms 145184 KB Output is correct
40 Correct 82 ms 145264 KB Output is correct
41 Correct 68 ms 145228 KB Output is correct
42 Correct 72 ms 145176 KB Output is correct
43 Correct 70 ms 145288 KB Output is correct
44 Correct 59 ms 145240 KB Output is correct
45 Correct 68 ms 145204 KB Output is correct
46 Correct 60 ms 145288 KB Output is correct
47 Correct 66 ms 145204 KB Output is correct
48 Correct 60 ms 145260 KB Output is correct
49 Correct 62 ms 145232 KB Output is correct
50 Correct 59 ms 145184 KB Output is correct
51 Correct 63 ms 145224 KB Output is correct
52 Correct 60 ms 145196 KB Output is correct
53 Correct 61 ms 145260 KB Output is correct
54 Correct 59 ms 145268 KB Output is correct
55 Correct 63 ms 145188 KB Output is correct
56 Correct 58 ms 145276 KB Output is correct
57 Correct 63 ms 145268 KB Output is correct
58 Correct 63 ms 145268 KB Output is correct
59 Correct 91 ms 145208 KB Output is correct
60 Correct 73 ms 145280 KB Output is correct
61 Correct 92 ms 145288 KB Output is correct
62 Correct 71 ms 145292 KB Output is correct
63 Correct 90 ms 145168 KB Output is correct
64 Correct 70 ms 145200 KB Output is correct
65 Correct 95 ms 145240 KB Output is correct
66 Correct 86 ms 145284 KB Output is correct
67 Correct 81 ms 145276 KB Output is correct
68 Correct 91 ms 145216 KB Output is correct
69 Correct 88 ms 145196 KB Output is correct
70 Correct 90 ms 145212 KB Output is correct
71 Correct 85 ms 145292 KB Output is correct
72 Correct 89 ms 145228 KB Output is correct
73 Correct 78 ms 145176 KB Output is correct
74 Correct 83 ms 145296 KB Output is correct
75 Correct 83 ms 145192 KB Output is correct
76 Correct 90 ms 145196 KB Output is correct
77 Correct 87 ms 145268 KB Output is correct
78 Correct 80 ms 145292 KB Output is correct
79 Correct 85 ms 145272 KB Output is correct
80 Correct 93 ms 145220 KB Output is correct
81 Correct 80 ms 145208 KB Output is correct
82 Correct 82 ms 145180 KB Output is correct
83 Correct 91 ms 145232 KB Output is correct
84 Correct 88 ms 145300 KB Output is correct
85 Correct 83 ms 145212 KB Output is correct
86 Correct 81 ms 145204 KB Output is correct
87 Correct 84 ms 145236 KB Output is correct
88 Correct 104 ms 145212 KB Output is correct
89 Correct 94 ms 145228 KB Output is correct
90 Correct 77 ms 145216 KB Output is correct
91 Correct 94 ms 145244 KB Output is correct
92 Correct 93 ms 145308 KB Output is correct
93 Correct 79 ms 145272 KB Output is correct