답안 #378060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378060 2021-03-15T22:12:04 Z MilosMilutinovic 쌀 창고 (IOI11_ricehub) C++14
100 / 100
29 ms 2688 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int n, int len, int* a, long long b) {
  vector<long long> pref(n);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      pref[i] = a[i];
    } else {
      pref[i] = pref[i - 1] + a[i];
    }
  }
  auto Can = [&](int l, int r) {
    int mid = l + r >> 1;
    long long ll = (long long) a[mid] * (mid - l + 1) - (pref[mid] - (l == 0 ? 0LL: pref[l - 1]));
    long long rr = pref[r] - pref[mid] - (long long) a[mid] * (r - mid);
    return ll + rr <= b;
  };
  int ans = 1;
  for (int i = 0; i < n; i++) {
    int bot = i, top = n - 1, mx = 0;
    while (bot <= top) {
      int mid = bot + top >> 1;
      if (Can(i, mid)) {
        mx = mid - i + 1;
        bot = mid + 1;
      } else {
        top = mid - 1;
      }
    }
    ans = max(ans, mx);
  }
  return ans;
}

Compilation message

ricehub.cpp: In lambda function:
ricehub.cpp:16:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |     int mid = l + r >> 1;
      |               ~~^~~
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:25:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |       int mid = bot + top >> 1;
      |                 ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 748 KB Output is correct
2 Correct 4 ms 748 KB Output is correct
3 Correct 23 ms 2540 KB Output is correct
4 Correct 22 ms 2540 KB Output is correct
5 Correct 14 ms 1260 KB Output is correct
6 Correct 10 ms 1260 KB Output is correct
7 Correct 20 ms 2284 KB Output is correct
8 Correct 26 ms 2284 KB Output is correct
9 Correct 11 ms 1260 KB Output is correct
10 Correct 11 ms 1132 KB Output is correct
11 Correct 22 ms 2540 KB Output is correct
12 Correct 29 ms 2688 KB Output is correct
13 Correct 13 ms 1388 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 17 ms 2028 KB Output is correct
16 Correct 16 ms 2028 KB Output is correct
17 Correct 19 ms 2284 KB Output is correct
18 Correct 20 ms 2284 KB Output is correct
19 Correct 26 ms 2412 KB Output is correct
20 Correct 25 ms 2412 KB Output is correct