답안 #538615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538615 2022-03-17T08:53:16 Z ssense 쌀 창고 (IOI11_ricehub) C++14
100 / 100
21 ms 2944 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

ll query(int l, int r, vector<ll>& p) {
	return p[r] - (l ? p[l - 1] : 0);
}

bool get(int val, vector<int>& x, ll b) {
	int n = x.size();
	vector<ll> p(n);
	for(int i = 0;i < n; ++i) {
		p[i] = (i ? p[i - 1] : 0) + x[i];
	}
 
	for(int i = 0; i + val - 1 < n; ++i) {
		ll med = (i + val / 2);
		ll calc = 1LL * x[med] * (i + val / 2 - i + 1) - query(i, i + val / 2, p);
		if(calc > b) continue;
		calc += 1LL * query(i + val / 2, i + val - 1, p) - 1LL * x[med] * (i + val - 1 - i - val / 2 + 1);
		if(calc <= b) return true;
	}
	return false;
}
 

int besthub(int n, int lungime, int a[], long long buget)
{
	vector<int> x(n);
	for(int i = 0; i < n; i++)
	{
		x[i] = a[i];
	}
	ll ans = 0;
	ll l = 1, r = n;
	while(l <= r)
	{
		ll mid = l+r>>1;
		if(!get(mid, x, 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:56:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |   ll mid = l+r>>1;
      |            ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 5 ms 692 KB Output is correct
3 Correct 21 ms 2848 KB Output is correct
4 Correct 14 ms 2848 KB Output is correct
5 Correct 7 ms 1332 KB Output is correct
6 Correct 7 ms 1328 KB Output is correct
7 Correct 11 ms 2532 KB Output is correct
8 Correct 11 ms 2628 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 7 ms 1364 KB Output is correct
11 Correct 15 ms 2836 KB Output is correct
12 Correct 14 ms 2944 KB Output is correct
13 Correct 9 ms 1396 KB Output is correct
14 Correct 7 ms 1492 KB Output is correct
15 Correct 10 ms 2260 KB Output is correct
16 Correct 10 ms 2260 KB Output is correct
17 Correct 14 ms 2656 KB Output is correct
18 Correct 12 ms 2620 KB Output is correct
19 Correct 12 ms 2720 KB Output is correct
20 Correct 13 ms 2756 KB Output is correct