답안 #76856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76856 2018-09-18T17:59:24 Z Vardanyan Stove (JOI18_stove) C++14
20 / 100
581 ms 209388 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 5007;
long long a[N];
long long dp[N][N];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    queue<pair<int,int> > q;
    for(int i = 1;i<=n;i++){
           if(i>1) q.push({i,1});
            scanf("%lld",&a[i]);
            for(int j = 0;j<=k;j++) dp[i][j] = 100000000000000005;
    }
    for(int kk = 1;kk<=k;kk++){
        dp[1][kk] = 1;
        /*for(int i = 2;i<=n;i++){
            dp[i][kk] = min(dp[i][kk],dp[i-1][kk]+((a[i]+1)-(a[i-1]+1)));
            dp[i][kk+1] = min(dp[i][kk+1],dp[i-1][kk]+1);
        }*/
        while(!q.empty()){
            pair<int,int> x = q.front();
            if(x.second>kk) break;
            q.pop();
            int i = x.first;
            long long u = dp[i-1][kk]+((a[i]+1)-(a[i-1]+1));
            if(dp[i][kk]>u){
                dp[i][kk] = u;
                q.push({i+1,kk+1});
            }
            u = dp[i-1][kk]+1;
            if(dp[i][kk+1]>u){
                dp[i][kk+1] = u;
                q.push({i+1,kk+1});
            }
        }
    }
    printf("%lld\n",dp[n][k]);
    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
stove.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[i]);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 12 ms 13152 KB Output is correct
11 Correct 28 ms 15636 KB Output is correct
12 Correct 175 ms 44296 KB Output is correct
13 Correct 330 ms 83580 KB Output is correct
14 Runtime error 581 ms 209388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 516 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 12 ms 13152 KB Output is correct
11 Correct 28 ms 15636 KB Output is correct
12 Correct 175 ms 44296 KB Output is correct
13 Correct 330 ms 83580 KB Output is correct
14 Runtime error 581 ms 209388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -