답안 #581830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581830 2022-06-23T07:03:50 Z 반딧불(#8365) Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 212 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;
    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;
    while(a<al || b<bl){
        if(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(Avec[a].first <= val){
            val += Avec[a++].second;
        }
        else if(Bvec[b].first <= val){
            val += Bvec[b++].second;
        }
        else return false;
        if(val<0) return false;
    }
    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;

    ll L = 0, 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:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d %d %lld", &n, &k, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:58:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -