답안 #70651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70651 2018-08-23T08:08:36 Z doowey 쌀 창고 (IOI11_ricehub) C++14
100 / 100
28 ms 14220 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll ab(ll x){
  return max(x, -x);
}

const int N = (int)1e5 + 9;
ll pref[N];

ll rq(int a, int b){
  if(a == 0)
    return pref[b];
  else
    return pref[b] - pref[a - 1];
}

int besthub(int n, int L, int X[], ll B){  
  int l = 1, r = n + 1;
  pref[0] = X[0];
  for(int i = 1;i < n;i ++ )
    pref[i] += pref[i - 1] + X[i];
  int k;
  bool ok;
  int med;
  ll sum = 0;
  ll s1, s2;
  ll D;
  while(l + 1 < r){
    k = (l + r)/2;
    ok = false;
    for(int i = 0;i <= n-k;i ++ ){
      med = k / 2;
      sum = 0;
      s1 = rq(i, i + med - 1);
      s2 = rq(i + med + 1, i + k - 1);
      D = X[i + med];
      sum += (1ll * D * med) - s1;
      sum += s2 - (1ll * D * (k - med - 1));
      if(sum <= B)
        ok = true;
    }
    if(ok)
      l = k;
    else
      r = k;
  }
  return l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 3 ms 528 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 736 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 3 ms 736 KB Output is correct
8 Correct 3 ms 744 KB Output is correct
9 Correct 2 ms 744 KB Output is correct
10 Correct 4 ms 744 KB Output is correct
11 Correct 2 ms 744 KB Output is correct
12 Correct 3 ms 744 KB Output is correct
13 Correct 2 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 3 ms 744 KB Output is correct
16 Correct 3 ms 744 KB Output is correct
17 Correct 3 ms 744 KB Output is correct
18 Correct 2 ms 744 KB Output is correct
19 Correct 3 ms 744 KB Output is correct
20 Correct 3 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 744 KB Output is correct
23 Correct 3 ms 760 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 2 ms 780 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 3 ms 780 KB Output is correct
28 Correct 3 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 780 KB Output is correct
2 Correct 2 ms 780 KB Output is correct
3 Correct 2 ms 780 KB Output is correct
4 Correct 4 ms 780 KB Output is correct
5 Correct 2 ms 780 KB Output is correct
6 Correct 4 ms 780 KB Output is correct
7 Correct 4 ms 780 KB Output is correct
8 Correct 4 ms 780 KB Output is correct
9 Correct 2 ms 780 KB Output is correct
10 Correct 3 ms 780 KB Output is correct
11 Correct 3 ms 780 KB Output is correct
12 Correct 4 ms 780 KB Output is correct
13 Correct 4 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 4 ms 780 KB Output is correct
16 Correct 3 ms 780 KB Output is correct
17 Correct 4 ms 780 KB Output is correct
18 Correct 2 ms 780 KB Output is correct
19 Correct 3 ms 780 KB Output is correct
20 Correct 3 ms 780 KB Output is correct
21 Correct 5 ms 780 KB Output is correct
22 Correct 6 ms 780 KB Output is correct
23 Correct 3 ms 780 KB Output is correct
24 Correct 4 ms 780 KB Output is correct
25 Correct 3 ms 780 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 3 ms 816 KB Output is correct
28 Correct 4 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 888 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 23 ms 1912 KB Output is correct
4 Correct 22 ms 2972 KB Output is correct
5 Correct 12 ms 2972 KB Output is correct
6 Correct 14 ms 3156 KB Output is correct
7 Correct 19 ms 4488 KB Output is correct
8 Correct 18 ms 5308 KB Output is correct
9 Correct 11 ms 5308 KB Output is correct
10 Correct 19 ms 5308 KB Output is correct
11 Correct 24 ms 6912 KB Output is correct
12 Correct 24 ms 7976 KB Output is correct
13 Correct 13 ms 7976 KB Output is correct
14 Correct 13 ms 8148 KB Output is correct
15 Correct 20 ms 9176 KB Output is correct
16 Correct 22 ms 10092 KB Output is correct
17 Correct 28 ms 11188 KB Output is correct
18 Correct 20 ms 12128 KB Output is correct
19 Correct 21 ms 13212 KB Output is correct
20 Correct 25 ms 14220 KB Output is correct