답안 #897513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897513 2024-01-03T10:34:30 Z ThylOne 쌀 창고 (IOI11_ricehub) C++14
17 / 100
1000 ms 3164 KB
#include "ricehub.h"
#include<bits/stdc++.h>

using namespace std;
vector<int> pos;
long long budget;
int limit;
bool existWithT(int T){
  long long sum = 0;

  for(int i=0;i<T;i++)
    sum+=pos[i];
  
  auto computeScore = [&](int x,int l,int r){
    long long re = 0;
    for(int i = l;i<=r;i++){
      re+=abs(x-pos[i]);
    }
    return re;
  };
  auto findGoodSegment = [&](int l,int r){
    long long bestInf = double(sum)/double(T);
    long long bestSup = ceil(double(sum)/double(T));
    
    if(computeScore(bestInf,l,r)<=budget)return true;
    if(computeScore(bestSup,l,r)<=budget)return true;
    return false;
  };
  if(findGoodSegment(0,T-1))return true;
  for(int right=T;right<pos.size();right++){
    sum-=pos[right-T];
    sum+=pos[right];
    if(findGoodSegment(right-T+1,right))return true;
  }
  return false;
}
int besthub(int R, int L, int X[], long long B)
{

  budget = B;
  pos.resize(R);
  limit = L;
  for(int i = 0;i<R;i++){
    pos[i] = X[i];
  }
  sort(pos.begin(),pos.end());
  int low = 1;
  int high = R;
  while ((high-low)>1){
    int mid = (low+high)/2;
    if(existWithT(mid)){
      low = mid;
    }else{
      high = mid;
    }
  }
  if(existWithT(high)){
    return high;
  }else{
    return low;
  }

}

Compilation message

ricehub.cpp: In function 'bool existWithT(int)':
ricehub.cpp:30:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int right=T;right<pos.size();right++){
      |                   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 440 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 1 ms 344 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 30 ms 484 KB Output is correct
22 Correct 32 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 420 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 110 ms 500 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 420 ms 348 KB Output is correct
2 Correct 434 ms 592 KB Output is correct
3 Correct 12 ms 2904 KB Output is correct
4 Correct 12 ms 2908 KB Output is correct
5 Execution timed out 1087 ms 3164 KB Time limit exceeded
6 Halted 0 ms 0 KB -