답안 #672117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672117 2022-12-14T19:30:32 Z Hacv16 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "ricehub.h"
 
using namespace std;
 
typedef long long ll;
const ll INF = 5e18 + 15;

int n, x[MAX], px[MAX], L;
ll b;

ll sum(int l, int r){
	return px[r] - (l == 0 ? 0 : px[l - 1]);
}

bool f(ll s){
	for(int l = 0, r = s - 1; r < n; l++, r++){
		int m = (l + r) >> 1; 
		ll cost = 0;

		cost += sum(m + 1, r) - (r - m) * x[m];
		cost += (m - l) * x[m] - sum(l, m - 1);

		if(cost <= b) return true; 
	}

	return false;
}

int besthub(int _n, int _L, int _x[], ll _b){
	n = _n, L = _L, b = _b;

	for(int i = 0; i < n; i++)
		x[i] = _x[i];

	for(int i = 1; i < n; i++)
		px[i] = x[i] + px[i - 1];

	int l = 0, r = n, ans = 0;
 
	while(l <= r){ //bbin na resposta
		int m = (l + r) >> 1;
		if(f(m)) l = m + 1, ans = m;
		else r = m - 1;
	}

	return ans;
}

Compilation message

ricehub.cpp:9:10: error: 'MAX' was not declared in this scope
    9 | int n, x[MAX], px[MAX], L;
      |          ^~~
ricehub.cpp:9:19: error: 'MAX' was not declared in this scope
    9 | int n, x[MAX], px[MAX], L;
      |                   ^~~
ricehub.cpp: In function 'll sum(int, int)':
ricehub.cpp:13:9: error: 'px' was not declared in this scope
   13 |  return px[r] - (l == 0 ? 0 : px[l - 1]);
      |         ^~
ricehub.cpp: In function 'bool f(ll)':
ricehub.cpp:21:37: error: 'x' was not declared in this scope
   21 |   cost += sum(m + 1, r) - (r - m) * x[m];
      |                                     ^
ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:34:3: error: 'x' was not declared in this scope
   34 |   x[i] = _x[i];
      |   ^
ricehub.cpp:37:3: error: 'px' was not declared in this scope; did you mean '_x'?
   37 |   px[i] = x[i] + px[i - 1];
      |   ^~
      |   _x
ricehub.cpp:37:11: error: 'x' was not declared in this scope
   37 |   px[i] = x[i] + px[i - 1];
      |           ^