답안 #234067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234067 2020-05-22T23:15:28 Z DanerZein 쌀 창고 (IOI11_ricehub) C++14
100 / 100
123 ms 1912 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long ma=-1;
int besthub(int R, int L, int X[], long long B){
    if(R<=500){ ma=-1;
  for(int i=0;i<R;i++){
    for(int j=i;j<R;j++){
      // cout<<i<<" "<<j<<endl;
      vector<int>rp;
      for(int k=i;k<=j;k++){
	rp.push_back(X[k]);
      }
      int mi=(i+j)/2;
      mi=X[mi];
      //  cout<<i<<" "<<j<<endl;
      bool sw=0;
      long long b=B;
      for(int k=0;k<rp.size();k++){
	
	b-=abs(mi-rp[k]);
	if(b<0){
	  sw=1;
	  break;
	}
	//c++;
      }
      if(sw==0){
	//	cout<<i<<" "<<j<<" "<<rp.size()<<endl;
	long long tam=rp.size();
	ma=max(ma,tam);
      }
    }
  }
  return ma;
}
  else{
  vector<ll>T;
  T.push_back(0);
  for(int i=0;i<R;i++){
    T.push_back(X[i]+T[T.size()-1]);
  }
  for(int i=0;i<R;i++){
    int l,r;
    l=i+1;
    r=R;
    while(true){
      
      ll mi=l+(r-l)/2;
      //cout<<l<<" "<<r<<" "<<ma<<" "<<mi<<endl;
      if(l>r) break;
      ll p=(i+mi)/2;
      if((p-i)*X[p]-(T[p]-T[i])+(T[mi+1]-T[p+1])-(mi-p)*X[p]<=B){
	ma=max(ma,(ll)(mi-i)+1);
	if(l==mi) break;
	l=mi;
      }
      else{
	if(r==mi) break;
	r=mi;
      }
    }
  }
  return ma;
  }
}
/*
#define MAX_R  1000000

static int R, L;
static long long B;
static int X[MAX_R];
static int solution;

inline 
void my_assert(int e) {if (!e) abort();}

static void read_input()
{
  int i;
  my_assert(3==scanf("%d %d %lld",&R,&L,&B));
  for(i=0; i<R; i++)
    my_assert(1==scanf("%d",&X[i]));
  my_assert(1==scanf("%d",&solution));
}

int main()
{
  int ans;
  read_input();
  ans = besthub(R,L,X,B);
  if(ans==solution)
    printf("Correct.\n");
  else
    printf("Incorrect.  Returned %d instead of %d.\n",ans,solution);

  return 0;
}
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int k=0;k<rp.size();k++){
                   ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 6 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 6 ms 256 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 97 ms 256 KB Output is correct
22 Correct 99 ms 256 KB Output is correct
23 Correct 118 ms 376 KB Output is correct
24 Correct 121 ms 256 KB Output is correct
25 Correct 123 ms 256 KB Output is correct
26 Correct 117 ms 256 KB Output is correct
27 Correct 112 ms 256 KB Output is correct
28 Correct 113 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 256 KB Output is correct
2 Correct 11 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 95 ms 256 KB Output is correct
6 Correct 99 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 101 ms 376 KB Output is correct
10 Correct 102 ms 376 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 110 ms 256 KB Output is correct
16 Correct 108 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 768 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 27 ms 1912 KB Output is correct
4 Correct 29 ms 1912 KB Output is correct
5 Correct 15 ms 1148 KB Output is correct
6 Correct 15 ms 1148 KB Output is correct
7 Correct 27 ms 1912 KB Output is correct
8 Correct 25 ms 1912 KB Output is correct
9 Correct 15 ms 1148 KB Output is correct
10 Correct 16 ms 1148 KB Output is correct
11 Correct 30 ms 1912 KB Output is correct
12 Correct 30 ms 1912 KB Output is correct
13 Correct 15 ms 1148 KB Output is correct
14 Correct 15 ms 1148 KB Output is correct
15 Correct 23 ms 1784 KB Output is correct
16 Correct 23 ms 1784 KB Output is correct
17 Correct 27 ms 1784 KB Output is correct
18 Correct 27 ms 1912 KB Output is correct
19 Correct 28 ms 1912 KB Output is correct
20 Correct 29 ms 1912 KB Output is correct