답안 #274560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
274560 2020-08-19T12:47:54 Z Gilgamesh Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
140 ms 127608 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
 
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
 
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0}; 
const char dir[] = {'R', 'L', 'D', 'U'};
 
int add(int a, int b){
    a += b;
    if(a >= MOD){
        a -= MOD;
    }
    return a;
}
 
int sub(int a, int b){
    a -= b;
    if(a < 0) a += MOD;
    return a;
}
 
int mult(int a, int b){
    return ((ll) a * b) % MOD;
}
 
void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen((s+".in").c_str(),"r",stdin);
//    freopen((s+".text").c_str(),"w",stdout);
}
 
//ctrl q is comment
//ctrl b is run
//ctrl s is compile
//alt r is search & replace
//alt d is delete a line
 
int main(){
    setIO();
    int N, L; cin >> N >> L;
    int X[N + 1], X2[N + 1], T[N];
    for(int i = 1; i <= N; ++i){
        cin >> X[i];
    }
    for(int i = 0; i < N; ++i){
        cin >> T[i];
    }
    for(int i = 1; i <= N; ++i){
        X2[N - i + 1] = L - X[i];
    }
    X[0] = 0; X2[0] = 0;
    ll dp[N+1][N+1][N+1][2];
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j) {
            for(int k = 0; k <= N; ++k) {
                dp[i][j][k][0] = 1e18;
                dp[i][j][k][1] = 1e18;
            }
        }
    }
    dp[0][0][0][0] = 0;
    dp[0][0][0][1] = 0;
    int ans = 0;
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j) {
            for(int k = 0; k <= N; ++k) {
                if(j + k > N || j + k < i) continue;
                if(j > 0) {
                    //transition from dp[i - 1][j - 1][k][0], dp[i - 1][j - 1][k][1], dp[i][j - 1][k][0], dp[i][j - 1][k][1]
                    dp[i][j][k][0] = dp[i][j - 1][k][0] + X2[j] - X2[j - 1];
                    if(i > 0 && dp[i - 1][j - 1][k][0] + X2[j] - X2[j - 1] <= T[N - j]) 
                        dp[i][j][k][0] = min(dp[i][j][k][0], dp[i - 1][j - 1][k][0] + X2[j] - X2[j - 1]);
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i][j - 1][k][1] + X2[j] + X[k]);
                    if(i > 0 && dp[i - 1][j - 1][k][1] + X2[j] + X[k] <= T[N - j])
                        dp[i][j][k][0] = min(dp[i][j][k][0], dp[i - 1][j - 1][k][1] + X2[j] + X[k]);
                }
                if(k > 0) {
                    dp[i][j][k][1] = dp[i][j][k - 1][0] + X2[j] + X[k];
                    if(i > 0 && dp[i - 1][j][k - 1][0] + X2[j] + X[k] <= T[k - 1])
                        dp[i][j][k][1] = min(dp[i][j][k][1], dp[i - 1][j][k - 1][0] + X2[j] + X[k]);
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j][k - 1][1] + X[k] - X[k - 1]);
                    if(i > 0 && dp[i - 1][j][k - 1][1] + X[k] - X[k - 1] <= T[k - 1])
                        dp[i][j][k][1] = min(dp[i][j][k][1], dp[i - 1][j][k - 1][1] + X[k] - X[k - 1]);
                }
                if(dp[i][j][k][0] < 1e18 || dp[i][j][k][1] < 1e18) ans = i;
            }
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 416 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 388 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 91 ms 91640 KB Output is correct
19 Correct 45 ms 43256 KB Output is correct
20 Correct 17 ms 16896 KB Output is correct
21 Correct 40 ms 39680 KB Output is correct
22 Correct 58 ms 58744 KB Output is correct
23 Correct 15 ms 13312 KB Output is correct
24 Correct 10 ms 9216 KB Output is correct
25 Correct 13 ms 12928 KB Output is correct
26 Correct 3 ms 3200 KB Output is correct
27 Correct 16 ms 13696 KB Output is correct
28 Correct 9 ms 8320 KB Output is correct
29 Correct 15 ms 14208 KB Output is correct
30 Correct 11 ms 9984 KB Output is correct
31 Correct 14 ms 12928 KB Output is correct
32 Correct 5 ms 4992 KB Output is correct
33 Correct 14 ms 12928 KB Output is correct
34 Correct 3 ms 2944 KB Output is correct
35 Correct 13 ms 12544 KB Output is correct
36 Correct 4 ms 4224 KB Output is correct
37 Correct 15 ms 13696 KB Output is correct
38 Correct 6 ms 5760 KB Output is correct
39 Correct 15 ms 14592 KB Output is correct
40 Correct 7 ms 6656 KB Output is correct
41 Correct 122 ms 125560 KB Output is correct
42 Correct 69 ms 69372 KB Output is correct
43 Correct 122 ms 125560 KB Output is correct
44 Correct 67 ms 68088 KB Output is correct
45 Correct 125 ms 125628 KB Output is correct
46 Correct 70 ms 69368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 416 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 388 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 91 ms 91640 KB Output is correct
37 Correct 45 ms 43256 KB Output is correct
38 Correct 17 ms 16896 KB Output is correct
39 Correct 40 ms 39680 KB Output is correct
40 Correct 58 ms 58744 KB Output is correct
41 Correct 15 ms 13312 KB Output is correct
42 Correct 10 ms 9216 KB Output is correct
43 Correct 13 ms 12928 KB Output is correct
44 Correct 3 ms 3200 KB Output is correct
45 Correct 16 ms 13696 KB Output is correct
46 Correct 9 ms 8320 KB Output is correct
47 Correct 15 ms 14208 KB Output is correct
48 Correct 11 ms 9984 KB Output is correct
49 Correct 14 ms 12928 KB Output is correct
50 Correct 5 ms 4992 KB Output is correct
51 Correct 14 ms 12928 KB Output is correct
52 Correct 3 ms 2944 KB Output is correct
53 Correct 13 ms 12544 KB Output is correct
54 Correct 4 ms 4224 KB Output is correct
55 Correct 15 ms 13696 KB Output is correct
56 Correct 6 ms 5760 KB Output is correct
57 Correct 15 ms 14592 KB Output is correct
58 Correct 7 ms 6656 KB Output is correct
59 Correct 122 ms 125560 KB Output is correct
60 Correct 69 ms 69372 KB Output is correct
61 Correct 122 ms 125560 KB Output is correct
62 Correct 67 ms 68088 KB Output is correct
63 Correct 125 ms 125628 KB Output is correct
64 Correct 70 ms 69368 KB Output is correct
65 Correct 105 ms 107768 KB Output is correct
66 Correct 105 ms 94712 KB Output is correct
67 Correct 88 ms 88568 KB Output is correct
68 Correct 79 ms 78712 KB Output is correct
69 Correct 105 ms 105996 KB Output is correct
70 Correct 104 ms 99448 KB Output is correct
71 Correct 98 ms 101112 KB Output is correct
72 Correct 106 ms 102776 KB Output is correct
73 Correct 98 ms 91640 KB Output is correct
74 Correct 81 ms 82808 KB Output is correct
75 Correct 99 ms 96248 KB Output is correct
76 Correct 115 ms 118264 KB Output is correct
77 Correct 118 ms 118392 KB Output is correct
78 Correct 82 ms 80120 KB Output is correct
79 Correct 82 ms 84216 KB Output is correct
80 Correct 116 ms 114692 KB Output is correct
81 Correct 83 ms 85624 KB Output is correct
82 Correct 97 ms 93304 KB Output is correct
83 Correct 123 ms 125560 KB Output is correct
84 Correct 106 ms 99512 KB Output is correct
85 Correct 113 ms 112888 KB Output is correct
86 Correct 110 ms 109476 KB Output is correct
87 Correct 110 ms 96248 KB Output is correct
88 Correct 131 ms 127480 KB Output is correct
89 Correct 140 ms 127608 KB Output is correct
90 Correct 96 ms 97912 KB Output is correct
91 Correct 129 ms 127480 KB Output is correct
92 Correct 125 ms 127608 KB Output is correct
93 Correct 123 ms 123896 KB Output is correct