Submission #371532

# Submission time Handle Problem Language Result Execution time Memory
371532 2021-02-26T20:44:02 Z ritul_kr_singh Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
171 ms 128748 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
 
int n, l, x[202], t[202];
 
int d(int i, int j){
    if(i>j) swap(i, j);
    return min(x[j]-x[i], l-(x[j]-x[i]));
}
 
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> l;
    for(int i=1; i<=n; ++i) cin >> x[i];
    for(int i=1; i<=n; ++i) cin >> t[i];
    x[0] = 0, x[n+1] = l;
    t[0] = -1, t[n+1] = -1;
    int dp[n+2][n+2][n+1][2];
    for(int i=0; i<n+2; ++i)
        for(int j=0; j<n+2; ++j)
            for(int k=0; k<=n; ++k)
                dp[i][j][k][0] = dp[i][j][k][1] = 1e10;
    dp[0][n+1][0][0] = 0;
    dp[0][n+1][0][1] = 0;
    int ans = 0;
    for(int k=0; k<=n; ++k){
        for(int i=0; i<=n+1; ++i){
            for(int j=n+1; j>i; --j){
                if(i){
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][0] + d(i, i-1));
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][1] + d(i, j));
                    if(dp[i][j][k][0]<=t[i]) ans = k;
                    else dp[i][j][k][0] = 1e10;
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][0] + d(i, i-1));
                    dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][1] + d(i, j));
                }
                if(j<=n){
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][1] + d(j+1, j));
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][0] + d(i, j));
                    if(dp[i][j][k][1]<=t[j]) ans = k;
                    else dp[i][j][k][1] = 1e10;
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][1] + d(j+1, j));
                    dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][0] + d(i, j));
                }
            }
        }
    }
    cout << ans nl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 106 ms 92652 KB Output is correct
19 Correct 48 ms 43884 KB Output is correct
20 Correct 21 ms 17260 KB Output is correct
21 Correct 47 ms 40300 KB Output is correct
22 Correct 79 ms 59372 KB Output is correct
23 Correct 16 ms 13696 KB Output is correct
24 Correct 11 ms 9452 KB Output is correct
25 Correct 16 ms 13164 KB Output is correct
26 Correct 4 ms 3308 KB Output is correct
27 Correct 18 ms 14060 KB Output is correct
28 Correct 12 ms 8704 KB Output is correct
29 Correct 17 ms 14444 KB Output is correct
30 Correct 12 ms 10220 KB Output is correct
31 Correct 17 ms 13164 KB Output is correct
32 Correct 6 ms 5228 KB Output is correct
33 Correct 16 ms 13164 KB Output is correct
34 Correct 3 ms 3052 KB Output is correct
35 Correct 15 ms 12780 KB Output is correct
36 Correct 5 ms 4332 KB Output is correct
37 Correct 17 ms 14060 KB Output is correct
38 Correct 7 ms 5868 KB Output is correct
39 Correct 18 ms 14956 KB Output is correct
40 Correct 8 ms 6892 KB Output is correct
41 Correct 143 ms 126828 KB Output is correct
42 Correct 79 ms 70252 KB Output is correct
43 Correct 171 ms 126888 KB Output is correct
44 Correct 81 ms 69100 KB Output is correct
45 Correct 141 ms 126828 KB Output is correct
46 Correct 78 ms 70252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 106 ms 92652 KB Output is correct
37 Correct 48 ms 43884 KB Output is correct
38 Correct 21 ms 17260 KB Output is correct
39 Correct 47 ms 40300 KB Output is correct
40 Correct 79 ms 59372 KB Output is correct
41 Correct 16 ms 13696 KB Output is correct
42 Correct 11 ms 9452 KB Output is correct
43 Correct 16 ms 13164 KB Output is correct
44 Correct 4 ms 3308 KB Output is correct
45 Correct 18 ms 14060 KB Output is correct
46 Correct 12 ms 8704 KB Output is correct
47 Correct 17 ms 14444 KB Output is correct
48 Correct 12 ms 10220 KB Output is correct
49 Correct 17 ms 13164 KB Output is correct
50 Correct 6 ms 5228 KB Output is correct
51 Correct 16 ms 13164 KB Output is correct
52 Correct 3 ms 3052 KB Output is correct
53 Correct 15 ms 12780 KB Output is correct
54 Correct 5 ms 4332 KB Output is correct
55 Correct 17 ms 14060 KB Output is correct
56 Correct 7 ms 5868 KB Output is correct
57 Correct 18 ms 14956 KB Output is correct
58 Correct 8 ms 6892 KB Output is correct
59 Correct 143 ms 126828 KB Output is correct
60 Correct 79 ms 70252 KB Output is correct
61 Correct 171 ms 126888 KB Output is correct
62 Correct 81 ms 69100 KB Output is correct
63 Correct 141 ms 126828 KB Output is correct
64 Correct 78 ms 70252 KB Output is correct
65 Correct 123 ms 108908 KB Output is correct
66 Correct 107 ms 95724 KB Output is correct
67 Correct 98 ms 89580 KB Output is correct
68 Correct 91 ms 79468 KB Output is correct
69 Correct 121 ms 107244 KB Output is correct
70 Correct 111 ms 100588 KB Output is correct
71 Correct 115 ms 102124 KB Output is correct
72 Correct 124 ms 103916 KB Output is correct
73 Correct 106 ms 92780 KB Output is correct
74 Correct 120 ms 83692 KB Output is correct
75 Correct 116 ms 97408 KB Output is correct
76 Correct 135 ms 119532 KB Output is correct
77 Correct 132 ms 119532 KB Output is correct
78 Correct 91 ms 80876 KB Output is correct
79 Correct 93 ms 85228 KB Output is correct
80 Correct 130 ms 115820 KB Output is correct
81 Correct 98 ms 86636 KB Output is correct
82 Correct 104 ms 94188 KB Output is correct
83 Correct 142 ms 126828 KB Output is correct
84 Correct 114 ms 100588 KB Output is correct
85 Correct 125 ms 114156 KB Output is correct
86 Correct 123 ms 110572 KB Output is correct
87 Correct 105 ms 97388 KB Output is correct
88 Correct 165 ms 128748 KB Output is correct
89 Correct 156 ms 128748 KB Output is correct
90 Correct 112 ms 98936 KB Output is correct
91 Correct 142 ms 128748 KB Output is correct
92 Correct 147 ms 128748 KB Output is correct
93 Correct 138 ms 125036 KB Output is correct