답안 #1115165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115165 2024-11-20T07:30:25 Z raspy 쌀 창고 (IOI11_ricehub) C++17
100 / 100
23 ms 5984 KB
#include <bits/stdc++.h>
#include "ricehub.h"

#define ll long long
#define vi vector<ll>
#define ii pair<ll, ll>
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define P 31
#define mod 1'000'000'007
#define inf 1'000'000'000'000'000'0
#define pb push_back
#define str string
#define sz(x) (x).size()
#define vvi vector<vi>
#define fun function
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define file freopen("problemname.in", "r", stdin); freopen("pr.out", "w", stdout);
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

using namespace std;
template <class T, int SZ> using arr = array<T, SZ>;

int besthub(int r, int l, int x[], long long b)
{
	vi kum(r+1);
	vi kum1(r+1);
	for (ll i = 1; i <= r; i++)
		kum[i] = kum[i-1]+x[i-1];
	for (ll i = r-1; i >= 0; i--)
		kum1[i] = kum1[i+1]+l-x[i];
	deque<ll> dq;
	ll rez = 0;
	auto calcprice = [&dq, &kum, &kum1, &x, &l]() -> ll
	{
		ll med = dq[dq.size()/2];
		ll std = dq.size()-dq.size()/2-1;
		ll stl = dq.size()/2;
		ll tr = kum[dq.back()+1]-kum[med+1]-x[med]*std;
		tr = tr+kum1[dq[0]]-kum1[med]-(l-x[med])*stl;
		return tr;
	};
	for (ll i = 0; i < r; i++)
	{
		dq.pb(i);
		ll trc = calcprice();
		while (trc > b)
		{
			dq.pop_front();
			trc = calcprice();
		}
		rez = max(rez, (ll)dq.size());
	}
	return rez;
}






























// #include <stdio.h>
// #include <stdlib.h>

// #define MAX_R  1000000

// static int R, L;
// static long long B;
// static int X[MAX_R];
// static int solution;

// inline 
// void my_assert(int e) {if (!e) abort();}

// static void read_input()
// {
//   int i;
//   my_assert(3==scanf("%d %d %lld",&R,&L,&B));
//   for(i=0; i<R; i++)
//     my_assert(1==scanf("%d",&X[i]));
//   my_assert(1==scanf("%d",&solution));
// }

// int main()
// {
//   int ans;
//   read_input();
//   ans = besthub(R,L,X,B);
//   if(ans==solution)
//     printf("Correct.\n");
//   else
//     printf("Incorrect.  Returned %d instead of %d.\n",ans,solution);

//   return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 508 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 20 ms 4956 KB Output is correct
4 Correct 13 ms 4944 KB Output is correct
5 Correct 6 ms 3664 KB Output is correct
6 Correct 7 ms 3832 KB Output is correct
7 Correct 12 ms 5712 KB Output is correct
8 Correct 16 ms 5688 KB Output is correct
9 Correct 11 ms 3664 KB Output is correct
10 Correct 6 ms 3664 KB Output is correct
11 Correct 23 ms 5984 KB Output is correct
12 Correct 17 ms 5968 KB Output is correct
13 Correct 7 ms 3664 KB Output is correct
14 Correct 7 ms 3664 KB Output is correct
15 Correct 11 ms 5200 KB Output is correct
16 Correct 10 ms 5200 KB Output is correct
17 Correct 12 ms 5712 KB Output is correct
18 Correct 14 ms 5800 KB Output is correct
19 Correct 12 ms 5712 KB Output is correct
20 Correct 14 ms 5712 KB Output is correct