답안 #961614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961614 2024-04-12T08:56:13 Z vjudge1 Safety (NOI18_safety) C++17
13 / 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];
ll p[maxl][maxn];
int lg[maxn];

void test(){
    cin >> n >> h;
    for(int i = 2; i <= 5001; i++){
        lg[i] = lg[i >> 1] + 1;
    }
    for(int i = 1; i <= n ;i++){
        cin >> a[i];
    }
    for(int x = 0; x <= 400; x++){
        dp[1][x] = abs(x - a[1]);
    }
    for(int i = 2; i <= n; i++){
        for(int x = 0; x <= 400; x++){
            p[0][x] = dp[i-1][x];
        }
        for(int k = 1; (1<<k) - 1 <= 400; k++){
            for(int x = 0; x + (1<<k) - 1 <= 400; x++){
                p[k][x] = min(p[k-1][x], p[k-1][x+(1<<(k-1))]);
            }
        }
        for(int x = 0; x <= 400; x++){
            int l = max(0, x - h);
            int r = min(400, x + h);
            int k = lg[r - l + 1];
            dp[i][x] = min(p[k][l], p[k][r-(1<<k)+1]);
            dp[i][x] += abs(x - a[i]);
        }
    }
    sort(dp[n], dp[n] + 400 + 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3064 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 5 ms 20824 KB Output is correct
14 Correct 4 ms 20828 KB Output is correct
15 Correct 4 ms 20828 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 5 ms 20824 KB Output is correct
14 Correct 4 ms 20828 KB Output is correct
15 Correct 4 ms 20828 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Incorrect 4 ms 20824 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 5 ms 20824 KB Output is correct
14 Correct 4 ms 20828 KB Output is correct
15 Correct 4 ms 20828 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 16732 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Incorrect 4 ms 20824 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -