답안 #538590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538590 2022-03-17T07:35:12 Z ssense 쌀 창고 (IOI11_ricehub) C++14
0 / 100
4 ms 1620 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 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[], long long buget)
{
	vector<ll> prefix;
	for(int i = 0; i < n; i++)
	{
		if(i == 0)
		{
			prefix.pb(a[i]);
		}
		else
		{
			prefix.pb(a[i]+prefix.back());
		}
	}
	vector<ll> 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));
	ll ans = 0;
	ll l = 1, r = n;
	while(l <= r)
	{
		ll mid = l+r>>1;
		deque<int> q;
		for(int i = 0; i < mid; i++)
		{
			q.push_back(i);
		}
		ll 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<int>)':
ricehub.cpp:21:667: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 | 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 'int besthub(int, int, int*, long long int)':
ricehub.cpp:54:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |   ll mid = l+r>>1;
      |            ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -