Submission #203643

# Submission time Handle Problem Language Result Execution time Memory
203643 2020-02-21T17:48:35 Z osaaateiasavtnl Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
139 ms 139384 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 207, INF = 1e9 + 7;
int dp[N][N][N][2];
int n, L, x[N], t[N];
void upd(int &a, int b) { a = min(a, b); }
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> 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; ++i)
        for (int j = 0; j < N; ++j)
            for (int k = 0; k < N; ++k)
                for (int t = 0; t < 2; ++t)
                    dp[i][j][k][t] = INF;
 
    x[0] = 0;
    x[n + 1] = L;
    n += 2;
 
    dp[0][0][n][0] = dp[0][0][n][1] = 0;
 
    /*
    for (int i = 0; i < n; ++i)
        cout << x[i] << ' ';
    cout << '\n';
    */
 
    dp[0][0][n - 1][0] = dp[0][0][n - 1][0] = 0;
    for (int i = 0; i + 1 < N; ++i) {
        for (int l = 0; l < n - 1; ++l) {
            for (int r = n - 1; r; --r) {
                int tt;
 
                if (r - l <= 1)
                    continue;
 
                if (dp[i][l][r][0] < INF) {
                    tt = dp[i][l][r][0] + x[l + 1] - x[l];
                    upd(dp[i + (tt <= t[l + 1])][l + 1][r][0], tt);
 
                    tt = dp[i][l][r][0] + x[l] + (L - x[r - 1]);
                    upd(dp[i + (tt <= t[r - 1])][l][r - 1][1], tt);                
                }
 
                if (dp[i][l][r][1] < INF) {
                    tt = dp[i][l][r][1] + (L - x[r]) + x[l + 1];
                    upd(dp[i + (tt <= t[l + 1])][l + 1][r][0], tt);
 
                    tt = dp[i][l][r][1] + x[r] - x[r - 1];
                    upd(dp[i + (tt <= t[r - 1])][l][r - 1][1], tt);
                }
            }   
        }   
    }   
    for (int i = N - 1; ; --i) {
        for (int l = 0; l < N; ++l) 
            for (int r = 0; r < N; ++r)
                for (int t = 0; t < 2; ++t)
                    if (dp[i][l][r][t] < INF) {
                        cout << i << '\n';
                        exit(0);
                    }   
    }   
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:46:24: warning: operation on 'dp[0][0][(n - 1)][0]' may be undefined [-Wsequence-point]
     dp[0][0][n - 1][0] = dp[0][0][n - 1][0] = 0;
     ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 139128 KB Output is correct
2 Correct 92 ms 139256 KB Output is correct
3 Correct 86 ms 139256 KB Output is correct
4 Correct 88 ms 139168 KB Output is correct
5 Correct 85 ms 139132 KB Output is correct
6 Correct 86 ms 139256 KB Output is correct
7 Correct 90 ms 139280 KB Output is correct
8 Correct 87 ms 139132 KB Output is correct
9 Correct 84 ms 139128 KB Output is correct
10 Correct 83 ms 139128 KB Output is correct
11 Correct 85 ms 139128 KB Output is correct
12 Correct 86 ms 139256 KB Output is correct
13 Correct 92 ms 139132 KB Output is correct
14 Correct 86 ms 139132 KB Output is correct
15 Correct 86 ms 139128 KB Output is correct
16 Correct 87 ms 139256 KB Output is correct
17 Correct 85 ms 139232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 139128 KB Output is correct
2 Correct 92 ms 139256 KB Output is correct
3 Correct 86 ms 139256 KB Output is correct
4 Correct 88 ms 139168 KB Output is correct
5 Correct 85 ms 139132 KB Output is correct
6 Correct 86 ms 139256 KB Output is correct
7 Correct 90 ms 139280 KB Output is correct
8 Correct 87 ms 139132 KB Output is correct
9 Correct 84 ms 139128 KB Output is correct
10 Correct 83 ms 139128 KB Output is correct
11 Correct 85 ms 139128 KB Output is correct
12 Correct 86 ms 139256 KB Output is correct
13 Correct 92 ms 139132 KB Output is correct
14 Correct 86 ms 139132 KB Output is correct
15 Correct 86 ms 139128 KB Output is correct
16 Correct 87 ms 139256 KB Output is correct
17 Correct 85 ms 139232 KB Output is correct
18 Correct 89 ms 139128 KB Output is correct
19 Correct 86 ms 139256 KB Output is correct
20 Correct 86 ms 139132 KB Output is correct
21 Correct 87 ms 139128 KB Output is correct
22 Correct 85 ms 139260 KB Output is correct
23 Correct 84 ms 139128 KB Output is correct
24 Correct 85 ms 139256 KB Output is correct
25 Correct 87 ms 139240 KB Output is correct
26 Correct 92 ms 139132 KB Output is correct
27 Correct 86 ms 139256 KB Output is correct
28 Correct 87 ms 139128 KB Output is correct
29 Correct 87 ms 139128 KB Output is correct
30 Correct 86 ms 139164 KB Output is correct
31 Correct 85 ms 139256 KB Output is correct
32 Correct 89 ms 139256 KB Output is correct
33 Correct 85 ms 139128 KB Output is correct
34 Correct 86 ms 139128 KB Output is correct
35 Correct 86 ms 139128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 139128 KB Output is correct
2 Correct 92 ms 139256 KB Output is correct
3 Correct 86 ms 139256 KB Output is correct
4 Correct 88 ms 139168 KB Output is correct
5 Correct 85 ms 139132 KB Output is correct
6 Correct 86 ms 139256 KB Output is correct
7 Correct 90 ms 139280 KB Output is correct
8 Correct 87 ms 139132 KB Output is correct
9 Correct 84 ms 139128 KB Output is correct
10 Correct 83 ms 139128 KB Output is correct
11 Correct 85 ms 139128 KB Output is correct
12 Correct 86 ms 139256 KB Output is correct
13 Correct 92 ms 139132 KB Output is correct
14 Correct 86 ms 139132 KB Output is correct
15 Correct 86 ms 139128 KB Output is correct
16 Correct 87 ms 139256 KB Output is correct
17 Correct 85 ms 139232 KB Output is correct
18 Correct 129 ms 139384 KB Output is correct
19 Correct 106 ms 139256 KB Output is correct
20 Correct 91 ms 139128 KB Output is correct
21 Correct 100 ms 139128 KB Output is correct
22 Correct 112 ms 139240 KB Output is correct
23 Correct 92 ms 139256 KB Output is correct
24 Correct 95 ms 139132 KB Output is correct
25 Correct 91 ms 139128 KB Output is correct
26 Correct 86 ms 139128 KB Output is correct
27 Correct 95 ms 139316 KB Output is correct
28 Correct 89 ms 139256 KB Output is correct
29 Correct 93 ms 139128 KB Output is correct
30 Correct 90 ms 139256 KB Output is correct
31 Correct 95 ms 139128 KB Output is correct
32 Correct 99 ms 139296 KB Output is correct
33 Correct 94 ms 139256 KB Output is correct
34 Correct 89 ms 139128 KB Output is correct
35 Correct 94 ms 139128 KB Output is correct
36 Correct 91 ms 139256 KB Output is correct
37 Correct 97 ms 139256 KB Output is correct
38 Correct 94 ms 139128 KB Output is correct
39 Correct 94 ms 139248 KB Output is correct
40 Correct 89 ms 139256 KB Output is correct
41 Correct 137 ms 139256 KB Output is correct
42 Correct 103 ms 139168 KB Output is correct
43 Correct 137 ms 139128 KB Output is correct
44 Correct 103 ms 139128 KB Output is correct
45 Correct 139 ms 139256 KB Output is correct
46 Correct 107 ms 139232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 139128 KB Output is correct
2 Correct 92 ms 139256 KB Output is correct
3 Correct 86 ms 139256 KB Output is correct
4 Correct 88 ms 139168 KB Output is correct
5 Correct 85 ms 139132 KB Output is correct
6 Correct 86 ms 139256 KB Output is correct
7 Correct 90 ms 139280 KB Output is correct
8 Correct 87 ms 139132 KB Output is correct
9 Correct 84 ms 139128 KB Output is correct
10 Correct 83 ms 139128 KB Output is correct
11 Correct 85 ms 139128 KB Output is correct
12 Correct 86 ms 139256 KB Output is correct
13 Correct 92 ms 139132 KB Output is correct
14 Correct 86 ms 139132 KB Output is correct
15 Correct 86 ms 139128 KB Output is correct
16 Correct 87 ms 139256 KB Output is correct
17 Correct 85 ms 139232 KB Output is correct
18 Correct 89 ms 139128 KB Output is correct
19 Correct 86 ms 139256 KB Output is correct
20 Correct 86 ms 139132 KB Output is correct
21 Correct 87 ms 139128 KB Output is correct
22 Correct 85 ms 139260 KB Output is correct
23 Correct 84 ms 139128 KB Output is correct
24 Correct 85 ms 139256 KB Output is correct
25 Correct 87 ms 139240 KB Output is correct
26 Correct 92 ms 139132 KB Output is correct
27 Correct 86 ms 139256 KB Output is correct
28 Correct 87 ms 139128 KB Output is correct
29 Correct 87 ms 139128 KB Output is correct
30 Correct 86 ms 139164 KB Output is correct
31 Correct 85 ms 139256 KB Output is correct
32 Correct 89 ms 139256 KB Output is correct
33 Correct 85 ms 139128 KB Output is correct
34 Correct 86 ms 139128 KB Output is correct
35 Correct 86 ms 139128 KB Output is correct
36 Correct 129 ms 139384 KB Output is correct
37 Correct 106 ms 139256 KB Output is correct
38 Correct 91 ms 139128 KB Output is correct
39 Correct 100 ms 139128 KB Output is correct
40 Correct 112 ms 139240 KB Output is correct
41 Correct 92 ms 139256 KB Output is correct
42 Correct 95 ms 139132 KB Output is correct
43 Correct 91 ms 139128 KB Output is correct
44 Correct 86 ms 139128 KB Output is correct
45 Correct 95 ms 139316 KB Output is correct
46 Correct 89 ms 139256 KB Output is correct
47 Correct 93 ms 139128 KB Output is correct
48 Correct 90 ms 139256 KB Output is correct
49 Correct 95 ms 139128 KB Output is correct
50 Correct 99 ms 139296 KB Output is correct
51 Correct 94 ms 139256 KB Output is correct
52 Correct 89 ms 139128 KB Output is correct
53 Correct 94 ms 139128 KB Output is correct
54 Correct 91 ms 139256 KB Output is correct
55 Correct 97 ms 139256 KB Output is correct
56 Correct 94 ms 139128 KB Output is correct
57 Correct 94 ms 139248 KB Output is correct
58 Correct 89 ms 139256 KB Output is correct
59 Correct 137 ms 139256 KB Output is correct
60 Correct 103 ms 139168 KB Output is correct
61 Correct 137 ms 139128 KB Output is correct
62 Correct 103 ms 139128 KB Output is correct
63 Correct 139 ms 139256 KB Output is correct
64 Correct 107 ms 139232 KB Output is correct
65 Correct 102 ms 139128 KB Output is correct
66 Correct 102 ms 139256 KB Output is correct
67 Correct 104 ms 139132 KB Output is correct
68 Correct 106 ms 139128 KB Output is correct
69 Correct 104 ms 139128 KB Output is correct
70 Correct 100 ms 139128 KB Output is correct
71 Correct 103 ms 139128 KB Output is correct
72 Correct 104 ms 139256 KB Output is correct
73 Correct 99 ms 139128 KB Output is correct
74 Correct 96 ms 139256 KB Output is correct
75 Correct 102 ms 139128 KB Output is correct
76 Correct 113 ms 139128 KB Output is correct
77 Correct 110 ms 139128 KB Output is correct
78 Correct 104 ms 139248 KB Output is correct
79 Correct 100 ms 139128 KB Output is correct
80 Correct 113 ms 139196 KB Output is correct
81 Correct 101 ms 139240 KB Output is correct
82 Correct 108 ms 139128 KB Output is correct
83 Correct 108 ms 139128 KB Output is correct
84 Correct 110 ms 139128 KB Output is correct
85 Correct 102 ms 139256 KB Output is correct
86 Correct 111 ms 139128 KB Output is correct
87 Correct 102 ms 139128 KB Output is correct
88 Correct 99 ms 139128 KB Output is correct
89 Correct 99 ms 139128 KB Output is correct
90 Correct 112 ms 139384 KB Output is correct
91 Correct 102 ms 139128 KB Output is correct
92 Correct 99 ms 139128 KB Output is correct
93 Correct 111 ms 139212 KB Output is correct