Submission #577688

# Submission time Handle Problem Language Result Execution time Memory
577688 2022-06-15T08:07:22 Z Jomnoi Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 724 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 205;
const long long llINF = 1e18 + 7;

int X[MAX_N], T[MAX_N];
long long dp1[MAX_N][MAX_N][MAX_N], dp2[MAX_N][MAX_N][MAX_N];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    int N, L;
    cin >> N >> L;
    
    for(int i = 1; i <= N; i++) {
        cin >> X[i];
    }
    for(int i = 1; i <= N; i++) {
        cin >> T[i];
    }
    X[++N] = L;

    for(int k = 0; k < N; k++) {
        for(int i = 0; i <= N; i++) {
            for(int j = 0; j <= N; j++) {
                dp1[i][j][k] = llINF;
                dp2[i][j][k] = llINF;
            }
        }
    }

    int ans = 0;
    dp1[0][N][0] = dp2[0][N][0] = 1;
    for(int k = 0; k < N; k++) {
        for(int i = 0; i <= N; i++) {
            for(int j = N; j >= 0; j--) {
                long long dist;
                if(i - 1 >= 0) {
                    dist = X[i] - X[i - 1];
                    if(k - 1 >= 0 and dp1[i - 1][j][k - 1] + dist <= T[i]) {
                        dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k - 1] + dist);
                    }
                    if(dp1[i - 1][j][k] + dist > T[i]) {
                        dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k] + dist);
                    }

                    dist = (L - X[j]) + X[i];
                    if(k - 1 >= 0 and dp2[i - 1][j][k - 1] + dist <= T[i]) {
                        dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k - 1] + dist);
                    }
                    if(dp2[i - 1][j][k] + dist > T[i]) {
                        dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k] + dist);
                    }
                }

                if(j + 1 <= N) {
                    dist = X[j + 1] - X[j];
                    if(k - 1 >= 0 and dp2[i][j + 1][k - 1] + dist <= T[j]) {
                        dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k - 1] + dist);
                    }
                    if(dp2[i][j + 1][k] + dist > T[j]) {
                        dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k] + dist);
                    }

                    dist = (L - X[j]) + X[i];
                    if(k - 1 >= 0 and dp1[i][j + 1][k - 1] + dist <= T[j]) {
                        dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k - 1] + dist);
                    }
                    if(dp1[i][j + 1][k] + dist > T[j]) {
                        dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k] + dist);
                    }
                }

                if(dp1[i][j][k] != llINF or dp2[i][j][k] != llINF) {
                    ans = k;
                }
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -