# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200194 | 2020-02-05T16:20:25 Z | wilwxk | Safety (NOI18_safety) | C++14 | 566 ms | 196344 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 5e3+5; int v[MAXN]; ll dp[MAXN][MAXN]; deque<pair<ll, int> > dq; int n, x; void update(int i, int j, int l) { while(dq.size() && dq.back().second < l) dq.pop_back(); if(i >= MAXN || j >= MAXN) return; ll val = dp[i][j]; while(dq.size() && dq.front().first >= val) dq.pop_front(); dq.push_front({val, j}); } ll query() { return dq.back().first; } int main() { scanf("%d %d", &n, &x); for(int i = 1; i <= n; i++) scanf("%d", &v[i]); for(int i = 1; i <= n; i++) { for(int j = 0; j < min(x, MAXN); j++) update(i-1, j, -1); for(int j = 0; j < MAXN; j++) { update(i-1, j+x, j-x); ll cost = abs(j-v[i]); cost += query(); dp[i][j] = cost; } while(dq.size()) dq.pop_back(); } ll ans = 1e18; for(int i = 0; i < MAXN; i++) ans = min(ans, dp[n][i]); printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 888 KB | Output is correct |
2 | Correct | 7 ms | 888 KB | Output is correct |
3 | Correct | 6 ms | 888 KB | Output is correct |
4 | Correct | 6 ms | 888 KB | Output is correct |
5 | Correct | 7 ms | 888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6 ms | 504 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 7 ms | 888 KB | Output is correct |
10 | Correct | 6 ms | 888 KB | Output is correct |
11 | Correct | 6 ms | 888 KB | Output is correct |
12 | Correct | 7 ms | 888 KB | Output is correct |
13 | Correct | 55 ms | 19960 KB | Output is correct |
14 | Correct | 50 ms | 19236 KB | Output is correct |
15 | Correct | 71 ms | 19448 KB | Output is correct |
16 | Correct | 79 ms | 19980 KB | Output is correct |
17 | Correct | 48 ms | 17816 KB | Output is correct |
18 | Correct | 37 ms | 14712 KB | Output is correct |
19 | Correct | 65 ms | 19064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 7 ms | 888 KB | Output is correct |
10 | Correct | 6 ms | 888 KB | Output is correct |
11 | Correct | 6 ms | 888 KB | Output is correct |
12 | Correct | 7 ms | 888 KB | Output is correct |
13 | Correct | 55 ms | 19960 KB | Output is correct |
14 | Correct | 50 ms | 19236 KB | Output is correct |
15 | Correct | 71 ms | 19448 KB | Output is correct |
16 | Correct | 79 ms | 19980 KB | Output is correct |
17 | Correct | 48 ms | 17816 KB | Output is correct |
18 | Correct | 37 ms | 14712 KB | Output is correct |
19 | Correct | 65 ms | 19064 KB | Output is correct |
20 | Correct | 62 ms | 18552 KB | Output is correct |
21 | Correct | 52 ms | 19976 KB | Output is correct |
22 | Correct | 49 ms | 16632 KB | Output is correct |
23 | Correct | 53 ms | 15352 KB | Output is correct |
24 | Correct | 53 ms | 18552 KB | Output is correct |
25 | Correct | 44 ms | 15736 KB | Output is correct |
26 | Correct | 47 ms | 19960 KB | Output is correct |
27 | Correct | 49 ms | 18556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 7 ms | 888 KB | Output is correct |
10 | Correct | 6 ms | 888 KB | Output is correct |
11 | Correct | 6 ms | 888 KB | Output is correct |
12 | Correct | 7 ms | 888 KB | Output is correct |
13 | Correct | 55 ms | 19960 KB | Output is correct |
14 | Correct | 50 ms | 19236 KB | Output is correct |
15 | Correct | 71 ms | 19448 KB | Output is correct |
16 | Correct | 79 ms | 19980 KB | Output is correct |
17 | Correct | 48 ms | 17816 KB | Output is correct |
18 | Correct | 37 ms | 14712 KB | Output is correct |
19 | Correct | 65 ms | 19064 KB | Output is correct |
20 | Correct | 62 ms | 18552 KB | Output is correct |
21 | Correct | 52 ms | 19976 KB | Output is correct |
22 | Correct | 49 ms | 16632 KB | Output is correct |
23 | Correct | 53 ms | 15352 KB | Output is correct |
24 | Correct | 53 ms | 18552 KB | Output is correct |
25 | Correct | 44 ms | 15736 KB | Output is correct |
26 | Correct | 47 ms | 19960 KB | Output is correct |
27 | Correct | 49 ms | 18556 KB | Output is correct |
28 | Correct | 451 ms | 196284 KB | Output is correct |
29 | Correct | 367 ms | 165472 KB | Output is correct |
30 | Correct | 493 ms | 193116 KB | Output is correct |
31 | Correct | 390 ms | 159968 KB | Output is correct |
32 | Correct | 360 ms | 161400 KB | Output is correct |
33 | Correct | 453 ms | 196344 KB | Output is correct |
34 | Correct | 566 ms | 192228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 7 ms | 888 KB | Output is correct |
10 | Correct | 6 ms | 888 KB | Output is correct |
11 | Correct | 6 ms | 888 KB | Output is correct |
12 | Correct | 7 ms | 888 KB | Output is correct |
13 | Incorrect | 5 ms | 632 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 760 KB | Output is correct |
3 | Correct | 6 ms | 632 KB | Output is correct |
4 | Correct | 7 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 7 ms | 888 KB | Output is correct |
10 | Correct | 6 ms | 888 KB | Output is correct |
11 | Correct | 6 ms | 888 KB | Output is correct |
12 | Correct | 7 ms | 888 KB | Output is correct |
13 | Incorrect | 5 ms | 632 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |