Submission #961646

# Submission time Handle Problem Language Result Execution time Memory
961646 2024-04-12T09:32:38 Z vjudge1 Safety (NOI18_safety) C++17
35 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 5e3 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 14;

int n, h;
int a[maxn];
ll dp[maxn][maxn];

void test(){
    cin >> n >> h;
    for(int i = 1; i <= n ;i++){
        cin >> a[i];
    }
    for(int x = 0; x <= 5000; x++){
        dp[1][x] = abs(x - a[1]);
    }
    for(int i = 2; i <= n; i++){
        deque<ll> d;
        for(int x = 0, l = 0, r = -1; x <= 5000; x++){
            while(abs(r - x + 1) <= h && r < 5000){
                r++;
                while(d.size() && d.back() > dp[i-1][r]){
                    d.pop_back();
                }
                d.push_back(dp[i-1][r]);
            }
            while(abs(l - x) > h){
                if(d.front() == dp[i-1][l]){
                    d.pop_front();
                }
                l++;
            }
            dp[i][x] = d.front() + abs(x - a[i]);
        }
    }
    sort(dp[n], dp[n] + 5000 + 1);
    cout << dp[n][0];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; t = 1;
    while(t--) test();
    cout << ent;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3285 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 21 ms 21080 KB Output is correct
14 Correct 20 ms 21084 KB Output is correct
15 Correct 22 ms 21152 KB Output is correct
16 Correct 21 ms 21336 KB Output is correct
17 Correct 18 ms 19036 KB Output is correct
18 Correct 15 ms 16984 KB Output is correct
19 Correct 20 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 21 ms 21080 KB Output is correct
14 Correct 20 ms 21084 KB Output is correct
15 Correct 22 ms 21152 KB Output is correct
16 Correct 21 ms 21336 KB Output is correct
17 Correct 18 ms 19036 KB Output is correct
18 Correct 15 ms 16984 KB Output is correct
19 Correct 20 ms 21080 KB Output is correct
20 Correct 18 ms 19032 KB Output is correct
21 Correct 22 ms 21112 KB Output is correct
22 Correct 19 ms 19036 KB Output is correct
23 Correct 14 ms 17040 KB Output is correct
24 Correct 19 ms 19036 KB Output is correct
25 Correct 18 ms 16988 KB Output is correct
26 Correct 30 ms 21096 KB Output is correct
27 Correct 20 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 21 ms 21080 KB Output is correct
14 Correct 20 ms 21084 KB Output is correct
15 Correct 22 ms 21152 KB Output is correct
16 Correct 21 ms 21336 KB Output is correct
17 Correct 18 ms 19036 KB Output is correct
18 Correct 15 ms 16984 KB Output is correct
19 Correct 20 ms 21080 KB Output is correct
20 Correct 18 ms 19032 KB Output is correct
21 Correct 22 ms 21112 KB Output is correct
22 Correct 19 ms 19036 KB Output is correct
23 Correct 14 ms 17040 KB Output is correct
24 Correct 19 ms 19036 KB Output is correct
25 Correct 18 ms 16988 KB Output is correct
26 Correct 30 ms 21096 KB Output is correct
27 Correct 20 ms 19036 KB Output is correct
28 Correct 211 ms 201552 KB Output is correct
29 Correct 189 ms 169060 KB Output is correct
30 Correct 218 ms 197584 KB Output is correct
31 Correct 164 ms 164696 KB Output is correct
32 Correct 181 ms 164692 KB Output is correct
33 Correct 236 ms 201816 KB Output is correct
34 Correct 189 ms 197456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -