Submission #64618

# Submission time Handle Problem Language Result Execution time Memory
64618 2018-08-05T05:02:40 Z nvmdava The Big Prize (IOI17_prize) C++17
0 / 100
8 ms 5312 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
 
/*
 
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;
 
vector<int> ask(int i) {
	query_count++;
	if(query_count > max_q) {
		cerr << "Query limit exceeded" << endl;
		exit(0);
	}
 
	if(i < 0 || i >= n) {
		cerr << "Bad index: " << i << endl;
		exit(0);
	}
 
	vector<int> res(2);
	res[0] = rank_count[g[i] - 1][i + 1];
	res[1] = rank_count[g[i] - 1][n] - res[0];
	return res;
}
*/
 
 
 
vector<int> ans[200001];
map<int, set<int> > v;
int L, R;
int find_best(int n) {
	L = 0;
	R = n - 1;
	queue<pair<int, int> > q;
	q.push(make_pair(L, R));
	int l, r, m;
	while(!q.empty()){
		l = q.front().first;
		r = q.front().second;
		q.pop();
		if(L > r ||  l > R || l >= r){
			continue;
		}
		m = (l + r) >> 1;
		if(ans[m].size() == 0)ans[m] = ask(m);
		if(ans[m][0] + ans[m][1] == 0){
			return m;
		}
		
		v[ans[m][0] + ans[m][1]].insert(m);
		auto it = v.find(ans[m][0] + ans[m][1]);
		auto loc = it -> second.find(m);
		bool in = 0;
		auto tmp = loc;
		while(tmp != it -> second.begin()){
			if(ans[m][0] != ans[*tmp][0]){
				in = 1;
				tmp++;
				q.push(make_pair(l, *tmp));
				break;
			}
			tmp--;
			
		}
		if(in == 0){
			tmp = it->second.begin();
			
			q.push(make_pair(l, *tmp - 1));
		} else {
			in = 0;
		}
		tmp = loc;
		while(tmp != it -> second.end()){
			if(ans[m][0] != ans[*tmp][0]){
				in = 1;
				tmp--;
				q.push(make_pair(*tmp, r));
				break;
			}
			tmp++;
		}
		if(in == 0){
			tmp = it->second.end();
			tmp--;
			q.push(make_pair(*tmp + 1, r));
		}
	}
}
 
 
/*
 
 
 
 
 
int main() {
	cin >> n;
 
	g.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> g[i];
		if(g[i] < 1) {
			cerr << "Invalid rank " << g[i] << " at index " << i << endl;
			exit(0);
		}
	}
 
	int max_rank = *max_element(g.begin(), g.end());
 
	rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
	for(int r = 0; r <= max_rank; r++) {
		for(int i = 1; i <= n; i++) {
			rank_count[r][i] = rank_count[r][i - 1];
			if(g[i - 1] == r)
			  rank_count[r][i]++;
		}
	}
 
	for(int i = 0; i <= n; i++)
		for(int r = 1; r <= max_rank; r++)
			rank_count[r][i] += rank_count[r - 1][i];
 
	int res = find_best(n);
	cout << res << endl << "Query count: " << query_count << endl;
 
	return 0;
}*/

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:94:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 8 ms 5048 KB Output is correct
3 Correct 6 ms 5048 KB Output is correct
4 Incorrect 6 ms 5264 KB answer is not correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5264 KB Output is correct
2 Correct 7 ms 5264 KB Output is correct
3 Correct 7 ms 5312 KB Output is correct
4 Incorrect 8 ms 5312 KB answer is not correct
5 Halted 0 ms 0 KB -