답안 #799618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799618 2023-07-31T16:45:23 Z Liudas 쌀 창고 (IOI11_ricehub) C++17
100 / 100
13 ms 4248 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int N, int L, int arr[], long long B){
    vector<long long> brr;
    for(int i = 0; i < N; i ++){
        brr.push_back(arr[i]);
    }
    long long ss = 0, ee = 1e9;
    vector <long long> suf(N + 1), pref(N + 1);
    for(int i = 0; i < N; i ++){
        pref[i+1] = pref[i]+1ll*brr[i];
        suf[N-i-1] = 1ll * suf[N-i]+brr[N-i-1] ;
    }
    int l = 1, r = N + 1;
    while(l + 1 < r){
        int mid = (l + r + 1) / 2;
        int best = 0;
        //cout << "start " << mid << endl;
        for(int i = 0; i < N - mid + 1; i ++){
            long long t = i + mid/ 2, tt = arr[t];
            long long s = suf[i] - suf[t];
            long long p = pref[i + mid] - pref[t];
            long long price = tt * (t - i) - s + p - tt * (i + mid - t);
            if(price <= B){
                best = mid;
                break;
            }
        }
        //cout <<"ans " << best <<  " " << mid << endl;
        if(best == mid){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    return l;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:9:15: warning: unused variable 'ss' [-Wunused-variable]
    9 |     long long ss = 0, ee = 1e9;
      |               ^~
ricehub.cpp:9:23: warning: unused variable 'ee' [-Wunused-variable]
    9 |     long long ss = 0, ee = 1e9;
      |                       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 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 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 312 KB Output is correct
12 Correct 1 ms 312 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 1 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 312 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 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 448 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1088 KB Output is correct
2 Correct 3 ms 1104 KB Output is correct
3 Correct 11 ms 4176 KB Output is correct
4 Correct 12 ms 4140 KB Output is correct
5 Correct 6 ms 2116 KB Output is correct
6 Correct 6 ms 2088 KB Output is correct
7 Correct 11 ms 3928 KB Output is correct
8 Correct 11 ms 3944 KB Output is correct
9 Correct 6 ms 1996 KB Output is correct
10 Correct 6 ms 1996 KB Output is correct
11 Correct 11 ms 4172 KB Output is correct
12 Correct 12 ms 4248 KB Output is correct
13 Correct 6 ms 2124 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 9 ms 3260 KB Output is correct
16 Correct 9 ms 3272 KB Output is correct
17 Correct 13 ms 3912 KB Output is correct
18 Correct 10 ms 3820 KB Output is correct
19 Correct 11 ms 4024 KB Output is correct
20 Correct 11 ms 4040 KB Output is correct