답안 #563300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563300 2022-05-16T20:19:34 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] + dpref[i];
  }
  auto dist = [&](int l,int r){
	 return pref[r] * (r - l + 1) - dpref[r] + 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]<<" "<<pref[mid]<<'\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:17:13: warning: unused variable 'cost' [-Wunused-variable]
   17 |   long long cost = B;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 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 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 -