답안 #581867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581867 2022-06-23T07:33:25 Z 반딧불(#8365) Sparklers (JOI17_sparklers) C++17
50 / 100
143 ms 36908 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

void makeVector(vector<pair<ll, ll> > &ret, vector<ll> vec){
    ll sum = 0, minSum = 0;
    for(auto x: vec){
        if(sum>0 && x<0){
            ret.push_back(make_pair(-minSum, sum));
            sum = minSum = 0;
        }
        sum += x;
        minSum = min(minSum, sum);
    }
    if(sum || minSum) ret.push_back(make_pair(-minSum, sum));
    ret.push_back(make_pair(5e18, -5e18));
}

bool able(ll speed){
    speed*=t*2;
    if(speed==6){
        #ifdef TEST
        puts("");
        #endif // TEST
    }
    for(int i=1; i<n; i++) val[i] = revVal[n-i] = speed - (arr[i+1] - arr[i]);

    /// ����, ������ �ٵ��
    vector<pair<ll, ll> > Avec, Bvec;
    makeVector(Avec, vector<ll>(revVal+(n+1-k), revVal+n));
    makeVector(Bvec, vector<ll>(val+k, val+n));

    ll val = 0;
    int a = 0, b = 0;
    int al = (int)Avec.size()-1, bl = (int)Bvec.size()-1;

    for(int i=0; i<al-2; i++) assert(Avec[i].second >= 0);
    for(int i=0; i<bl-2; i++) assert(Bvec[i].second >= 0);

    while(a<al-1 || b<bl-1){
        if(a<al-1 && b<bl-1 && Avec[a].first <= val && Bvec[b].first <= val){ /// �� �� ���� �� ����
            if(Avec[a].second >= Bvec[b].second) val += Avec[a++].second;
            else val += Bvec[b++].second;
        }
        else if(a<al-1 && Avec[a].first <= val){
            val += Avec[a++].second;
        }
        else if(b<bl-1 && Bvec[b].first <= val){
            val += Bvec[b++].second;
        }
        else return false;
        if(val<0) exit(1);
    }
    if(a>=al && b>=bl) return true;
    else if(a>=al){
        while(b<bl){
            if(Bvec[b].first > val) return false;
            val += Bvec[b++].second;
            if(val<0) return false;
        }
        return true;
    }
    else if(b>=bl){
        while(a<al){
            if(Avec[a].first > val) return false;
            val += Avec[a++].second;
            if(val<0) return false;
        }
        return true;
    }

    assert(a==al-1 && b==bl-1);
    /// �ϳ��� ���� ����
    vector<pair<ll, ll> > vec = {Avec[a], Bvec[b]};
    if(val >= vec[0].first && val+vec[0].second >= vec[1].first && val+vec[0].second+vec[1].second >= 0) return true;
    if(val >= vec[1].first && val+vec[1].second >= vec[0].first && val+vec[1].second+vec[0].second >= 0) return true;
    return false;
}

pair<ll, ll> DP[1002][1002];
ll able2(ll speed){
    speed*=t;
    for(int i=1; i<=n; i++) for(int j=i; j<=n; j++) DP[i][j].first=1e18, DP[i][j].second=-1e18;
    DP[k][k] = make_pair(arr[k], arr[k]);
    for(int d=1; d<n; d++){
        for(int i=1; i+d<=n; i++){
            int j = i+d;
            if((arr[j]-speed*d) <= (DP[i][j-1].second+speed)){
                DP[i][j].first = min(DP[i][j].first, max(arr[j]-speed*d, DP[i][j-1].first-speed));
                DP[i][j].second = max(DP[i][j].second, DP[i][j-1].second+speed);
            }
            if((arr[i]+speed*d) >= (DP[i+1][j].first-speed)){
                DP[i][j].first = min(DP[i][j].first, DP[i+1][j].first-speed);
                DP[i][j].second = max(DP[i][j].second, min(arr[i]+speed*d, DP[i+1][j].second+speed));
            }
        }
    }
    return DP[1][n].first <= DP[1][n].second;
}

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

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

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     scanf("%d %d %lld", &n, &k, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:111:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 54 ms 7436 KB Output is correct
23 Correct 34 ms 5108 KB Output is correct
24 Correct 43 ms 7380 KB Output is correct
25 Correct 86 ms 11644 KB Output is correct
26 Correct 126 ms 11604 KB Output is correct
27 Correct 98 ms 11604 KB Output is correct
28 Correct 102 ms 11648 KB Output is correct
29 Correct 143 ms 11724 KB Output is correct
30 Correct 115 ms 11644 KB Output is correct
31 Correct 97 ms 11604 KB Output is correct
32 Correct 102 ms 11604 KB Output is correct
33 Correct 109 ms 11644 KB Output is correct
34 Correct 112 ms 11644 KB Output is correct
35 Correct 124 ms 11644 KB Output is correct
36 Correct 87 ms 11640 KB Output is correct
37 Correct 99 ms 11644 KB Output is correct
38 Correct 116 ms 11644 KB Output is correct
39 Correct 95 ms 11604 KB Output is correct
40 Correct 115 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 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 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 54 ms 7436 KB Output is correct
23 Correct 34 ms 5108 KB Output is correct
24 Correct 43 ms 7380 KB Output is correct
25 Correct 86 ms 11644 KB Output is correct
26 Correct 126 ms 11604 KB Output is correct
27 Correct 98 ms 11604 KB Output is correct
28 Correct 102 ms 11648 KB Output is correct
29 Correct 143 ms 11724 KB Output is correct
30 Correct 115 ms 11644 KB Output is correct
31 Correct 97 ms 11604 KB Output is correct
32 Correct 102 ms 11604 KB Output is correct
33 Correct 109 ms 11644 KB Output is correct
34 Correct 112 ms 11644 KB Output is correct
35 Correct 124 ms 11644 KB Output is correct
36 Correct 87 ms 11640 KB Output is correct
37 Correct 99 ms 11644 KB Output is correct
38 Correct 116 ms 11644 KB Output is correct
39 Correct 95 ms 11604 KB Output is correct
40 Correct 115 ms 11640 KB Output is correct
41 Runtime error 80 ms 36908 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -