답안 #581805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581805 2022-06-23T06:37:46 Z 박상훈(#8364) Sparklers (JOI17_sparklers) C++17
50 / 100
83 ms 17352 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const ll INF = 4e18;
int d[100100], n, k, t;
ll dp[1010][1010];

bool solve(int s){

    for (int i=1;i<=n;i++) fill(dp[i], dp[i]+n+1, -1);
    dp[k][k] = (ll)t * s * 2;

    for (int D=0;D<n-1;D++){
        for (int i=max(0, k-D);i<=k;i++) if (dp[i][i+D]>=0){
            int j = i+D;
            dp[i][j] = min(dp[i][j], INF);

            if (i>1){
                if (dp[i][j] >= d[i-1]){
                    dp[i-1][j] = max(dp[i-1][j], dp[i][j] + (ll)t*s*2 - d[i-1]);
                }
            }
            if (j<n){
                if (dp[i][j] >= d[j]){
                    dp[i][j+1] = max(dp[i][j+1], dp[i][j] + (ll)t*s*2 - d[j]);
                }
            }

        }
    }

    return dp[1][n] >= 0;

    /*while(r-l+1<n){
        ll dL = 4e18, dR = 4e18;
        if (l>1) dL = d[l-1];
        if (r<n) dR = d[r];

        if (dL < dR){
            if (rem < dL) return 0;
            rem += (ll)t * s * 2 - dL;
            rem = min(rem, INF);
            --l;
        }
        else{
            if (rem < dR) return 0;
            rem += (ll)t * s  * 2 - dR;
            rem = min(rem, INF);
            ++r;
        }
    }
    return 1;*/
}

int main(){
    scanf("%d %d %d", &n, &k, &t);

    int prv = 0;
    for (int i=0;i<n;i++){
        int cur;
        scanf("%d", &cur);
        d[i] = cur - prv;
        prv = cur;
    }

    if (n==1) {printf("0\n"); exit(0);}

    int l = 0, r = 1e9, ans = 1e9;
    while(l<=r){
        int m = (l+r)>>1;
        if (solve(m)) ans = m, r = m-1;
        else l = m+1;
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d %d %d", &n, &k, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d", &cur);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 33 ms 6108 KB Output is correct
23 Correct 15 ms 4808 KB Output is correct
24 Correct 18 ms 6080 KB Output is correct
25 Correct 39 ms 8148 KB Output is correct
26 Correct 38 ms 8148 KB Output is correct
27 Correct 69 ms 8200 KB Output is correct
28 Correct 83 ms 8148 KB Output is correct
29 Correct 59 ms 8148 KB Output is correct
30 Correct 57 ms 8192 KB Output is correct
31 Correct 55 ms 8200 KB Output is correct
32 Correct 50 ms 8180 KB Output is correct
33 Correct 69 ms 8196 KB Output is correct
34 Correct 59 ms 8148 KB Output is correct
35 Correct 52 ms 8200 KB Output is correct
36 Correct 35 ms 8148 KB Output is correct
37 Correct 47 ms 8196 KB Output is correct
38 Correct 48 ms 8148 KB Output is correct
39 Correct 58 ms 8148 KB Output is correct
40 Correct 65 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 33 ms 6108 KB Output is correct
23 Correct 15 ms 4808 KB Output is correct
24 Correct 18 ms 6080 KB Output is correct
25 Correct 39 ms 8148 KB Output is correct
26 Correct 38 ms 8148 KB Output is correct
27 Correct 69 ms 8200 KB Output is correct
28 Correct 83 ms 8148 KB Output is correct
29 Correct 59 ms 8148 KB Output is correct
30 Correct 57 ms 8192 KB Output is correct
31 Correct 55 ms 8200 KB Output is correct
32 Correct 50 ms 8180 KB Output is correct
33 Correct 69 ms 8196 KB Output is correct
34 Correct 59 ms 8148 KB Output is correct
35 Correct 52 ms 8200 KB Output is correct
36 Correct 35 ms 8148 KB Output is correct
37 Correct 47 ms 8196 KB Output is correct
38 Correct 48 ms 8148 KB Output is correct
39 Correct 58 ms 8148 KB Output is correct
40 Correct 65 ms 8148 KB Output is correct
41 Runtime error 37 ms 17352 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -