답안 #950892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950892 2024-03-21T00:33:04 Z irmuun 쌀 창고 (IOI11_ricehub) C++17
100 / 100
22 ms 4520 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int besthub(int R,int L,int X[],ll B){
    ll sum[R+1];
    sum[0]=0;
    for(int i=0;i<R;i++){
        sum[i+1]=sum[i]+X[i];
    }
    int ans=0;
    for(int i=1;i<=R;i++){
        int l=0,r=R;
        while(l<r){
            int mid=(l+r+1)/2;
            if(i-mid<=0||i+mid>R){
                r=mid-1;
                continue;
            }
            ll cost=1ll*X[i-1]*mid-(sum[i-1]-sum[i-mid-1])+(sum[i+mid]-sum[i])-1ll*X[i-1]*mid;
            if(cost<=B){
                l=mid;
            }
            else{
                r=mid-1;
            }
        }
        ans=max(ans,l*2+1);
    }
    for(int i=1;i<R;i++){
        if((ll)X[i]-(ll)X[i-1]>B) continue;
        int l=0,r=R;
        while(l<r){
            int mid=(l+r+1)/2;
            if(i-mid<=0||i+mid+1>R){
                r=mid-1;
                continue;
            }
            ll cost=1ll*X[i-1]*mid-(sum[i-1]-sum[i-mid-1])+(sum[i+mid+1]-sum[i])-1ll*X[i-1]*(mid+1);
            if(cost<=B){
                l=mid;
            }
            else{
                r=mid-1;
            }
        }
        ans=max(ans,l*2+2);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 448 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 448 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 480 KB Output is correct
24 Correct 1 ms 712 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 20 ms 3440 KB Output is correct
4 Correct 20 ms 4520 KB Output is correct
5 Correct 10 ms 3164 KB Output is correct
6 Correct 8 ms 3164 KB Output is correct
7 Correct 19 ms 4188 KB Output is correct
8 Correct 22 ms 4444 KB Output is correct
9 Correct 7 ms 3160 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 20 ms 4444 KB Output is correct
12 Correct 20 ms 4468 KB Output is correct
13 Correct 8 ms 3416 KB Output is correct
14 Correct 8 ms 3416 KB Output is correct
15 Correct 15 ms 3928 KB Output is correct
16 Correct 15 ms 3932 KB Output is correct
17 Correct 17 ms 4188 KB Output is correct
18 Correct 18 ms 4136 KB Output is correct
19 Correct 21 ms 4188 KB Output is correct
20 Correct 20 ms 4188 KB Output is correct