답안 #884215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884215 2023-12-06T18:50:07 Z TahirAliyev 쌀 창고 (IOI11_ricehub) C++17
100 / 100
10 ms 3676 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define oo 1e18
#define all(v) v.begin(), v.end()

const int MAX = 1e5 + 5;
int n;
ll arr[MAX];
ll pre[MAX];

signed besthub(int R, int L, int X[], long long B)
{
    n = R;
    for(int i = 1; i <= n; i++){
        arr[i] = X[i - 1];
        pre[i] = pre[i - 1] + arr[i];
    }
    ll l = 1, r = n;
    ll ans = 1;
    while(l <= r){
        ll len = (l + r) / 2;
        ll cost = oo;
        for(int s = 1; s <= n - len + 1; s++){
            ll f = s + len - 1;
            ll med = (s + f) / 2;
            cost = min(cost, (arr[med] * (med - s + 1)) - (pre[med] - pre[s - 1]) 
                            - (arr[med] * (f - med)) + (pre[f] - pre[med]));
        }
        if(cost <= B){
            ans = len;
            l = len + 1;
        }
        else{
            r = len - 1;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2456 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2552 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2492 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2492 KB Output is correct
21 Correct 0 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2552 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2700 KB Output is correct
3 Correct 9 ms 3676 KB Output is correct
4 Correct 9 ms 3556 KB Output is correct
5 Correct 7 ms 2908 KB Output is correct
6 Correct 5 ms 2832 KB Output is correct
7 Correct 8 ms 3420 KB Output is correct
8 Correct 8 ms 3420 KB Output is correct
9 Correct 6 ms 2908 KB Output is correct
10 Correct 6 ms 3112 KB Output is correct
11 Correct 9 ms 3672 KB Output is correct
12 Correct 10 ms 3676 KB Output is correct
13 Correct 6 ms 2908 KB Output is correct
14 Correct 6 ms 2908 KB Output is correct
15 Correct 7 ms 3464 KB Output is correct
16 Correct 8 ms 3416 KB Output is correct
17 Correct 8 ms 3524 KB Output is correct
18 Correct 10 ms 3528 KB Output is correct
19 Correct 9 ms 3676 KB Output is correct
20 Correct 9 ms 3628 KB Output is correct