답안 #538582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538582 2022-03-17T07:18:46 Z ssense 쌀 창고 (IOI11_ricehub) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define nax 200005
#define pb push_back
#define sc second
#define fr first
#define int long long
#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//ssense

int besthub(int n, int lungime, int a[], ll buget)
{
	vector<int> prefix;
	for(int i = 0; i < n; i++)
	{
		if(i == 0)
		{
			prefix.pb(a[i]);
		}
		else
		{
			prefix.pb(a[i]+prefix.back());
		}
	}
	vector<int> suffix;
	for(int i = n-1; i >= 0; i--)
	{
		if(i == n-1)
		{
			suffix.pb(lungime-a[i]);
		}
		else
		{
			suffix.pb(suffix.back()+lungime-a[i]);
		}
	}
	reverse(all(suffix));
	int ans = 0;
	int l = 1, r = n;
	while(l <= r)
	{
		int mid = l+r>>1;
		deque<int> q;
		for(int i = 0; i < mid; i++)
		{
			q.push_back(i);
		}
		int now = suffix[q.front()]-a[q[mid/2]]*(mid-1-mid/2)+prefix[q.back()]-a[mid/2]*(mid/2);
		ll ansnow = now;
		for(int i = mid; i < n; i++)
		{
			q.pop_front();
			q.push_back(a[i]);
			now = suffix[q.front()]-a[q[mid/2]]*(mid-1-mid/2)+prefix[q.back()]-a[mid/2]*(mid/2);
			ansnow = min(now, ansnow);
		}
		if(ansnow > buget)
		{
			r = mid-1;
		}
		else
		{
			ans = mid;
			l = mid+1;
		}
	}
	return ans;
}

/*
int32_t main(){
	startt
	int t = 1;
	//cin >> t;
	while (t--) {
		int a[5]= {1, 2, 10, 12, 14};
		cout << besthub(5, 20, a, 6);
	}
}


*/

Compilation message

ricehub.cpp: In member function 'void prefix_sum::build(std::vector<long long int>)':
ricehub.cpp:22:667: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 | int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//ssense
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ~~^~~~~~~~~~
ricehub.cpp: In function 'long long int besthub(long long int, long long int, long long int*, ll)':
ricehub.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |   int mid = l+r>>1;
      |             ~^~
/usr/bin/ld: /tmp/ccfhsVqt.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