답안 #156770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156770 2019-10-07T10:44:40 Z brcode Safety (NOI18_safety) C++14
35 / 100
403 ms 604 KB
#include <iostream>
#include <deque>
using namespace std;
const int MAXN = 5e3+5;
const int MAXK = 5e3+5;
deque<pair<int,int>> d1;
int dp[3][MAXK];
int arr[MAXN];
int main(){
    int n,h;
    cin>>n>>h;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=min(MAXK-1,h);j++){
            int hold = dp[(i-1)%2][j];
            while(d1.size() && d1.back().first>hold){
                d1.pop_back();
            }
            d1.push_back(make_pair(hold,j));

        }
        for(int j=0;j<MAXK;j++){

            dp[i%2][j] = d1.front().first+abs(j-arr[i]);
            if(j<=10){
              //  cout<<i<<" "<<j<<" "<<dp[i%2][j]<<" "<<d1.front().first<<" "<<d1.front().second<<endl;
            }
            if(d1.front().second == j-h){
                d1.pop_front();
            }
            if(j+1+h<MAXK){
                int hold = dp[(i-1)%2][j+1+h];
                while(d1.size() && d1.back().first>hold){
                    d1.pop_back();
                }
                d1.push_back(make_pair(hold,j+h+1));
            }

        }
        while(d1.size()){
            d1.pop_back();
        }
    }
    int ans = 1e9;
    for(int i=0;i<MAXK;i++){
        ans = min(ans,dp[n%2][i]);
    }
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 39 ms 416 KB Output is correct
14 Correct 40 ms 404 KB Output is correct
15 Correct 42 ms 488 KB Output is correct
16 Correct 38 ms 376 KB Output is correct
17 Correct 34 ms 376 KB Output is correct
18 Correct 28 ms 376 KB Output is correct
19 Correct 36 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 39 ms 416 KB Output is correct
14 Correct 40 ms 404 KB Output is correct
15 Correct 42 ms 488 KB Output is correct
16 Correct 38 ms 376 KB Output is correct
17 Correct 34 ms 376 KB Output is correct
18 Correct 28 ms 376 KB Output is correct
19 Correct 36 ms 376 KB Output is correct
20 Correct 41 ms 452 KB Output is correct
21 Correct 41 ms 380 KB Output is correct
22 Correct 34 ms 376 KB Output is correct
23 Correct 32 ms 376 KB Output is correct
24 Correct 39 ms 376 KB Output is correct
25 Correct 33 ms 376 KB Output is correct
26 Correct 39 ms 376 KB Output is correct
27 Correct 37 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 39 ms 416 KB Output is correct
14 Correct 40 ms 404 KB Output is correct
15 Correct 42 ms 488 KB Output is correct
16 Correct 38 ms 376 KB Output is correct
17 Correct 34 ms 376 KB Output is correct
18 Correct 28 ms 376 KB Output is correct
19 Correct 36 ms 376 KB Output is correct
20 Correct 41 ms 452 KB Output is correct
21 Correct 41 ms 380 KB Output is correct
22 Correct 34 ms 376 KB Output is correct
23 Correct 32 ms 376 KB Output is correct
24 Correct 39 ms 376 KB Output is correct
25 Correct 33 ms 376 KB Output is correct
26 Correct 39 ms 376 KB Output is correct
27 Correct 37 ms 376 KB Output is correct
28 Correct 381 ms 448 KB Output is correct
29 Correct 323 ms 436 KB Output is correct
30 Correct 387 ms 376 KB Output is correct
31 Correct 328 ms 472 KB Output is correct
32 Correct 316 ms 452 KB Output is correct
33 Correct 388 ms 504 KB Output is correct
34 Correct 403 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Incorrect 3 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Incorrect 3 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -