# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251985 | 2020-07-23T12:50:01 Z | ivandasfs | Collecting Stamps 3 (JOI20_ho_t3) | C++14 | 121 ms | 135296 KB |
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define x first #define y second const ll MOD = 1e9+7; const ll INF = 1e18+5; // dp[pos][0/1 = l/r][l+r][skupljeno] = mintime; pair <ll, ll> a[205]; ll dp[205][2][205][205]; int main() { for (int i=0 ; i<205 ; i++) { for (int j=0 ; j<205 ; j++) { for (int k=0 ; k<205 ; k++) { dp[i][0][j][k] = INF; dp[i][1][j][k] = INF; } } } int n; ll l; scanf("%d%lld", &n, &l); for (int i=0 ; i<n ; i++) { scanf("%lld", &a[i].x); } for (int i=0 ; i<n ; i++) { scanf("%lld", &a[i].y); } sort(a, a+n); int maxx = 0; if (a[0].x <= a[0].y or l - a[n-1].x <= a[n-1].y) maxx = 1; dp[0][0][1][a[0].x <= a[0].y] = a[0].x; dp[n-1][1][1][l - a[n-1].x <= a[n-1].y] = l - a[n-1].x; for (int i=2 ; i<=n ; i++) { for (int pos=0 ; pos<n ; pos++) { for (int sk = 0 ; sk<=n ; sk++) { if (dp[pos][0][i-1][sk] != INF) { ll tim = dp[pos][0][i-1][sk]; ll nxt = a[pos+1].x - a[pos].x; if (tim + nxt <= a[pos+1].y) { dp[pos+1][0][i][sk+1] = min(dp[pos+1][0][i][sk+1], tim + nxt); maxx = max(maxx, sk+1); } else { dp[pos+1][0][i][sk] = min(dp[pos+1][0][i][sk], tim + nxt); } int indp = n+pos-i+1; ll prev = a[pos].x + l - a[indp].x; if (tim + prev <= a[indp].y) { dp[indp][1][i][sk+1] = min(dp[indp][1][i][sk+1], tim + prev); maxx = max(maxx, sk+1); } else { dp[indp][1][i][sk] = min(dp[indp][1][i][sk], tim + prev); } } if (dp[pos][1][i-1][sk] != INF) { ll tim = dp[pos][1][i-1][sk]; ll prev = a[pos].x - a[pos-1].x; if (tim + prev <= a[pos-1].y) { dp[pos-1][1][i][sk+1] = min(dp[pos-1][1][i][sk+1], tim + prev); maxx = max(maxx, sk+1); } else { dp[pos-1][1][i][sk] = min(dp[pos-1][1][i][sk], tim + prev); } int indn = (pos + i - 1) % n; ll nxt = l - a[pos].x + a[indn].x; if (tim + nxt <= a[indn].y) { dp[indn][0][i][sk+1] = min(dp[indn][0][i][sk+1], tim + nxt); maxx = max(maxx, sk+1); } else { dp[indn][0][i][sk] = min(dp[indn][0][i][sk], tim + nxt); } } } } } printf("%d\n", maxx); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 135160 KB | Output is correct |
2 | Correct | 77 ms | 135180 KB | Output is correct |
3 | Correct | 77 ms | 135160 KB | Output is correct |
4 | Correct | 67 ms | 135160 KB | Output is correct |
5 | Correct | 72 ms | 135160 KB | Output is correct |
6 | Correct | 66 ms | 135160 KB | Output is correct |
7 | Correct | 67 ms | 135160 KB | Output is correct |
8 | Correct | 76 ms | 135160 KB | Output is correct |
9 | Correct | 67 ms | 135164 KB | Output is correct |
10 | Correct | 66 ms | 135160 KB | Output is correct |
11 | Correct | 79 ms | 135160 KB | Output is correct |
12 | Correct | 68 ms | 135160 KB | Output is correct |
13 | Correct | 66 ms | 135160 KB | Output is correct |
14 | Correct | 69 ms | 135160 KB | Output is correct |
15 | Correct | 65 ms | 135160 KB | Output is correct |
16 | Correct | 67 ms | 135160 KB | Output is correct |
17 | Correct | 66 ms | 135160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 135160 KB | Output is correct |
2 | Correct | 77 ms | 135180 KB | Output is correct |
3 | Correct | 77 ms | 135160 KB | Output is correct |
4 | Correct | 67 ms | 135160 KB | Output is correct |
5 | Correct | 72 ms | 135160 KB | Output is correct |
6 | Correct | 66 ms | 135160 KB | Output is correct |
7 | Correct | 67 ms | 135160 KB | Output is correct |
8 | Correct | 76 ms | 135160 KB | Output is correct |
9 | Correct | 67 ms | 135164 KB | Output is correct |
10 | Correct | 66 ms | 135160 KB | Output is correct |
11 | Correct | 79 ms | 135160 KB | Output is correct |
12 | Correct | 68 ms | 135160 KB | Output is correct |
13 | Correct | 66 ms | 135160 KB | Output is correct |
14 | Correct | 69 ms | 135160 KB | Output is correct |
15 | Correct | 65 ms | 135160 KB | Output is correct |
16 | Correct | 67 ms | 135160 KB | Output is correct |
17 | Correct | 66 ms | 135160 KB | Output is correct |
18 | Correct | 68 ms | 135236 KB | Output is correct |
19 | Correct | 67 ms | 135288 KB | Output is correct |
20 | Correct | 66 ms | 135160 KB | Output is correct |
21 | Correct | 66 ms | 135160 KB | Output is correct |
22 | Correct | 66 ms | 135160 KB | Output is correct |
23 | Correct | 67 ms | 135160 KB | Output is correct |
24 | Correct | 66 ms | 135160 KB | Output is correct |
25 | Correct | 65 ms | 135160 KB | Output is correct |
26 | Correct | 68 ms | 135160 KB | Output is correct |
27 | Correct | 66 ms | 135288 KB | Output is correct |
28 | Correct | 69 ms | 135160 KB | Output is correct |
29 | Correct | 65 ms | 135160 KB | Output is correct |
30 | Correct | 68 ms | 135160 KB | Output is correct |
31 | Correct | 65 ms | 135240 KB | Output is correct |
32 | Correct | 68 ms | 135160 KB | Output is correct |
33 | Correct | 68 ms | 135160 KB | Output is correct |
34 | Correct | 67 ms | 135160 KB | Output is correct |
35 | Correct | 67 ms | 135280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 135160 KB | Output is correct |
2 | Correct | 77 ms | 135180 KB | Output is correct |
3 | Correct | 77 ms | 135160 KB | Output is correct |
4 | Correct | 67 ms | 135160 KB | Output is correct |
5 | Correct | 72 ms | 135160 KB | Output is correct |
6 | Correct | 66 ms | 135160 KB | Output is correct |
7 | Correct | 67 ms | 135160 KB | Output is correct |
8 | Correct | 76 ms | 135160 KB | Output is correct |
9 | Correct | 67 ms | 135164 KB | Output is correct |
10 | Correct | 66 ms | 135160 KB | Output is correct |
11 | Correct | 79 ms | 135160 KB | Output is correct |
12 | Correct | 68 ms | 135160 KB | Output is correct |
13 | Correct | 66 ms | 135160 KB | Output is correct |
14 | Correct | 69 ms | 135160 KB | Output is correct |
15 | Correct | 65 ms | 135160 KB | Output is correct |
16 | Correct | 67 ms | 135160 KB | Output is correct |
17 | Correct | 66 ms | 135160 KB | Output is correct |
18 | Correct | 91 ms | 135272 KB | Output is correct |
19 | Correct | 80 ms | 135176 KB | Output is correct |
20 | Correct | 73 ms | 135160 KB | Output is correct |
21 | Correct | 78 ms | 135160 KB | Output is correct |
22 | Correct | 84 ms | 135160 KB | Output is correct |
23 | Correct | 73 ms | 135160 KB | Output is correct |
24 | Correct | 69 ms | 135160 KB | Output is correct |
25 | Correct | 76 ms | 135160 KB | Output is correct |
26 | Correct | 77 ms | 135160 KB | Output is correct |
27 | Correct | 81 ms | 135160 KB | Output is correct |
28 | Correct | 69 ms | 135160 KB | Output is correct |
29 | Correct | 73 ms | 135160 KB | Output is correct |
30 | Correct | 72 ms | 135160 KB | Output is correct |
31 | Correct | 73 ms | 135180 KB | Output is correct |
32 | Correct | 70 ms | 135160 KB | Output is correct |
33 | Correct | 72 ms | 135160 KB | Output is correct |
34 | Correct | 69 ms | 135160 KB | Output is correct |
35 | Correct | 83 ms | 135160 KB | Output is correct |
36 | Correct | 71 ms | 135160 KB | Output is correct |
37 | Correct | 81 ms | 135176 KB | Output is correct |
38 | Correct | 69 ms | 135160 KB | Output is correct |
39 | Correct | 82 ms | 135288 KB | Output is correct |
40 | Correct | 71 ms | 135160 KB | Output is correct |
41 | Correct | 105 ms | 135160 KB | Output is correct |
42 | Correct | 95 ms | 135160 KB | Output is correct |
43 | Correct | 103 ms | 135160 KB | Output is correct |
44 | Correct | 95 ms | 135164 KB | Output is correct |
45 | Correct | 121 ms | 135288 KB | Output is correct |
46 | Correct | 90 ms | 135288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 135160 KB | Output is correct |
2 | Correct | 77 ms | 135180 KB | Output is correct |
3 | Correct | 77 ms | 135160 KB | Output is correct |
4 | Correct | 67 ms | 135160 KB | Output is correct |
5 | Correct | 72 ms | 135160 KB | Output is correct |
6 | Correct | 66 ms | 135160 KB | Output is correct |
7 | Correct | 67 ms | 135160 KB | Output is correct |
8 | Correct | 76 ms | 135160 KB | Output is correct |
9 | Correct | 67 ms | 135164 KB | Output is correct |
10 | Correct | 66 ms | 135160 KB | Output is correct |
11 | Correct | 79 ms | 135160 KB | Output is correct |
12 | Correct | 68 ms | 135160 KB | Output is correct |
13 | Correct | 66 ms | 135160 KB | Output is correct |
14 | Correct | 69 ms | 135160 KB | Output is correct |
15 | Correct | 65 ms | 135160 KB | Output is correct |
16 | Correct | 67 ms | 135160 KB | Output is correct |
17 | Correct | 66 ms | 135160 KB | Output is correct |
18 | Correct | 68 ms | 135236 KB | Output is correct |
19 | Correct | 67 ms | 135288 KB | Output is correct |
20 | Correct | 66 ms | 135160 KB | Output is correct |
21 | Correct | 66 ms | 135160 KB | Output is correct |
22 | Correct | 66 ms | 135160 KB | Output is correct |
23 | Correct | 67 ms | 135160 KB | Output is correct |
24 | Correct | 66 ms | 135160 KB | Output is correct |
25 | Correct | 65 ms | 135160 KB | Output is correct |
26 | Correct | 68 ms | 135160 KB | Output is correct |
27 | Correct | 66 ms | 135288 KB | Output is correct |
28 | Correct | 69 ms | 135160 KB | Output is correct |
29 | Correct | 65 ms | 135160 KB | Output is correct |
30 | Correct | 68 ms | 135160 KB | Output is correct |
31 | Correct | 65 ms | 135240 KB | Output is correct |
32 | Correct | 68 ms | 135160 KB | Output is correct |
33 | Correct | 68 ms | 135160 KB | Output is correct |
34 | Correct | 67 ms | 135160 KB | Output is correct |
35 | Correct | 67 ms | 135280 KB | Output is correct |
36 | Correct | 91 ms | 135272 KB | Output is correct |
37 | Correct | 80 ms | 135176 KB | Output is correct |
38 | Correct | 73 ms | 135160 KB | Output is correct |
39 | Correct | 78 ms | 135160 KB | Output is correct |
40 | Correct | 84 ms | 135160 KB | Output is correct |
41 | Correct | 73 ms | 135160 KB | Output is correct |
42 | Correct | 69 ms | 135160 KB | Output is correct |
43 | Correct | 76 ms | 135160 KB | Output is correct |
44 | Correct | 77 ms | 135160 KB | Output is correct |
45 | Correct | 81 ms | 135160 KB | Output is correct |
46 | Correct | 69 ms | 135160 KB | Output is correct |
47 | Correct | 73 ms | 135160 KB | Output is correct |
48 | Correct | 72 ms | 135160 KB | Output is correct |
49 | Correct | 73 ms | 135180 KB | Output is correct |
50 | Correct | 70 ms | 135160 KB | Output is correct |
51 | Correct | 72 ms | 135160 KB | Output is correct |
52 | Correct | 69 ms | 135160 KB | Output is correct |
53 | Correct | 83 ms | 135160 KB | Output is correct |
54 | Correct | 71 ms | 135160 KB | Output is correct |
55 | Correct | 81 ms | 135176 KB | Output is correct |
56 | Correct | 69 ms | 135160 KB | Output is correct |
57 | Correct | 82 ms | 135288 KB | Output is correct |
58 | Correct | 71 ms | 135160 KB | Output is correct |
59 | Correct | 105 ms | 135160 KB | Output is correct |
60 | Correct | 95 ms | 135160 KB | Output is correct |
61 | Correct | 103 ms | 135160 KB | Output is correct |
62 | Correct | 95 ms | 135164 KB | Output is correct |
63 | Correct | 121 ms | 135288 KB | Output is correct |
64 | Correct | 90 ms | 135288 KB | Output is correct |
65 | Correct | 96 ms | 135160 KB | Output is correct |
66 | Correct | 111 ms | 135288 KB | Output is correct |
67 | Correct | 109 ms | 135160 KB | Output is correct |
68 | Correct | 98 ms | 135196 KB | Output is correct |
69 | Correct | 117 ms | 135160 KB | Output is correct |
70 | Correct | 116 ms | 135160 KB | Output is correct |
71 | Correct | 107 ms | 135288 KB | Output is correct |
72 | Correct | 100 ms | 135296 KB | Output is correct |
73 | Correct | 87 ms | 135160 KB | Output is correct |
74 | Correct | 92 ms | 135160 KB | Output is correct |
75 | Correct | 92 ms | 135160 KB | Output is correct |
76 | Correct | 104 ms | 135160 KB | Output is correct |
77 | Correct | 100 ms | 135292 KB | Output is correct |
78 | Correct | 91 ms | 135160 KB | Output is correct |
79 | Correct | 91 ms | 135240 KB | Output is correct |
80 | Correct | 103 ms | 135160 KB | Output is correct |
81 | Correct | 102 ms | 135160 KB | Output is correct |
82 | Correct | 95 ms | 135160 KB | Output is correct |
83 | Correct | 98 ms | 135160 KB | Output is correct |
84 | Correct | 88 ms | 135292 KB | Output is correct |
85 | Correct | 93 ms | 135160 KB | Output is correct |
86 | Correct | 98 ms | 135160 KB | Output is correct |
87 | Correct | 97 ms | 135160 KB | Output is correct |
88 | Correct | 110 ms | 135288 KB | Output is correct |
89 | Correct | 105 ms | 135160 KB | Output is correct |
90 | Correct | 85 ms | 135160 KB | Output is correct |
91 | Correct | 117 ms | 135160 KB | Output is correct |
92 | Correct | 108 ms | 135160 KB | Output is correct |
93 | Correct | 92 ms | 135160 KB | Output is correct |