답안 #1039114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039114 2024-07-30T13:05:17 Z Otalp Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
278 ms 580876 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second

const ll INF = 1e9 + 5;

pii a[501];
ll dp[501][501][501][2];

void solve(){
    int n, L;
    cin>>n;
    cin>>L;
    a[n + 1] = {0, 0};
    for(int i=1; i<=n; i++){
        cin>>a[i+n + 1].ff;
    }
    for(int i=1; i<=n; i++){
        cin>>a[i+n+1].ss;
    }
    for(int i=n; i>=1; i--){
        a[i] = {a[i + n + 1].ff - L, a[i+n+1].ss};
    }
    for(int i=1; i<=n + n + 1; i++){
        for(int r = n + n + 1; r>=i; r--){
            for(int k=0; k<=n; k++){
                dp[i][r][k][0] = dp[i][r][k][1] = INF;
            }
        }
    }

    dp[n+1][n+1][0][0] = dp[n+1][n+1][0][1] = 0;
    int ans = 0;
    for(int d=2; d<=n+1; d++){
        for(int l=1; l<=2 * n + 1 - d + 1; l++){
            int r = l + d - 1;
            for(int k=0; k<=n; k++){
                ll g;
                g = dp[l][r-1][k][0] + a[r].ff - a[l].ff;
                if(g <= a[r].ss){
                    dp[l][r][k+1][1] = min(dp[l][r][k+1][1], g);
                }
                dp[l][r][k][1] = min(dp[l][r][k][1], g);

                g = dp[l][r-1][k][1] + a[r].ff - a[r-1].ff;
                if(g <= a[r].ss){
                    dp[l][r][k+1][1] = min(dp[l][r][k+1][1], g);
                }
                dp[l][r][k][1] = min(dp[l][r][k][1], g);

                g = dp[l+1][r][k][0] + a[l+1].ff - a[l].ff;
                if(g <= a[l].ss){
                    dp[l][r][k+1][0] = min(dp[l][r][k+1][0], g);
                }
                dp[l][r][k][0] = min(dp[l][r][k][0], g);

                g = dp[l+1][r][k][1] + a[r].ff - a[l].ff;
                if(g <= a[l].ss){
                    dp[l][r][k+1][0] = min(dp[l][r][k+1][0], g);
                }
                dp[l][r][k][0] = min(dp[l][r][k][0], g);
            }
        }
    }
    for(int i=1; i<=n + n + 1; i++){
        for(int r = n + n + 1; r>=i; r--){
            for(int k=0; k<=n; k++){
                if(dp[i][r][k][0] < INF or dp[i][r][k][1] < INF){
                    //cout<<i<<' '<<r<<' '<<k<<' '<<min(dp[i][r][k][1], dp[i][r][k][0])<<'\n';
                    ans = max(ans, k);
                }
            }
        }
    }
    cout<<ans;
    




    


}

signed main(){
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6584 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 7568 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 7516 KB Output is correct
13 Correct 1 ms 7512 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 9052 KB Output is correct
16 Correct 1 ms 7516 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6584 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 7568 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 7516 KB Output is correct
13 Correct 1 ms 7512 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 9052 KB Output is correct
16 Correct 1 ms 7516 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
18 Correct 1 ms 8028 KB Output is correct
19 Correct 1 ms 7260 KB Output is correct
20 Correct 1 ms 7516 KB Output is correct
21 Correct 1 ms 8028 KB Output is correct
22 Correct 1 ms 7004 KB Output is correct
23 Correct 1 ms 8284 KB Output is correct
24 Correct 1 ms 7772 KB Output is correct
25 Correct 1 ms 8028 KB Output is correct
26 Correct 1 ms 8028 KB Output is correct
27 Correct 1 ms 7004 KB Output is correct
28 Correct 1 ms 7004 KB Output is correct
29 Correct 1 ms 8284 KB Output is correct
30 Correct 1 ms 8280 KB Output is correct
31 Correct 1 ms 8024 KB Output is correct
32 Correct 1 ms 9820 KB Output is correct
33 Correct 1 ms 8284 KB Output is correct
34 Correct 2 ms 8280 KB Output is correct
35 Correct 1 ms 8400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6584 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 7568 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 7516 KB Output is correct
13 Correct 1 ms 7512 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 9052 KB Output is correct
16 Correct 1 ms 7516 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
18 Correct 200 ms 445012 KB Output is correct
19 Correct 110 ms 246096 KB Output is correct
20 Correct 51 ms 121172 KB Output is correct
21 Correct 100 ms 230488 KB Output is correct
22 Correct 144 ms 312892 KB Output is correct
23 Correct 49 ms 101708 KB Output is correct
24 Correct 33 ms 78168 KB Output is correct
25 Correct 44 ms 99416 KB Output is correct
26 Correct 15 ms 37724 KB Output is correct
27 Correct 46 ms 104028 KB Output is correct
28 Correct 30 ms 72536 KB Output is correct
29 Correct 47 ms 106324 KB Output is correct
30 Correct 35 ms 83792 KB Output is correct
31 Correct 43 ms 99416 KB Output is correct
32 Correct 21 ms 51084 KB Output is correct
33 Correct 44 ms 99416 KB Output is correct
34 Correct 16 ms 35420 KB Output is correct
35 Correct 42 ms 97156 KB Output is correct
36 Correct 17 ms 45400 KB Output is correct
37 Correct 47 ms 104020 KB Output is correct
38 Correct 22 ms 55640 KB Output is correct
39 Correct 47 ms 110428 KB Output is correct
40 Correct 25 ms 62032 KB Output is correct
41 Correct 278 ms 573952 KB Output is correct
42 Correct 163 ms 357080 KB Output is correct
43 Correct 260 ms 573120 KB Output is correct
44 Correct 159 ms 352128 KB Output is correct
45 Correct 265 ms 573012 KB Output is correct
46 Correct 166 ms 356944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6584 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 7568 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7260 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 7516 KB Output is correct
13 Correct 1 ms 7512 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 9052 KB Output is correct
16 Correct 1 ms 7516 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
18 Correct 1 ms 8028 KB Output is correct
19 Correct 1 ms 7260 KB Output is correct
20 Correct 1 ms 7516 KB Output is correct
21 Correct 1 ms 8028 KB Output is correct
22 Correct 1 ms 7004 KB Output is correct
23 Correct 1 ms 8284 KB Output is correct
24 Correct 1 ms 7772 KB Output is correct
25 Correct 1 ms 8028 KB Output is correct
26 Correct 1 ms 8028 KB Output is correct
27 Correct 1 ms 7004 KB Output is correct
28 Correct 1 ms 7004 KB Output is correct
29 Correct 1 ms 8284 KB Output is correct
30 Correct 1 ms 8280 KB Output is correct
31 Correct 1 ms 8024 KB Output is correct
32 Correct 1 ms 9820 KB Output is correct
33 Correct 1 ms 8284 KB Output is correct
34 Correct 2 ms 8280 KB Output is correct
35 Correct 1 ms 8400 KB Output is correct
36 Correct 200 ms 445012 KB Output is correct
37 Correct 110 ms 246096 KB Output is correct
38 Correct 51 ms 121172 KB Output is correct
39 Correct 100 ms 230488 KB Output is correct
40 Correct 144 ms 312892 KB Output is correct
41 Correct 49 ms 101708 KB Output is correct
42 Correct 33 ms 78168 KB Output is correct
43 Correct 44 ms 99416 KB Output is correct
44 Correct 15 ms 37724 KB Output is correct
45 Correct 46 ms 104028 KB Output is correct
46 Correct 30 ms 72536 KB Output is correct
47 Correct 47 ms 106324 KB Output is correct
48 Correct 35 ms 83792 KB Output is correct
49 Correct 43 ms 99416 KB Output is correct
50 Correct 21 ms 51084 KB Output is correct
51 Correct 44 ms 99416 KB Output is correct
52 Correct 16 ms 35420 KB Output is correct
53 Correct 42 ms 97156 KB Output is correct
54 Correct 17 ms 45400 KB Output is correct
55 Correct 47 ms 104020 KB Output is correct
56 Correct 22 ms 55640 KB Output is correct
57 Correct 47 ms 110428 KB Output is correct
58 Correct 25 ms 62032 KB Output is correct
59 Correct 278 ms 573952 KB Output is correct
60 Correct 163 ms 357080 KB Output is correct
61 Correct 260 ms 573120 KB Output is correct
62 Correct 159 ms 352128 KB Output is correct
63 Correct 265 ms 573012 KB Output is correct
64 Correct 166 ms 356944 KB Output is correct
65 Correct 237 ms 507600 KB Output is correct
66 Correct 219 ms 457044 KB Output is correct
67 Correct 203 ms 433420 KB Output is correct
68 Correct 190 ms 394068 KB Output is correct
69 Correct 233 ms 500048 KB Output is correct
70 Correct 220 ms 475156 KB Output is correct
71 Correct 220 ms 482568 KB Output is correct
72 Correct 228 ms 487508 KB Output is correct
73 Correct 208 ms 445096 KB Output is correct
74 Correct 193 ms 410556 KB Output is correct
75 Correct 213 ms 462908 KB Output is correct
76 Correct 271 ms 545872 KB Output is correct
77 Correct 242 ms 545876 KB Output is correct
78 Correct 186 ms 399440 KB Output is correct
79 Correct 202 ms 416364 KB Output is correct
80 Correct 250 ms 532492 KB Output is correct
81 Correct 189 ms 422016 KB Output is correct
82 Correct 217 ms 452420 KB Output is correct
83 Correct 266 ms 573012 KB Output is correct
84 Correct 227 ms 475220 KB Output is correct
85 Correct 246 ms 526072 KB Output is correct
86 Correct 235 ms 512848 KB Output is correct
87 Correct 210 ms 462912 KB Output is correct
88 Correct 252 ms 580876 KB Output is correct
89 Correct 247 ms 580176 KB Output is correct
90 Correct 199 ms 468964 KB Output is correct
91 Correct 256 ms 580180 KB Output is correct
92 Correct 247 ms 580176 KB Output is correct
93 Correct 245 ms 566100 KB Output is correct