답안 #581754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581754 2022-06-23T05:46:35 Z 반딧불(#8365) Sparklers (JOI17_sparklers) C++17
50 / 100
36 ms 4148 KB
/*#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
ll t;
ll arr[100002];

bool able(ll speed){
    speed*=t;
    int l = k, r = k;
    ll s = arr[k], e = arr[k];
    for(int cnt=1; cnt<n; cnt++){
        ll lDist = (s - speed) - (arr[l-1] + speed*cnt);
        ll rDist = (arr[r+1] - speed*cnt) - (e + speed);
        if(min(lDist, rDist) > 0) return false;
        if(lDist < rDist){
            l--;
            s = s - speed;
            e = min(arr[l] + speed*cnt, e+speed);
        }
        else{
            r++;
            s = max(arr[r] - speed*cnt, s-speed);
            e = e + speed;
        }
    }
    return true;
}

int main(){
    scanf("%d %d %lld", &n, &k, &t);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    arr[0] = -1e18, arr[n+1] = 1e18;
    if(arr[1] == arr[n]){
        puts("0");
        return 0;
    }

    ll L = 1, R = 1e9, ANS = 1e9;
    while(L<=R){
        ll MID = (L+R)/2;
        if(able(MID)) ANS = MID, R = MID-1;
        else L = MID+1;
    }
    printf("%lld", ANS);
}
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
ll t;
ll arr[100002];
bool DP[1002][1002];

ll able(ll speed){
    speed*=t;
    memset(DP, 0, sizeof(DP));
    DP[k][k] = true;
    for(int d=1; d<n; d++){
        for(int i=1; i+d<=n; i++){
            int j = i+d;
            if((DP[i+1][j] || DP[i][j-1]) && (arr[j] - arr[i] <= speed*d*2)) DP[i][j] = true;
        }
    }
    return DP[1][n];
}

int main(){
    scanf("%d %d %lld", &n, &k, &t);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    if(arr[1] == arr[n]){
        puts("0");
        return 0;
    }

    ll L = 1, R = 1e9, ANS = 1e9;
    while(L<=R){
        ll MID = (L+R)/2;
        if(able(MID)) ANS = MID, R = MID-1;
        else L = MID+1;
    }
    printf("%lld", ANS);
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     scanf("%d %d %lld", &n, &k, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:78:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1236 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1208 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1204 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 1208 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1208 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 1208 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1236 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1208 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1204 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 1208 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1208 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 1208 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 14 ms 1216 KB Output is correct
23 Correct 9 ms 1236 KB Output is correct
24 Correct 14 ms 1236 KB Output is correct
25 Correct 27 ms 1308 KB Output is correct
26 Correct 27 ms 1236 KB Output is correct
27 Correct 25 ms 1236 KB Output is correct
28 Correct 24 ms 1308 KB Output is correct
29 Correct 24 ms 1308 KB Output is correct
30 Correct 26 ms 1236 KB Output is correct
31 Correct 23 ms 1236 KB Output is correct
32 Correct 27 ms 1236 KB Output is correct
33 Correct 25 ms 1212 KB Output is correct
34 Correct 29 ms 1236 KB Output is correct
35 Correct 36 ms 1236 KB Output is correct
36 Correct 26 ms 1308 KB Output is correct
37 Correct 25 ms 1236 KB Output is correct
38 Correct 23 ms 1236 KB Output is correct
39 Correct 28 ms 1236 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1236 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1208 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1204 KB Output is correct
15 Correct 2 ms 1208 KB Output is correct
16 Correct 2 ms 1208 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1208 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 1208 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 14 ms 1216 KB Output is correct
23 Correct 9 ms 1236 KB Output is correct
24 Correct 14 ms 1236 KB Output is correct
25 Correct 27 ms 1308 KB Output is correct
26 Correct 27 ms 1236 KB Output is correct
27 Correct 25 ms 1236 KB Output is correct
28 Correct 24 ms 1308 KB Output is correct
29 Correct 24 ms 1308 KB Output is correct
30 Correct 26 ms 1236 KB Output is correct
31 Correct 23 ms 1236 KB Output is correct
32 Correct 27 ms 1236 KB Output is correct
33 Correct 25 ms 1212 KB Output is correct
34 Correct 29 ms 1236 KB Output is correct
35 Correct 36 ms 1236 KB Output is correct
36 Correct 26 ms 1308 KB Output is correct
37 Correct 25 ms 1236 KB Output is correct
38 Correct 23 ms 1236 KB Output is correct
39 Correct 28 ms 1236 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Runtime error 10 ms 4148 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -