답안 #715575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715575 2023-03-27T08:45:41 Z cbup 쌀 창고 (IOI11_ricehub) C++14
68 / 100
16 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,m,check = 0;
    vector<long long> prefixSum(n+1,0);

    st = en = 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;
    for(int i=0;i<n;i++){
        en = i;
        mid = (st+en)/2;
        cost = findcost(st,en,mid,prefixSum,x);

        if(cost <= b){
            ans = max(ans,en-st+1LL);
        }
        else{
            while(findcost(st,en,mid,prefixSum,x) > b){
                st++;
                mid = (st+en)/2;
            }
        }
        //cout<<st<<" "<<en<<" "<<cost<<endl;
    }

    return ans;
}

Compilation message

ricehub.cpp: In function 'long long int besthub(int, int, int*, long long int)':
ricehub.cpp:10:19: warning: unused variable 'm' [-Wunused-variable]
   10 |     int mid,st,en,m,check = 0;
      |                   ^
ricehub.cpp:10:21: warning: unused variable 'check' [-Wunused-variable]
   10 |     int mid,st,en,m,check = 0;
      |                     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 240 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 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 1 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 1 ms 212 KB Output is correct
16 Correct 0 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 1 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 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 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 1 ms 212 KB Output is correct
28 Correct 1 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 0 ms 212 KB Output is correct
4 Correct 1 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 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 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 1 ms 212 KB Output is correct
20 Correct 1 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 512 KB Output is correct
3 Correct 12 ms 1492 KB Output is correct
4 Correct 12 ms 1480 KB Output is correct
5 Correct 5 ms 828 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 9 ms 1492 KB Output is correct
8 Correct 9 ms 1460 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 13 ms 1492 KB Output is correct
12 Correct 16 ms 1440 KB Output is correct
13 Correct 5 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 9 ms 1168 KB Output is correct
16 Correct 9 ms 1108 KB Output is correct
17 Correct 10 ms 1236 KB Output is correct
18 Incorrect 12 ms 1364 KB Output isn't correct
19 Halted 0 ms 0 KB -