답안 #1098632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098632 2024-10-09T16:16:33 Z flyingkite Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
105 ms 143020 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()
 
const ll N = 222;
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const ll block = 350;
ll dp[N][N][N][2]; // dp[l][r][stamps][left/right]
ll n,L;
ll x[N], t[N];
void to_thic_cau(){
    cin >> n >> L;
    x[n+1] = L;
    for(int i = 1; i <= n;i++) cin >> x[i];
    for(int i = 1; i <= n;i++) cin >> t[i];
    for(int i = 0; i <= n + 1;i++){
        for(int j = 0; j <= n + 1;j++){
            for(int k = 0; k <= n;k++) dp[i][j][k][0] = dp[i][j][k][1] = inf;
        }
    }
    dp[0][n+1][0][0] = 0;
    for(int i = 0; i <= n + 1;i++){
        for(int j = n + 1; j > i;j--){
            if(i == 0 && j == n + 1) continue;
            for(int k = 0; k <= n;k++){
                // TH ko pick
                if(i >= 1){
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][0] + x[i] - x[i-1]);
                    if(j <= n) dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][1] + x[i] + L - x[j]);
                }
                if(j <= n){
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][1] + x[j+1] - x[j]);
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][0] + x[i] + L - x[j]);
                }
                if(k == 0) continue;
                // xet TH co pick (ben trai)
                if(i >= 1){
                    if(dp[i-1][j][k-1][0] + x[i] - x[i-1] <= t[i]){
                        dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][0] + x[i] - x[i-1]);
                    }
                    if(j <= n){
                        if(dp[i-1][j][k-1][1] + x[i] + L - x[j] <= t[i]){
                            dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][1] + x[i] + L - x[j]);
                        }
                    }
                }
                if(j <= n){
                    if(dp[i][j+1][k-1][1] + x[j+1] - x[j] <= t[j]){
                        dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][1] + x[j+1] - x[j]);
                    } 
                    if(dp[i][j+1][k-1][0] + x[i] + L - x[j] <= t[j]){
                        dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][0] + x[i] + L - x[j]);
                    }
                }
            }
        }
    }
    ll res = 0;
    for(int i = 0; i <= n;i++){
        for(int j = 0; j <= n + 1;j++){
            for(int k = 0; k <= n;k++){
                if(dp[i][j][k][0] < inf || dp[i][j][k][1] < inf) res = max(res, k * 1ll);
            }
        }
    }
    cout << res << '\n';
}
 
signed main()   
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tc = 1;
    //cin >> tc;
    while(tc--) to_thic_cau();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1368 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 0 ms 860 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 0 ms 1372 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1372 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 74 ms 114768 KB Output is correct
19 Correct 49 ms 69972 KB Output is correct
20 Correct 27 ms 37464 KB Output is correct
21 Correct 51 ms 65872 KB Output is correct
22 Correct 50 ms 85552 KB Output is correct
23 Correct 15 ms 32092 KB Output is correct
24 Correct 17 ms 25176 KB Output is correct
25 Correct 13 ms 31324 KB Output is correct
26 Correct 5 ms 12124 KB Output is correct
27 Correct 14 ms 32600 KB Output is correct
28 Correct 9 ms 23424 KB Output is correct
29 Correct 23 ms 33372 KB Output is correct
30 Correct 11 ms 26204 KB Output is correct
31 Correct 14 ms 31440 KB Output is correct
32 Correct 7 ms 16476 KB Output is correct
33 Correct 19 ms 31312 KB Output is correct
34 Correct 4 ms 11356 KB Output is correct
35 Correct 14 ms 30556 KB Output is correct
36 Correct 8 ms 14684 KB Output is correct
37 Correct 21 ms 32604 KB Output is correct
38 Correct 10 ms 17972 KB Output is correct
39 Correct 14 ms 33884 KB Output is correct
40 Correct 9 ms 20056 KB Output is correct
41 Correct 86 ms 141608 KB Output is correct
42 Correct 57 ms 95572 KB Output is correct
43 Correct 96 ms 141396 KB Output is correct
44 Correct 49 ms 94288 KB Output is correct
45 Correct 97 ms 141392 KB Output is correct
46 Correct 75 ms 95568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1368 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 0 ms 860 KB Output is correct
23 Correct 1 ms 1372 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 0 ms 1372 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 1372 KB Output is correct
30 Correct 1 ms 1368 KB Output is correct
31 Correct 1 ms 1372 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 1 ms 1372 KB Output is correct
34 Correct 1 ms 1372 KB Output is correct
35 Correct 1 ms 1372 KB Output is correct
36 Correct 74 ms 114768 KB Output is correct
37 Correct 49 ms 69972 KB Output is correct
38 Correct 27 ms 37464 KB Output is correct
39 Correct 51 ms 65872 KB Output is correct
40 Correct 50 ms 85552 KB Output is correct
41 Correct 15 ms 32092 KB Output is correct
42 Correct 17 ms 25176 KB Output is correct
43 Correct 13 ms 31324 KB Output is correct
44 Correct 5 ms 12124 KB Output is correct
45 Correct 14 ms 32600 KB Output is correct
46 Correct 9 ms 23424 KB Output is correct
47 Correct 23 ms 33372 KB Output is correct
48 Correct 11 ms 26204 KB Output is correct
49 Correct 14 ms 31440 KB Output is correct
50 Correct 7 ms 16476 KB Output is correct
51 Correct 19 ms 31312 KB Output is correct
52 Correct 4 ms 11356 KB Output is correct
53 Correct 14 ms 30556 KB Output is correct
54 Correct 8 ms 14684 KB Output is correct
55 Correct 21 ms 32604 KB Output is correct
56 Correct 10 ms 17972 KB Output is correct
57 Correct 14 ms 33884 KB Output is correct
58 Correct 9 ms 20056 KB Output is correct
59 Correct 86 ms 141608 KB Output is correct
60 Correct 57 ms 95572 KB Output is correct
61 Correct 96 ms 141396 KB Output is correct
62 Correct 49 ms 94288 KB Output is correct
63 Correct 97 ms 141392 KB Output is correct
64 Correct 75 ms 95568 KB Output is correct
65 Correct 86 ms 127824 KB Output is correct
66 Correct 65 ms 117324 KB Output is correct
67 Correct 80 ms 112212 KB Output is correct
68 Correct 54 ms 103716 KB Output is correct
69 Correct 82 ms 126548 KB Output is correct
70 Correct 75 ms 121168 KB Output is correct
71 Correct 73 ms 122448 KB Output is correct
72 Correct 69 ms 123732 KB Output is correct
73 Correct 60 ms 114772 KB Output is correct
74 Correct 65 ms 107356 KB Output is correct
75 Correct 70 ms 118612 KB Output is correct
76 Correct 88 ms 136016 KB Output is correct
77 Correct 105 ms 136016 KB Output is correct
78 Correct 78 ms 105048 KB Output is correct
79 Correct 60 ms 108624 KB Output is correct
80 Correct 72 ms 133240 KB Output is correct
81 Correct 64 ms 109904 KB Output is correct
82 Correct 65 ms 116240 KB Output is correct
83 Correct 74 ms 141392 KB Output is correct
84 Correct 63 ms 121168 KB Output is correct
85 Correct 88 ms 131784 KB Output is correct
86 Correct 68 ms 129104 KB Output is correct
87 Correct 68 ms 118608 KB Output is correct
88 Correct 76 ms 143020 KB Output is correct
89 Correct 75 ms 142932 KB Output is correct
90 Correct 62 ms 119892 KB Output is correct
91 Correct 100 ms 142928 KB Output is correct
92 Correct 76 ms 142928 KB Output is correct
93 Correct 86 ms 139992 KB Output is correct