답안 #379344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379344 2021-03-18T02:30:05 Z pavement 쌀 창고 (IOI11_ricehub) C++17
100 / 100
17 ms 2540 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll P[100005];

int besthub(int R, int L, int X[], ll B) {
	int lo = 1, hi = R, mid, rh, ans;
	P[0] = (ll)X[0];
	for (int i = 1; i < R; i++)
		P[i] = P[i - 1] + (ll)X[i];
	while (lo <= hi) {
		bool yes = 0;
		mid = (lo + hi) >> 1;
		for (int i = 0; i <= R - mid; i++) {
			rh = i + mid / 2;
			ll res = (ll)(rh - i + 1) * (ll)X[rh] - (ll)P[rh] + (ll)(i ? P[i - 1] : 0) + (ll)P[i + mid - 1] - (ll)(rh ? P[rh - 1] : 0) - (ll)(i + mid - rh) * (ll)X[rh];
			if (res <= B) {
				yes = 1;
				break;
			}
		}
		if (yes) ans = mid, lo = mid + 1;
		else hi = mid - 1;
	}
	return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:53:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 748 KB Output is correct
2 Correct 5 ms 748 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 17 ms 2540 KB Output is correct
5 Correct 11 ms 1260 KB Output is correct
6 Correct 8 ms 1260 KB Output is correct
7 Correct 15 ms 2284 KB Output is correct
8 Correct 15 ms 2412 KB Output is correct
9 Correct 8 ms 1260 KB Output is correct
10 Correct 8 ms 1260 KB Output is correct
11 Correct 17 ms 2540 KB Output is correct
12 Correct 16 ms 2540 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1260 KB Output is correct
15 Correct 17 ms 2028 KB Output is correct
16 Correct 14 ms 2028 KB Output is correct
17 Correct 15 ms 2284 KB Output is correct
18 Correct 15 ms 2284 KB Output is correct
19 Correct 16 ms 2412 KB Output is correct
20 Correct 15 ms 2412 KB Output is correct