답안 #294862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294862 2020-09-09T10:05:48 Z shrek12357 쌀 창고 (IOI11_ricehub) C++14
100 / 100
89 ms 1536 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include "ricehub.h"
using namespace std;
 
bool tern(int lo, int hi, long long pre[], long long b, int s1, int s2) {
	if (hi - lo == 1) {
		long long val1 = pre[hi + 1] - pre[hi] - pre[lo + 1] + pre[lo];
		return val1 <= b;
	}
	while (hi >= lo) {
		int mid1 = lo + (hi - lo) / 3;
		int mid2 = hi - (hi - lo) / 3;
		long long val1 = pre[s2 + 1] - pre[mid1 + 1] - (s2- mid1)*(pre[mid1 + 1] - pre[mid1]) + (mid1 - s1)*(pre[mid1 + 1] - pre[mid1]) - pre[mid1] + pre[s1];
		long long val2 = pre[s2 + 1] - pre[mid2 + 1] - (s2 - mid2)*(pre[mid2 + 1] - pre[mid2]) + (mid2 - s1)*(pre[mid2 + 1] - pre[mid2]) - pre[mid2] + pre[s1];
		if (val1 <= b || val2 <= b) {
			return true;
		}
		if (val1 < val2) {
			hi = mid2 - 1;
		}
		else if (val1 > val2) {
			lo = mid1 + 1;
		}
		else {
			lo = mid1 + 1;
			hi = mid2 - 1;
		}
	}
	return false;
}
 
bool check(int r, int mid, long long pre[], long long b) {
	if (mid == 0) {
		return true;
	}
	for (int i = mid - 1; i < r; i++) {
		if (tern(i - (mid - 1), i, pre, b, i - (mid - 1), i)) {
			return true;
		}
	}
	return false;
}
 
int besthub(int r, int l, int x[], long long b) {
	int lo = 0;
	int hi = r;
	int best = 0;
	long long pre[r + 1];
  pre[0] = 0;
	for (int i = 0; i < r; i++) {
		pre[i + 1] = pre[i] + x[i];
	}
	while (hi >= lo) {
		int mid = (hi + lo) / 2;
		if (check(r, mid, pre, b)) {
			best = max(best, mid);
			lo = mid + 1;
		}
		else {
			hi = mid - 1;
		}
	}
	//cout << best << endl;
	return best;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 512 KB Output is correct
2 Correct 16 ms 512 KB Output is correct
3 Correct 17 ms 1536 KB Output is correct
4 Correct 17 ms 1536 KB Output is correct
5 Correct 52 ms 1016 KB Output is correct
6 Correct 58 ms 1016 KB Output is correct
7 Correct 15 ms 1536 KB Output is correct
8 Correct 13 ms 1536 KB Output is correct
9 Correct 86 ms 896 KB Output is correct
10 Correct 88 ms 896 KB Output is correct
11 Correct 17 ms 1536 KB Output is correct
12 Correct 18 ms 1536 KB Output is correct
13 Correct 84 ms 1016 KB Output is correct
14 Correct 89 ms 896 KB Output is correct
15 Correct 24 ms 1152 KB Output is correct
16 Correct 24 ms 1152 KB Output is correct
17 Correct 15 ms 1408 KB Output is correct
18 Correct 18 ms 1408 KB Output is correct
19 Correct 25 ms 1408 KB Output is correct
20 Correct 16 ms 1408 KB Output is correct