답안 #684349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684349 2023-01-21T00:14:29 Z speedyArda 쌀 창고 (IOI11_ricehub) C++14
100 / 100
15 ms 2260 KB
#include "ricehub.h"
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B)
{

  ll pref[R];
  ll Big[R];
  pref[0] = 0;
  for(int i = 0; i < R; i++)
  {
      if(i > 0)
        pref[i] = pref[i - 1];
      pref[i] += X[i];
      Big[i] = X[i];
  }

  int left = 1, right = R;
  int ans = 0;
  while(left <= right)
  {
    int m = (left + right) / 2; // We are controlling whether we can get m rices. We use binary search because rice count is monotonic. For example, we can get 6 rices, if we can get 7 rices.
    //int mid = 1;
    bool valid = false;
    for(int i = 0; i + m - 1 < R; i++)
    {
      ll mid = i + (m-1) / 2;
      ll price = Big[mid] * (mid - i + 1) - (pref[mid] - pref[i - 1]);
      price += (pref[i + m - 1] - pref[mid]) - Big[mid] * (i + m - 1 - mid);
      if(price <= B)
        valid = true;
    }

    

    if(valid) {
      left = m + 1;
      ans = m;
    }
    else
      right = m - 1;

  }
  return ans;
}



 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 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 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 312 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 1 ms 212 KB Output is correct
17 Correct 1 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 308 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 316 KB Output is correct
28 Correct 1 ms 308 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 0 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 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 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 0 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 1 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 2 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 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 14 ms 2240 KB Output is correct
4 Correct 11 ms 2260 KB Output is correct
5 Correct 7 ms 1236 KB Output is correct
6 Correct 6 ms 1236 KB Output is correct
7 Correct 13 ms 2164 KB Output is correct
8 Correct 11 ms 2256 KB Output is correct
9 Correct 6 ms 1336 KB Output is correct
10 Correct 6 ms 1264 KB Output is correct
11 Correct 11 ms 2236 KB Output is correct
12 Correct 11 ms 2260 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 6 ms 1176 KB Output is correct
15 Correct 8 ms 1748 KB Output is correct
16 Correct 12 ms 1692 KB Output is correct
17 Correct 15 ms 1932 KB Output is correct
18 Correct 10 ms 2004 KB Output is correct
19 Correct 12 ms 2052 KB Output is correct
20 Correct 15 ms 2096 KB Output is correct