답안 #471654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471654 2021-09-10T07:35:08 Z FatihSolak Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
551 ms 539936 KB
#include <bits/stdc++.h>
#define N 205
#define int long long
using namespace std;
int x[2*N],t[2*N];
int dp[2*N][2*N][N][2];
int L;
int go(int a,int b,int dir){
    if(dir == 0){
        return (x[a] - x[b] + L)%L;
    }
    return (x[b] - x[a] +L)%L;
}
void solve(){
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            for(int c=0;c<N;c++){
                for(int d=0;d<2;d++){
                    dp[i][j][c][d] = 2e18;
                }
            }
        }
    }
    int n;
    cin >> n >> L;
    n++;
    dp[n+1][n+1][0][0] = 0;
    for(int i=2;i<=n;i++){
        cin >> x[i];
    }
    for(int i=2;i<=n;i++){
        cin >> t[i];
    }
    for(int i=n+1;i<=2*n;i++){
        x[i] = x[i-n];
        t[i] = t[i-n];
    }
    for(int len=2;len<=n;len++){
        for(int l=1;l<=n+1;l++){
            int r = l+len-2;
            for(int c=0;c<=n;c++){
                dp[l-1][r][c + (dp[l][r][c][0] + go(l,l-1,0) <= t[l-1])][0] = min(dp[l-1][r][c + (dp[l][r][c][0] + go(l,l-1,0) <= t[l-1])][0], dp[l][r][c][0] + go(l,l-1,0));
                dp[l][r+1][c + (dp[l][r][c][0] + go(l,r+1,1) <= t[r+1])][1] = min(dp[l][r+1][c + (dp[l][r][c][0] + go(l,r+1,1) <= t[r+1])][1], dp[l][r][c][0] + go(l,r+1,1));
                dp[l-1][r][c + (dp[l][r][c][1] + go(r,l-1,0) <= t[l-1])][0] = min(dp[l-1][r][c + (dp[l][r][c][1] + go(r,l-1,0) <= t[l-1])][0], dp[l][r][c][1] + go(r,l-1,0));
                dp[l][r+1][c + (dp[l][r][c][1] + go(r,r+1,1) <= t[r+1])][1] = min(dp[l][r+1][c + (dp[l][r][c][1] + go(r,r+1,1) <= t[r+1])][1], dp[l][r][c][1] + go(r,r+1,1));
            }
        }
    }
    int ans = 0;
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            for(int c=0;c<N;c++){
                for(int d=0;d<2;d++){
                    if(dp[i][j][c][d] != 2e18)ans = max(ans,c);
                }
            }
        }
    }
    cout << ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 539784 KB Output is correct
2 Correct 365 ms 539784 KB Output is correct
3 Correct 360 ms 539728 KB Output is correct
4 Correct 366 ms 539684 KB Output is correct
5 Correct 416 ms 539748 KB Output is correct
6 Correct 364 ms 539808 KB Output is correct
7 Correct 363 ms 539732 KB Output is correct
8 Correct 358 ms 539720 KB Output is correct
9 Correct 374 ms 539792 KB Output is correct
10 Correct 354 ms 539768 KB Output is correct
11 Correct 358 ms 539800 KB Output is correct
12 Correct 366 ms 539888 KB Output is correct
13 Correct 371 ms 539808 KB Output is correct
14 Correct 370 ms 539728 KB Output is correct
15 Correct 359 ms 539780 KB Output is correct
16 Correct 358 ms 539812 KB Output is correct
17 Correct 365 ms 539688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 539784 KB Output is correct
2 Correct 365 ms 539784 KB Output is correct
3 Correct 360 ms 539728 KB Output is correct
4 Correct 366 ms 539684 KB Output is correct
5 Correct 416 ms 539748 KB Output is correct
6 Correct 364 ms 539808 KB Output is correct
7 Correct 363 ms 539732 KB Output is correct
8 Correct 358 ms 539720 KB Output is correct
9 Correct 374 ms 539792 KB Output is correct
10 Correct 354 ms 539768 KB Output is correct
11 Correct 358 ms 539800 KB Output is correct
12 Correct 366 ms 539888 KB Output is correct
13 Correct 371 ms 539808 KB Output is correct
14 Correct 370 ms 539728 KB Output is correct
15 Correct 359 ms 539780 KB Output is correct
16 Correct 358 ms 539812 KB Output is correct
17 Correct 365 ms 539688 KB Output is correct
18 Correct 367 ms 539796 KB Output is correct
19 Correct 378 ms 539776 KB Output is correct
20 Correct 360 ms 539712 KB Output is correct
21 Correct 356 ms 539712 KB Output is correct
22 Correct 369 ms 539916 KB Output is correct
23 Correct 359 ms 539896 KB Output is correct
24 Correct 384 ms 539768 KB Output is correct
25 Correct 361 ms 539792 KB Output is correct
26 Correct 353 ms 539796 KB Output is correct
27 Correct 365 ms 539696 KB Output is correct
28 Correct 358 ms 539884 KB Output is correct
29 Correct 362 ms 539792 KB Output is correct
30 Correct 376 ms 539796 KB Output is correct
31 Correct 373 ms 539792 KB Output is correct
32 Correct 357 ms 539768 KB Output is correct
33 Correct 357 ms 539716 KB Output is correct
34 Correct 353 ms 539936 KB Output is correct
35 Correct 359 ms 539792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 539784 KB Output is correct
2 Correct 365 ms 539784 KB Output is correct
3 Correct 360 ms 539728 KB Output is correct
4 Correct 366 ms 539684 KB Output is correct
5 Correct 416 ms 539748 KB Output is correct
6 Correct 364 ms 539808 KB Output is correct
7 Correct 363 ms 539732 KB Output is correct
8 Correct 358 ms 539720 KB Output is correct
9 Correct 374 ms 539792 KB Output is correct
10 Correct 354 ms 539768 KB Output is correct
11 Correct 358 ms 539800 KB Output is correct
12 Correct 366 ms 539888 KB Output is correct
13 Correct 371 ms 539808 KB Output is correct
14 Correct 370 ms 539728 KB Output is correct
15 Correct 359 ms 539780 KB Output is correct
16 Correct 358 ms 539812 KB Output is correct
17 Correct 365 ms 539688 KB Output is correct
18 Correct 500 ms 539796 KB Output is correct
19 Correct 424 ms 539796 KB Output is correct
20 Correct 387 ms 539712 KB Output is correct
21 Correct 415 ms 539724 KB Output is correct
22 Correct 444 ms 539916 KB Output is correct
23 Correct 377 ms 539716 KB Output is correct
24 Correct 378 ms 539848 KB Output is correct
25 Correct 375 ms 539752 KB Output is correct
26 Correct 367 ms 539832 KB Output is correct
27 Correct 372 ms 539792 KB Output is correct
28 Correct 370 ms 539780 KB Output is correct
29 Correct 368 ms 539732 KB Output is correct
30 Correct 367 ms 539848 KB Output is correct
31 Correct 378 ms 539716 KB Output is correct
32 Correct 357 ms 539780 KB Output is correct
33 Correct 380 ms 539852 KB Output is correct
34 Correct 363 ms 539680 KB Output is correct
35 Correct 376 ms 539700 KB Output is correct
36 Correct 358 ms 539716 KB Output is correct
37 Correct 389 ms 539844 KB Output is correct
38 Correct 361 ms 539716 KB Output is correct
39 Correct 378 ms 539732 KB Output is correct
40 Correct 359 ms 539716 KB Output is correct
41 Correct 545 ms 539884 KB Output is correct
42 Correct 451 ms 539764 KB Output is correct
43 Correct 531 ms 539732 KB Output is correct
44 Correct 452 ms 539796 KB Output is correct
45 Correct 537 ms 539796 KB Output is correct
46 Correct 468 ms 539696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 539784 KB Output is correct
2 Correct 365 ms 539784 KB Output is correct
3 Correct 360 ms 539728 KB Output is correct
4 Correct 366 ms 539684 KB Output is correct
5 Correct 416 ms 539748 KB Output is correct
6 Correct 364 ms 539808 KB Output is correct
7 Correct 363 ms 539732 KB Output is correct
8 Correct 358 ms 539720 KB Output is correct
9 Correct 374 ms 539792 KB Output is correct
10 Correct 354 ms 539768 KB Output is correct
11 Correct 358 ms 539800 KB Output is correct
12 Correct 366 ms 539888 KB Output is correct
13 Correct 371 ms 539808 KB Output is correct
14 Correct 370 ms 539728 KB Output is correct
15 Correct 359 ms 539780 KB Output is correct
16 Correct 358 ms 539812 KB Output is correct
17 Correct 365 ms 539688 KB Output is correct
18 Correct 367 ms 539796 KB Output is correct
19 Correct 378 ms 539776 KB Output is correct
20 Correct 360 ms 539712 KB Output is correct
21 Correct 356 ms 539712 KB Output is correct
22 Correct 369 ms 539916 KB Output is correct
23 Correct 359 ms 539896 KB Output is correct
24 Correct 384 ms 539768 KB Output is correct
25 Correct 361 ms 539792 KB Output is correct
26 Correct 353 ms 539796 KB Output is correct
27 Correct 365 ms 539696 KB Output is correct
28 Correct 358 ms 539884 KB Output is correct
29 Correct 362 ms 539792 KB Output is correct
30 Correct 376 ms 539796 KB Output is correct
31 Correct 373 ms 539792 KB Output is correct
32 Correct 357 ms 539768 KB Output is correct
33 Correct 357 ms 539716 KB Output is correct
34 Correct 353 ms 539936 KB Output is correct
35 Correct 359 ms 539792 KB Output is correct
36 Correct 500 ms 539796 KB Output is correct
37 Correct 424 ms 539796 KB Output is correct
38 Correct 387 ms 539712 KB Output is correct
39 Correct 415 ms 539724 KB Output is correct
40 Correct 444 ms 539916 KB Output is correct
41 Correct 377 ms 539716 KB Output is correct
42 Correct 378 ms 539848 KB Output is correct
43 Correct 375 ms 539752 KB Output is correct
44 Correct 367 ms 539832 KB Output is correct
45 Correct 372 ms 539792 KB Output is correct
46 Correct 370 ms 539780 KB Output is correct
47 Correct 368 ms 539732 KB Output is correct
48 Correct 367 ms 539848 KB Output is correct
49 Correct 378 ms 539716 KB Output is correct
50 Correct 357 ms 539780 KB Output is correct
51 Correct 380 ms 539852 KB Output is correct
52 Correct 363 ms 539680 KB Output is correct
53 Correct 376 ms 539700 KB Output is correct
54 Correct 358 ms 539716 KB Output is correct
55 Correct 389 ms 539844 KB Output is correct
56 Correct 361 ms 539716 KB Output is correct
57 Correct 378 ms 539732 KB Output is correct
58 Correct 359 ms 539716 KB Output is correct
59 Correct 545 ms 539884 KB Output is correct
60 Correct 451 ms 539764 KB Output is correct
61 Correct 531 ms 539732 KB Output is correct
62 Correct 452 ms 539796 KB Output is correct
63 Correct 537 ms 539796 KB Output is correct
64 Correct 468 ms 539696 KB Output is correct
65 Correct 507 ms 539860 KB Output is correct
66 Correct 489 ms 539772 KB Output is correct
67 Correct 483 ms 539796 KB Output is correct
68 Correct 472 ms 539804 KB Output is correct
69 Correct 518 ms 539844 KB Output is correct
70 Correct 502 ms 539796 KB Output is correct
71 Correct 493 ms 539784 KB Output is correct
72 Correct 494 ms 539860 KB Output is correct
73 Correct 480 ms 539800 KB Output is correct
74 Correct 468 ms 539716 KB Output is correct
75 Correct 500 ms 539924 KB Output is correct
76 Correct 522 ms 539716 KB Output is correct
77 Correct 532 ms 539844 KB Output is correct
78 Correct 465 ms 539848 KB Output is correct
79 Correct 474 ms 539888 KB Output is correct
80 Correct 519 ms 539844 KB Output is correct
81 Correct 477 ms 539796 KB Output is correct
82 Correct 489 ms 539832 KB Output is correct
83 Correct 541 ms 539844 KB Output is correct
84 Correct 503 ms 539844 KB Output is correct
85 Correct 521 ms 539828 KB Output is correct
86 Correct 512 ms 539848 KB Output is correct
87 Correct 486 ms 539756 KB Output is correct
88 Correct 551 ms 539748 KB Output is correct
89 Correct 544 ms 539776 KB Output is correct
90 Correct 484 ms 539720 KB Output is correct
91 Correct 523 ms 539800 KB Output is correct
92 Correct 521 ms 539804 KB Output is correct
93 Correct 513 ms 539844 KB Output is correct