답안 #563306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563306 2022-05-16T20:32:33 Z 1ne 쌀 창고 (IOI11_ricehub) C++14
0 / 100
3 ms 596 KB
#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
  int ans = 0;
  vector<int64_t>pref(R + 1,0),dpref(R + 1,0);
  for (int i = 0 ;i<R - 1;++i){
	  pref[i + 1] = pref[i] + (X[i + 1] - X[i]);
	  dpref[i + 1] = pref[i + 1] + dpref[i];
  }
  //for (int i = 0;i<R;++i)cout<<dpref[i]<<" ";
  //cout<<'\n';
  //1 3 18 - 
  auto dist = [&](int l,int r){
	 return pref[r] * (r - l) - dpref[max(0,r - 1)] + dpref[max(0,l - 1)];
  };
  for (int i = 0;i<R;++i){
		int l = 0;
		long long cost = B;
		int left = 0,right = i;
		while(left<=right){
			int mid = (left + right)>>1;
			//cout<<mid<<" "<<i<<" "<<dist(mid,i)<< " "<<pref[i]<<" "<<dpref[max(0,i - 1)]<<" "<< dpref[max(0,mid - 1)]<<'\n';
			if (dist(mid,i)<=B){
				l = mid;
				right = mid - 1;
			} 
			else left = mid + 1;
		}
		ans = max(ans,i - l + 1);
		
		//(X[r] - X[r - 1])*(r - l) + (X[r - 1] - X[r - 2]) * (r - l - 1) ...  == pref[r] - pref[l] + pref[r] - pref[l + 1] .. pref[r] - pref[r - 1]
		//1 3 , (X[5] - X[4])*5 + (X[4] - X[3]) * 4 + (X[3] - X[2]) * 3  + (X[2] - X[1])*2 + (X[1] - X[0])*1
		// (X[5] - [4]) * 1 + (X[4] - X[3]) * 2 + (X[3] - X[2]) * 3 + (X[2] - X[1])*4 + (X[1] - X[0])*5
  }
  return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:20:13: warning: unused variable 'cost' [-Wunused-variable]
   20 |   long long cost = B;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -