답안 #478835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478835 2021-10-08T15:03:22 Z nicetrymaza 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define add push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define filein(a) freopen(a, "r", stdin);
#define fileout(a) freopen(a, "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
 
const int N = 100011;
const ll MOD = 1000000007;

int besthub(int R, ll L, ll X[], ll B) {
	if(R == 1) return 1;
	ll a[N], b[N];
	a[0] = 0;
	b[R + 1] = 0;
	for(int i = 1; i <= R; i++) {
		if(i == 1) a[i] = 0;
		else a[i] = a[i - 1] + (i - 1) * (X[i - 1] - X[i - 2]);
	}
	for(int i = R; i >= 1; i--) {
		if(i == R) b[i] = 0;
		else b[i] = b[i + 1] + (R - i) * (X[i] - X[i - 1]);
	}
	int l = 1, r = R, ans = 1;
	while(l <= r) {
		bool yes = true;
		int m = (l + r) / 2;
		int mi = m / 2, mj = (m + 1) / 2;
		for(int i = mi; (i + mj) < R; i++) {
			if(i == 0) {
				if(B >= (X[i + 1] - X[i])) {
					ans = 2;
					l = m + 1;
					i = R;
					yes = false;
				}
			}
			else {
				ll c1 = a[i] - a[i - mi];
				ll c2 = a[i + 2] - a[i + 2 + mj];
				if(mi != 0) c1 += (X[i] - X[i - 1]) * mi;
				c2 += (X[i + 1] - X[i]) * mj;
				ll c3 = c1 + c2;
				if(c3 <= B) {
					ans = m;
					l = m + 1;
					i = R;
					yes = false;
				}
			}
		}
		if(yes) r = m - 1;
	}
	return ans;
}

int main() {
	fastio;
	ll R, L, X[N], B;
	cin >> R >> L;
	for(int i = 0; i < R; i++) cin >> X[i];
	cin >> B;
	cout << besthub(R, L, X, B);
	return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccJtodzI.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccZQyRIJ.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccJtodzI.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status