Submission #648954

#TimeUsernameProblemLanguageResultExecution timeMemory
648954ymmThe Big Prize (IOI17_prize)C++17
0 / 100
1 ms424 KiB
#include "prize.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

static const int N = 200'010;
static int cnt[N];
static int *dard = new int[8];

static int test(int *a, int n)
{
	fill(cnt, cnt+n, 0);
	int pos = -1;
	int mx = 1;
	Loop (i,0,n) {
		if (a[i] > n || 1 > a[i])
			return -1;
		if (a[i] > mx)
			mx = a[i];
		if (a[i] == 1)
			pos = i;
		cnt[a[i]-1]++;
	}
	if (cnt[0] != 1)
		return -1;
	Loop (i,0,mx-1)
		if ((ll)cnt[i] * cnt[i] >= cnt[i+1])
			return -1;
	return pos;
}

int find_best(int n)
{
	int rem = n, mx = 0, cnt_nxt = 1;
	while (rem >= cnt_nxt) {
		rem -= cnt_nxt;
		++mx;
		cnt_nxt = cnt_nxt*cnt_nxt + 1;
	}
	int *r = dard;
	int *l = dard;
	cerr << "dard = " << dard << '\n';
	for (;;) {
		if (*r < 1 || mx < *r)
			l = r+1;
		++r;
		if (r - l == n) {
			int tmp = test(l, n);
			if (tmp != -1)
				return tmp;
			++l;
		}
	}
	return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...