Submission #294794

# Submission time Handle Problem Language Result Execution time Memory
294794 2020-09-09T09:35:27 Z shrek12357 Rice Hub (IOI11_ricehub) C++14
0 / 100
572 ms 1004 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, vector<int> pre, long long b, int s1, int s2) {
	if (hi - lo == 1) {
		int 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;
		int val1 = pre[s2 + 1] - pre[mid1 + 1] - (s2- mid1)*(pre[mid1 + 1] - pre[mid1]) + (mid1 - s1)*(pre[mid1 + 1] - pre[mid1]) - pre[mid1];
		int val2 = pre[s2 + 1] - pre[mid2 + 1] - (s2 - mid2)*(pre[mid2 + 1] - pre[mid2]) + (mid2 - s1)*(pre[mid2 + 1] - pre[mid2]) - pre[mid2];
		if (val1 <= b) {
			return true;
		}
		if (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, vector<int> 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 - 1;
	int best = 0;
	vector<int> pre;
	pre.push_back(0);
	for (int i = 0; i < r; i++) {
		pre.push_back(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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 572 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -