답안 #674272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674272 2022-12-23T15:36:30 Z Ahmed57 Sparklers (JOI17_sparklers) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;
int n,k;int t;
int arr[100001];

bool check(int mid){
    int l = k-1 , r = k+1 , lin = k , rin = k;
    int te = t , tel = t , ter = t , suml = 0, sumr = 0;
    int minl = 1000000000;
    int minr = 1000000000;
    while(1){
        int mi = 0;
        bool ss = 0;
        while(l>=0){
            int dis = ((arr[l+1]-arr[l])+1)/2;
            int tim = (dis+(mid-1))/mid;
            if(tel<tim){
                break;
            }
            minl = min(minl,tel-tim);
            tel-=tim;tel+=t;
            suml+=t-tim;
            if(suml>0){
                ss = 1;
                lin = l;
                minr+=suml;
                te = tel;
                ter += suml;
                suml = 0;
                minl = 1000000000;
            }
            l--;
        }while(r<n){
            int dis = ((arr[r]-arr[r-1])+1)/2;
            int tim = (dis+(mid-1))/mid;
            if(ter<tim){
                break;
            }
            minr = min(minr,ter-tim);
            ter-=tim;
            ter+=t;
            sumr+=t-tim;
            if(sumr>0){
                ss = 1;
                rin = r;
                minl+=sumr;
                te = ter;
                tel += sumr;
                sumr = 0;
                minr = 1000000000.0;
            }
            r++;
        }
        if(lin==0&&rin==n-1)return 1;
        if(l==-1&&r==n&&((minr>=te-suml)||(minl>=te-sumr))){
            return 1;
        }
        if(ss==0)return 0;
    }
    return 1;
}
int main(){
    cin>>n>>k>>t;
    k--;
    for(int i = 0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    if(arr[0]==arr[n-1]){
        cout<<0<<"\n";
        return 0;
    }
    int l = 1 , r = 1e9 , ans = 0;
    while(l<=r){
        int mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
            ans = mid;
        }else l = mid+1;
    }
    cout<<ans;
}

Compilation message

sparklers.cpp: In function 'bool check(int)':
sparklers.cpp:13:13: warning: unused variable 'mi' [-Wunused-variable]
   13 |         int mi = 0;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -