Submission #211267

# Submission time Handle Problem Language Result Execution time Memory
211267 2020-03-19T20:57:12 Z DS007 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
287 ms 144828 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 202;
int n, l;
int x[N], t[N];
int dp[N][N][N][2];
bool seen[N][N][N][2];

int calc(int i, int j, int k, int s) {
    if (seen[i][j][k][s])
        return dp[i][j][k][s];

    seen[i][j][k][s] = true;
    int &val = dp[i][j][k][s];

    if (i + j < k || (i == 0 && s == 0) || (j == 0 && s == 1) || i + j > n)
        return val = 1e11;

    if (k == 0) {
        if (s == 0)
            return val = x[i];
        else
            return val = l - x[n - j + 1];
    }

    if (j == 0) {
        int temp = calc(i - 1, j, k - 1, s);
        if (temp + x[i] - x[i - 1] <= t[i])
            val = min(val, temp + x[i] - x[i - 1]);
        return val = min(val, calc(i - 1, j, k, s) + x[i] - x[i - 1]);
    }

    if (i == 0) {
        int temp = calc(i, j - 1, k - 1, s);
        if (temp + abs(x[n - j + 2] - x[n - j + 1]) <= t[n - j + 1])
            val = min(val, temp + abs(x[n - j + 2] - x[n - j + 1]));
        return val = min(val, calc(i, j - 1, k, s) + abs(x[n - j + 2] - x[n - j + 1]));
    }

    if (s == 0) {
        int temp = calc(i - 1, j, k - 1, s);
        if (temp + x[i] - x[i - 1] <= t[i])
            val = min(val, temp + x[i] - x[i - 1]);
        val = min(val, calc(i - 1, j, k, s) + x[i] - x[i - 1]);

        temp = calc(i - 1, j, k - 1, 1);
        if (temp + x[i] + l - x[n - j + 1] <= t[i])
            val = min(val, temp + x[i] + l - x[n - j + 1]);
        return val = min(val, calc(i - 1, j, k, 1) + x[i] + l - x[n - j + 1]);
    }

    if (s == 1) {
        int temp = calc(i, j - 1, k - 1, s);
        if (temp + abs(x[n - j + 2] - x[n - j + 1]) <= t[n - j + 1])
            val = min(val, temp + abs(x[n - j + 2] - x[n - j + 1]));
        val = min(val, calc(i, j - 1, k, s) + abs(x[n - j + 2] - x[n - j + 1]));

        temp = calc(i, j - 1, k - 1, 0);
        if (temp + x[i] + l - x[n - j + 1] <= t[n - j + 1])
            val = min(val, temp + x[i] + l - x[n - j + 1]);
        return val = min(val, calc(i, j - 1, k, 0) + x[i] + l - x[n - j + 1]);
    }
}

void solveTestCase() {
    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 + 1] = l;

    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] = dp[i][j][k][1] = 1e11;
        }
    }

    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    seen[0][0][0][0] = seen[0][0][0][1] = true;

    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] = calc(i, j, k, 0), dp[i][j][k][1] = calc(i, j, k, 1);
        }
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= n; k++) {
                int a1 = dp[i][j][k][0], a2 = dp[i][j][k][1];
                if (dp[i][j][k][0] < 1e11)
                    ans = max(ans, k);
                if (dp[i][j][k][1] < 1e11)
                    ans = max(ans, k);
            }
        }
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    //cin >> test;
    while (test--)
        solveTestCase();
}

Compilation message

ho_t3.cpp: In function 'void solveTestCase()':
ho_t3.cpp:94:21: warning: unused variable 'a1' [-Wunused-variable]
                 int a1 = dp[i][j][k][0], a2 = dp[i][j][k][1];
                     ^~
ho_t3.cpp:94:42: warning: unused variable 'a2' [-Wunused-variable]
                 int a1 = dp[i][j][k][0], a2 = dp[i][j][k][1];
                                          ^~
ho_t3.cpp: In function 'long long int calc(long long int, long long int, long long int, long long int)':
ho_t3.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1072 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1072 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1280 KB Output is correct
19 Correct 5 ms 896 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 6 ms 1280 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 6 ms 1408 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 5 ms 1280 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 1408 KB Output is correct
30 Correct 5 ms 1408 KB Output is correct
31 Correct 5 ms 1280 KB Output is correct
32 Correct 5 ms 1152 KB Output is correct
33 Correct 5 ms 1408 KB Output is correct
34 Correct 6 ms 1408 KB Output is correct
35 Correct 5 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1072 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 217 ms 116984 KB Output is correct
19 Correct 120 ms 71160 KB Output is correct
20 Correct 56 ms 38008 KB Output is correct
21 Correct 109 ms 67192 KB Output is correct
22 Correct 151 ms 86904 KB Output is correct
23 Correct 44 ms 32384 KB Output is correct
24 Correct 33 ms 25336 KB Output is correct
25 Correct 43 ms 31736 KB Output is correct
26 Correct 17 ms 12288 KB Output is correct
27 Correct 45 ms 33144 KB Output is correct
28 Correct 33 ms 23672 KB Output is correct
29 Correct 49 ms 33784 KB Output is correct
30 Correct 36 ms 26616 KB Output is correct
31 Correct 45 ms 31864 KB Output is correct
32 Correct 23 ms 16768 KB Output is correct
33 Correct 43 ms 31736 KB Output is correct
34 Correct 17 ms 11520 KB Output is correct
35 Correct 41 ms 31096 KB Output is correct
36 Correct 19 ms 14848 KB Output is correct
37 Correct 45 ms 33144 KB Output is correct
38 Correct 24 ms 18176 KB Output is correct
39 Correct 47 ms 34552 KB Output is correct
40 Correct 26 ms 20352 KB Output is correct
41 Correct 278 ms 143676 KB Output is correct
42 Correct 168 ms 97272 KB Output is correct
43 Correct 281 ms 143608 KB Output is correct
44 Correct 161 ms 96120 KB Output is correct
45 Correct 280 ms 143632 KB Output is correct
46 Correct 173 ms 97272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1072 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 640 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1280 KB Output is correct
19 Correct 5 ms 896 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 6 ms 1280 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 6 ms 1408 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 5 ms 1280 KB Output is correct
26 Correct 5 ms 1280 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 768 KB Output is correct
29 Correct 5 ms 1408 KB Output is correct
30 Correct 5 ms 1408 KB Output is correct
31 Correct 5 ms 1280 KB Output is correct
32 Correct 5 ms 1152 KB Output is correct
33 Correct 5 ms 1408 KB Output is correct
34 Correct 6 ms 1408 KB Output is correct
35 Correct 5 ms 1408 KB Output is correct
36 Correct 217 ms 116984 KB Output is correct
37 Correct 120 ms 71160 KB Output is correct
38 Correct 56 ms 38008 KB Output is correct
39 Correct 109 ms 67192 KB Output is correct
40 Correct 151 ms 86904 KB Output is correct
41 Correct 44 ms 32384 KB Output is correct
42 Correct 33 ms 25336 KB Output is correct
43 Correct 43 ms 31736 KB Output is correct
44 Correct 17 ms 12288 KB Output is correct
45 Correct 45 ms 33144 KB Output is correct
46 Correct 33 ms 23672 KB Output is correct
47 Correct 49 ms 33784 KB Output is correct
48 Correct 36 ms 26616 KB Output is correct
49 Correct 45 ms 31864 KB Output is correct
50 Correct 23 ms 16768 KB Output is correct
51 Correct 43 ms 31736 KB Output is correct
52 Correct 17 ms 11520 KB Output is correct
53 Correct 41 ms 31096 KB Output is correct
54 Correct 19 ms 14848 KB Output is correct
55 Correct 45 ms 33144 KB Output is correct
56 Correct 24 ms 18176 KB Output is correct
57 Correct 47 ms 34552 KB Output is correct
58 Correct 26 ms 20352 KB Output is correct
59 Correct 278 ms 143676 KB Output is correct
60 Correct 168 ms 97272 KB Output is correct
61 Correct 281 ms 143608 KB Output is correct
62 Correct 161 ms 96120 KB Output is correct
63 Correct 280 ms 143632 KB Output is correct
64 Correct 173 ms 97272 KB Output is correct
65 Correct 244 ms 130296 KB Output is correct
66 Correct 225 ms 119648 KB Output is correct
67 Correct 211 ms 114424 KB Output is correct
68 Correct 191 ms 105696 KB Output is correct
69 Correct 247 ms 128888 KB Output is correct
70 Correct 228 ms 123812 KB Output is correct
71 Correct 243 ms 124920 KB Output is correct
72 Correct 235 ms 126200 KB Output is correct
73 Correct 214 ms 117112 KB Output is correct
74 Correct 193 ms 109448 KB Output is correct
75 Correct 223 ms 120952 KB Output is correct
76 Correct 258 ms 138232 KB Output is correct
77 Correct 264 ms 138232 KB Output is correct
78 Correct 190 ms 106872 KB Output is correct
79 Correct 198 ms 110676 KB Output is correct
80 Correct 250 ms 135544 KB Output is correct
81 Correct 199 ms 111992 KB Output is correct
82 Correct 220 ms 118264 KB Output is correct
83 Correct 280 ms 143608 KB Output is correct
84 Correct 227 ms 123640 KB Output is correct
85 Correct 252 ms 134272 KB Output is correct
86 Correct 278 ms 131652 KB Output is correct
87 Correct 222 ms 121080 KB Output is correct
88 Correct 287 ms 144760 KB Output is correct
89 Correct 284 ms 144828 KB Output is correct
90 Correct 225 ms 122232 KB Output is correct
91 Correct 285 ms 144760 KB Output is correct
92 Correct 280 ms 144760 KB Output is correct
93 Correct 273 ms 142200 KB Output is correct