# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200193 | 2020-02-05T16:15:58 Z | wilwxk | Safety (NOI18_safety) | C++14 | 47 ms | 19960 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(ll val, int id, int l) { if(id >= MAXN) return; while(dq.size() && dq.back().second < l) dq.pop_back(); while(dq.size() && dq.front().first >= val) dq.pop_front(); dq.push_front({val, id}); } 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(dp[i-1][j], j, -1); for(int j = 0; j < MAXN; j++) { update(dp[i-1][j+x], j+x, j-x); ll cost = abs(j-v[i]); cost += query(); dp[i][j] = cost; // printf("%d %d >> %lld\n", 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 | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 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 | 6 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 | 376 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 | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 6 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 | 47 ms | 19960 KB | Output is correct |
14 | Correct | 44 ms | 19228 KB | Output is correct |
15 | Correct | 45 ms | 19448 KB | Output is correct |
16 | Correct | 46 ms | 19960 KB | Output is correct |
17 | Correct | 43 ms | 17656 KB | Output is correct |
18 | Correct | 38 ms | 14712 KB | Output is correct |
19 | Correct | 47 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 | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 6 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 | 47 ms | 19960 KB | Output is correct |
14 | Correct | 44 ms | 19228 KB | Output is correct |
15 | Correct | 45 ms | 19448 KB | Output is correct |
16 | Correct | 46 ms | 19960 KB | Output is correct |
17 | Correct | 43 ms | 17656 KB | Output is correct |
18 | Correct | 38 ms | 14712 KB | Output is correct |
19 | Correct | 47 ms | 19064 KB | Output is correct |
20 | Incorrect | 47 ms | 18680 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 6 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 | 47 ms | 19960 KB | Output is correct |
14 | Correct | 44 ms | 19228 KB | Output is correct |
15 | Correct | 45 ms | 19448 KB | Output is correct |
16 | Correct | 46 ms | 19960 KB | Output is correct |
17 | Correct | 43 ms | 17656 KB | Output is correct |
18 | Correct | 38 ms | 14712 KB | Output is correct |
19 | Correct | 47 ms | 19064 KB | Output is correct |
20 | Incorrect | 47 ms | 18680 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 6 ms | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 6 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 | 764 KB | Output is correct |
3 | Correct | 5 ms | 632 KB | Output is correct |
4 | Correct | 6 ms | 760 KB | Output is correct |
5 | Correct | 6 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 632 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 6 ms | 888 KB | Output is correct |
9 | Correct | 6 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 | - |