답안 #581800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581800 2022-06-23T06:35:31 Z 박상훈(#8364) Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 596 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=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);
    if (n>20) {printf("asdfkjsdf;j"); exit(0);}

    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:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         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 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Runtime error 1 ms 596 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Runtime error 1 ms 596 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Runtime error 1 ms 596 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -