Submission #166375

# Submission time Handle Problem Language Result Execution time Memory
166375 2019-12-01T19:50:57 Z qkxwsm Koala Game (APIO17_koala) C++14
70 / 100
70 ms 528 KB
#include "koala.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

random_device rd;
mt19937 rng(rd());

template<class T>
T randomize(T mod)
{
	return uniform_int_distribution<T>(0, mod - 1)(rng);
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= b; i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) x.begin(), x.end()
#define INF 1000000007
#define LLINF 2696969696969696969

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, Q;
vi arr, rec;
vi test = {8, 4, 2, 1};
vi ans;

vi ask(vi s)
{
	int tmp[100], tmp1[100];
	FOR(i, 0, N)
	{
		tmp[i] = s[i];
	}
	playRound(tmp, tmp1);
	FOR(i, 0, N)
	{
		s[i] = tmp1[i];
	}
	return s;
}

int minValue(int n, int q)
{
	N = n; Q = q; arr.resize(N);
	arr[0] = 1;
	rec = ask(arr);
	FOR(i, 1, N)
	{
		if (rec[i] == 0) return i;
	}
    return 0;
}

int maxValue(int n, int q)
{
    N = n; Q = q; arr.resize(N);
	vi cands;
	FOR(i, 0, N) cands.PB(i);
	while(SZ(cands) > 1)
	{
		vi tmp;
		FOR(i, 0, N) arr[i] = 0;
		for (int x : cands) arr[x] = N / SZ(cands);
		rec = ask(arr);
		FOR(i, 0, N)
		{
			if (rec[i] > (N / SZ(cands))) tmp.PB(i);
		}
		cands = tmp;
		// for (int x : cands)
		// {
		// 	cerr << x << ' ';
		// }
		// cerr << endl;
	}
	return cands[0];
}

bool cmp(int i, int j)
{
	if (i == j) return false;
	FOR(k, 0, N) arr[k] = 0;
	int lo = 1, hi = 9;
	while(true)
	{
		int mid = (hi + lo) >> 1;
		arr[i] = mid; arr[j] = mid;
		rec = ask(arr);
		if (rec[i] > mid && rec[j] <= mid) return false;
		if (rec[i] <= mid && rec[j] > mid) return true;
		if (rec[i] > mid && rec[j] > mid) lo = mid + 1;
		else hi = mid - 1;
	}
	// return false;
}

int greaterValue(int n, int q)
{
	N = n; Q = q; arr.resize(N);
	//say you put x on each.
	//they will put 98 on thhe other guys and 0 on both of you.
	//they will put 99-x on the other guys and x+1 on one of you. it's a sacrifice of 1+2+...x-1. for you. but the next one needs x....2x-2
	//they will put 98-2x on everybody else and x+1 on both of you.
	//they put it on the more expensive of you two.
	return cmp(0, 1);
}

bool cmp1(int a, int b)
{
	//return true if a < b
	FOR(i, 0, N)
	{
		arr[i] = 0;
	}
	arr[a] = N; arr[b] = N;
	rec = ask(arr);
	return (rec[b] > N);
}
vi ord[300];
void build4(int w, int L, int R)
{
	ord[w].clear();
	if (L == R)
	{
		ord[w].PB(L);
		return;
	}
	int mid = (L + R) >> 1;
	build4(w << 1, L, mid);
	build4(w << 1 | 1, mid + 1, R);
}
void solve4(int w, int L, int R)
{
	if (L == R) return;
	int mid = (L + R) >> 1;
	solve4(w << 1, L, mid);
	solve4(w << 1 | 1, mid + 1, R);
	int lt = 0, rt = 0;
	while(lt < SZ(ord[w << 1]) || rt < SZ(ord[w << 1 | 1]))
	{
		if (rt == SZ(ord[w << 1 | 1]) || ((lt != SZ(ord[w << 1]) && cmp1(ord[w << 1][lt], ord[w << 1 | 1][rt]))))
		{
			ord[w].PB(ord[w << 1][lt]);
			lt++;
		}
		else
		{
			ord[w].PB(ord[w << 1 | 1][rt]);
			rt++;
		}
	}
}
void allValues(int n, int q, int *res)
{
    N = n; Q = q; arr.resize(N); ans.resize(N);
	if (Q == 2 * N)
	{
		build4(1, 0, N - 1);
		solve4(1, 0, N - 1);
		FOR(i, 0, SZ(ord[1]))
		{
			ans[ord[1][i]] = i + 1;
		}
	}
	else
	{
		FOR(i, 0, N) arr[i] = 1;
		rec = ask(arr);
		vi upper, lower;
		FOR(i, 0, N)
		{
			if (rec[i]) upper.PB(i);
			else lower.PB(i);
		}
		FOR(i, 0, SZ(upper))
		{
			swap(upper[i], upper[randomize(i + 1)]);
		}
		FOR(i, 0, SZ(lower))
		{
			swap(lower[i], lower[randomize(i + 1)]);
		}
		sort(ALL(upper), cmp);
		sort(ALL(lower), cmp);
		ans = lower;
		ans.insert(ans.end(), ALL(upper));
		FOR(i, 0, N)
		{
			arr[ans[i]] = i + 1;
		}
		ans = arr;
	}
	//eh we only have N.
	//well you know who the upper half is now.
	FOR(i, 0, N) res[i] = ans[i];
	return;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 376 KB Output is correct
2 Correct 16 ms 376 KB Output is correct
3 Correct 17 ms 376 KB Output is correct
4 Correct 16 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 528 KB Output is correct
2 Correct 70 ms 376 KB Output is correct
3 Correct 60 ms 376 KB Output is correct
4 Correct 60 ms 416 KB Output is correct
5 Correct 60 ms 440 KB Output is correct
6 Correct 61 ms 376 KB Output is correct
7 Correct 60 ms 440 KB Output is correct
8 Correct 61 ms 376 KB Output is correct
9 Correct 60 ms 404 KB Output is correct
10 Correct 59 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 396 KB Output is correct
2 Correct 35 ms 376 KB Output is correct
3 Correct 36 ms 376 KB Output is correct
4 Correct 35 ms 376 KB Output is correct
5 Correct 33 ms 376 KB Output is correct
6 Correct 33 ms 400 KB Output is correct
7 Correct 34 ms 376 KB Output is correct
8 Correct 33 ms 376 KB Output is correct
9 Correct 33 ms 432 KB Output is correct
10 Correct 34 ms 380 KB Output is correct
11 Correct 34 ms 376 KB Output is correct
12 Correct 21 ms 508 KB Output is correct
13 Correct 34 ms 376 KB Output is correct
14 Correct 31 ms 376 KB Output is correct
15 Correct 31 ms 376 KB Output is correct
16 Correct 34 ms 376 KB Output is correct
17 Correct 30 ms 376 KB Output is correct
18 Correct 31 ms 376 KB Output is correct
19 Correct 30 ms 376 KB Output is correct
20 Correct 30 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 35 ms 376 KB Output is partially correct
2 Partially correct 36 ms 428 KB Output is partially correct
3 Partially correct 35 ms 376 KB Output is partially correct
4 Partially correct 38 ms 376 KB Output is partially correct
5 Partially correct 37 ms 376 KB Output is partially correct
6 Partially correct 35 ms 376 KB Output is partially correct
7 Partially correct 38 ms 376 KB Output is partially correct
8 Partially correct 38 ms 392 KB Output is partially correct
9 Partially correct 48 ms 392 KB Output is partially correct
10 Partially correct 38 ms 376 KB Output is partially correct
11 Partially correct 35 ms 376 KB Output is partially correct
12 Partially correct 35 ms 376 KB Output is partially correct
13 Partially correct 38 ms 376 KB Output is partially correct
14 Partially correct 36 ms 376 KB Output is partially correct
15 Partially correct 45 ms 376 KB Output is partially correct
16 Partially correct 37 ms 432 KB Output is partially correct
17 Partially correct 35 ms 376 KB Output is partially correct
18 Partially correct 38 ms 432 KB Output is partially correct
19 Partially correct 35 ms 376 KB Output is partially correct
20 Partially correct 38 ms 376 KB Output is partially correct
21 Partially correct 35 ms 376 KB Output is partially correct
22 Partially correct 38 ms 376 KB Output is partially correct
23 Partially correct 36 ms 376 KB Output is partially correct
24 Partially correct 36 ms 376 KB Output is partially correct
25 Partially correct 37 ms 376 KB Output is partially correct
26 Partially correct 37 ms 376 KB Output is partially correct
27 Partially correct 38 ms 376 KB Output is partially correct
28 Partially correct 35 ms 376 KB Output is partially correct
29 Partially correct 36 ms 376 KB Output is partially correct
30 Partially correct 36 ms 376 KB Output is partially correct
31 Partially correct 36 ms 404 KB Output is partially correct
32 Partially correct 37 ms 296 KB Output is partially correct
33 Partially correct 39 ms 376 KB Output is partially correct
34 Partially correct 40 ms 376 KB Output is partially correct
35 Partially correct 37 ms 376 KB Output is partially correct
36 Partially correct 35 ms 376 KB Output is partially correct
37 Partially correct 35 ms 376 KB Output is partially correct
38 Partially correct 35 ms 396 KB Output is partially correct
39 Partially correct 44 ms 376 KB Output is partially correct
40 Partially correct 37 ms 388 KB Output is partially correct