답안 #757881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757881 2023-06-13T21:18:48 Z jasmin Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
39 ms 72796 KB
#include<bits/stdc++.h>
using namespace std;

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

const int INF=1e9+7;

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++){
                    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 31 ms 72780 KB Output is correct
2 Correct 33 ms 72716 KB Output is correct
3 Correct 39 ms 72784 KB Output is correct
4 Correct 35 ms 72796 KB Output is correct
5 Correct 31 ms 72764 KB Output is correct
6 Correct 32 ms 72788 KB Output is correct
7 Correct 32 ms 72692 KB Output is correct
8 Correct 33 ms 72676 KB Output is correct
9 Correct 33 ms 72780 KB Output is correct
10 Correct 35 ms 72756 KB Output is correct
11 Correct 34 ms 72780 KB Output is correct
12 Correct 32 ms 72764 KB Output is correct
13 Incorrect 32 ms 72732 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 72780 KB Output is correct
2 Correct 33 ms 72716 KB Output is correct
3 Correct 39 ms 72784 KB Output is correct
4 Correct 35 ms 72796 KB Output is correct
5 Correct 31 ms 72764 KB Output is correct
6 Correct 32 ms 72788 KB Output is correct
7 Correct 32 ms 72692 KB Output is correct
8 Correct 33 ms 72676 KB Output is correct
9 Correct 33 ms 72780 KB Output is correct
10 Correct 35 ms 72756 KB Output is correct
11 Correct 34 ms 72780 KB Output is correct
12 Correct 32 ms 72764 KB Output is correct
13 Incorrect 32 ms 72732 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 72780 KB Output is correct
2 Correct 33 ms 72716 KB Output is correct
3 Correct 39 ms 72784 KB Output is correct
4 Correct 35 ms 72796 KB Output is correct
5 Correct 31 ms 72764 KB Output is correct
6 Correct 32 ms 72788 KB Output is correct
7 Correct 32 ms 72692 KB Output is correct
8 Correct 33 ms 72676 KB Output is correct
9 Correct 33 ms 72780 KB Output is correct
10 Correct 35 ms 72756 KB Output is correct
11 Correct 34 ms 72780 KB Output is correct
12 Correct 32 ms 72764 KB Output is correct
13 Incorrect 32 ms 72732 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 72780 KB Output is correct
2 Correct 33 ms 72716 KB Output is correct
3 Correct 39 ms 72784 KB Output is correct
4 Correct 35 ms 72796 KB Output is correct
5 Correct 31 ms 72764 KB Output is correct
6 Correct 32 ms 72788 KB Output is correct
7 Correct 32 ms 72692 KB Output is correct
8 Correct 33 ms 72676 KB Output is correct
9 Correct 33 ms 72780 KB Output is correct
10 Correct 35 ms 72756 KB Output is correct
11 Correct 34 ms 72780 KB Output is correct
12 Correct 32 ms 72764 KB Output is correct
13 Incorrect 32 ms 72732 KB Output isn't correct
14 Halted 0 ms 0 KB -