답안 #797774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797774 2023-07-29T21:40:03 Z farhan132 쌀 창고 (IOI11_ricehub) C++17
100 / 100
12 ms 2904 KB
#include "ricehub.h"

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert

int besthub(int R, int L, int x[], long long B){

  vector < ll > pref(1, x[0]);
  for(ll i = 1; i < R; i++){
    pref.pb(pref.back() + x[i]);
  }

  ll l = 1, r = R;
  ll ans = 0;

  while(l <= r){
    ll m = (l + r) / 2;
    bool f = 0;
    for(ll i = 0; i + m - 1 < R; i++){
      ll k = (i + i + m - 1) / 2;
      ll cost = (pref[i + m - 1] - x[k] * (i + m - 1 - k)) + (x[k] * (k - i + 1) - pref[k]);
      cost -= pref[k];
      if(i){
        cost += pref[i - 1];
      }
      if(cost <= B){
        ans = m; f = 1;
      }
    }
    if(f){
      l = m + 1;
    }else{
      r = m - 1;
    }
  }

  return ans;
}
# 결과 실행 시간 메모리 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 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 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 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 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 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 316 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 312 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 312 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 312 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 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 468 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 10 ms 2892 KB Output is correct
4 Correct 10 ms 2904 KB Output is correct
5 Correct 6 ms 1488 KB Output is correct
6 Correct 8 ms 1608 KB Output is correct
7 Correct 9 ms 2652 KB Output is correct
8 Correct 9 ms 2748 KB Output is correct
9 Correct 6 ms 1360 KB Output is correct
10 Correct 7 ms 1344 KB Output is correct
11 Correct 11 ms 2872 KB Output is correct
12 Correct 10 ms 2892 KB Output is correct
13 Correct 6 ms 1472 KB Output is correct
14 Correct 7 ms 1468 KB Output is correct
15 Correct 8 ms 2504 KB Output is correct
16 Correct 8 ms 2496 KB Output is correct
17 Correct 9 ms 2724 KB Output is correct
18 Correct 12 ms 2684 KB Output is correct
19 Correct 11 ms 2764 KB Output is correct
20 Correct 10 ms 2736 KB Output is correct