답안 #715578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715578 2023-03-27T08:52:19 Z cbup 쌀 창고 (IOI11_ricehub) C++14
100 / 100
13 ms 1492 KB
#include<bits/stdc++.h>
using namespace std;

long long findcost(int st,int en,int mid,vector<long long> &prefixSum,int *x){
    return (mid-st)*x[mid]*1LL-(prefixSum[mid]-prefixSum[st]) + (prefixSum[en+1]-prefixSum[mid+1])-(en-mid)*x[mid]*1LL;
}

long long besthub(int n,int l,int x[],long long b){
    long long cost,ans=1;
    int mid,st,en,len,low=0,high=n-1,m,check = 0;
    vector<long long> prefixSum(n+1,0);

    for(int i=1;i<=n;i++)prefixSum[i] = prefixSum[i-1]+x[i-1];
    //for(int i=1;i<=n;i++)cout<<prefixSum[i]<<" "; cout<<endl;
    while(low<=high){
        check = 0;
        len = (low+high)/2;
        for(st=0;st<n-len;st++){
            en = st+len;
            mid = (st+en)/2;
            cost = findcost(st,en,mid,prefixSum,x);

            if(cost <= b){
                ans = max(ans,en-st+1LL);
                check = 1;
                break;
            }
            //cout<<st<<" "<<en<<" "<<cost<<endl;
        }

        if(!check)high = len-1;
        else low = len+1;
    }

    return ans;
}

Compilation message

ricehub.cpp: In function 'long long int besthub(int, int, int*, long long int)':
ricehub.cpp:10:38: warning: unused variable 'm' [-Wunused-variable]
   10 |     int mid,st,en,len,low=0,high=n-1,m,check = 0;
      |                                      ^
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 13 ms 1492 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 6 ms 868 KB Output is correct
7 Correct 10 ms 1492 KB Output is correct
8 Correct 9 ms 1492 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 12 ms 1492 KB Output is correct
12 Correct 11 ms 1492 KB Output is correct
13 Correct 6 ms 852 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 9 ms 1108 KB Output is correct
16 Correct 8 ms 1068 KB Output is correct
17 Correct 11 ms 1364 KB Output is correct
18 Correct 9 ms 1236 KB Output is correct
19 Correct 10 ms 1388 KB Output is correct
20 Correct 10 ms 1312 KB Output is correct