답안 #551239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551239 2022-04-20T06:17:02 Z AriaH 쌀 창고 (IOI11_ricehub) C++17
100 / 100
17 ms 1496 KB
#include "ricehub.h"

/* Im the best and i work like that */

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;

const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;

ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }

mt19937 rng(time(nullptr));

int n;

ll ps[N];

inline ll get(int l, int r)
{
  return ps[r] - (l <= 0? 0 : ps[l - 1]);
}

int besthub(int _n, int L, int X[], ll B)
{
  n = _n;
  for(int i = 0; i < n; i ++)
  {
    ps[i] += X[i];
    ps[i + 1] += ps[i];
  }
  int ans = 1;
  for(int i = 0; i < n; i ++)
  {
    int d = 0, up = min(i, n - 1 - i) + 1;
    while(up - d > 1)
    {
      int mid = (up + d) >> 1;
      ll cu = -get(i - mid, i) + get(i, i + mid);
      if(cu <= B)
      {
        d = mid;
        ans = max(ans, d << 1 | 1);
        if(i + mid + 1 < n && cu + X[i + mid + 1] - X[i] <= B)
        {
          ans = max(ans, d * 2 + 2);
        }
      }
      else up = mid;
    }
    if(i + 1 < n && X[i + 1] - X[i] <= B) ans = max(ans, 2);
  }
  return ans;
}

/* check corner case(n = 1?), watch for negetive index or overflow */
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 0 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 212 KB Output is correct
12 Correct 1 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 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 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 0 ms 212 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 0 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 0 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 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 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 1 ms 212 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 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 1 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 2 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 3 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 16 ms 1492 KB Output is correct
4 Correct 16 ms 1492 KB Output is correct
5 Correct 6 ms 900 KB Output is correct
6 Correct 7 ms 884 KB Output is correct
7 Correct 16 ms 1492 KB Output is correct
8 Correct 17 ms 1496 KB Output is correct
9 Correct 9 ms 868 KB Output is correct
10 Correct 7 ms 852 KB Output is correct
11 Correct 17 ms 1488 KB Output is correct
12 Correct 17 ms 1488 KB Output is correct
13 Correct 7 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 12 ms 1108 KB Output is correct
16 Correct 11 ms 1108 KB Output is correct
17 Correct 15 ms 1288 KB Output is correct
18 Correct 15 ms 1364 KB Output is correct
19 Correct 14 ms 1364 KB Output is correct
20 Correct 16 ms 1364 KB Output is correct