답안 #115838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115838 2019-06-09T08:39:28 Z dolphingarlic 쌀 창고 (IOI11_ricehub) C++14
100 / 100
18 ms 2560 KB
#include "ricehub.h"
#include <algorithm>
 
typedef long long LL;
LL all[100005];
int besthub(int R, int L, int X[], long long B)
{
  for (int i=1; i <= R; i++) all[i] = X[i-1];
  std::sort(all+1,all+R+1);
  LL left = 1, right = 1, mx = -1, totalSum = 0;
  LL median = 1, newmedian;
  LL cost = 0;
  LL mxInterval = -1;
  while (right <= R){
    totalSum += all[right];
    int range = (right-left+1);
    newmedian = (left+right)>>1;
    cost += all[right]-all[median];
    if (newmedian > median){
      while (median < newmedian){
        int change = median - left + 1 - (right - median);
        cost += 1LL * change * (all[median+1]-all[median]);
        median++;
      }
    }
    while (cost > B){
      left++;
      cost -= all[median] - all[left-1];
      while (median < ((left+right)>>1)){
        int change = median - left + 1 - (right - median);
        cost += 1LL * change * (all[median+1]-all[median]);
        median++;
      }
    }
    mxInterval = std::max(mxInterval, right - left + 1);
    right++;
  }
  return mxInterval;
 
  //return R;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:16:9: warning: unused variable 'range' [-Wunused-variable]
     int range = (right-left+1);
         ^~~~~
ricehub.cpp:10:27: warning: unused variable 'mx' [-Wunused-variable]
   LL left = 1, right = 1, mx = -1, totalSum = 0;
                           ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 412 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 612 KB Output is correct
3 Correct 16 ms 2560 KB Output is correct
4 Correct 16 ms 2532 KB Output is correct
5 Correct 8 ms 1252 KB Output is correct
6 Correct 8 ms 1280 KB Output is correct
7 Correct 14 ms 2304 KB Output is correct
8 Correct 14 ms 2304 KB Output is correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 8 ms 1152 KB Output is correct
11 Correct 18 ms 2560 KB Output is correct
12 Correct 18 ms 2560 KB Output is correct
13 Correct 9 ms 1280 KB Output is correct
14 Correct 9 ms 1280 KB Output is correct
15 Correct 14 ms 1920 KB Output is correct
16 Correct 14 ms 1920 KB Output is correct
17 Correct 16 ms 2304 KB Output is correct
18 Correct 16 ms 2304 KB Output is correct
19 Correct 17 ms 2428 KB Output is correct
20 Correct 17 ms 2432 KB Output is correct