Submission #732621

# Submission time Handle Problem Language Result Execution time Memory
732621 2023-04-29T06:51:34 Z SanguineChameleon Koala Game (APIO17_koala) C++17
59 / 100
79 ms 340 KB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e2 + 20;
int B[maxn];
int R[maxn];
int tr[maxn * 4];

int minValue(int N, int W) {
	// TODO: Implement Subtask 1 solution here.
	// You may leave this function unmodified if you are not attempting this
	// subtask.
	B[0] = 1;
	for (int i = 1; i < N; i++) {
		B[i] = 0;
	}
	playRound(B, R);
	for (int i = 0; i < N; i++) {
		if (R[i] <= B[i]) {
			return i;
		}
	}
	return -1;
}

int maxValue(int N, int W) {
	// TODO: Implement Subtask 2 solution here.
	// You may leave this function unmodified if you are not attempting this
	// subtask.
	int cnt = N;
	for (int i = 0; i < N; i++) {
		B[i] = 1;
	}
	while (cnt > 1) {
		for (int i = 0; i < N; i++) {
			if (B[i] == 1) {
				B[i] = W / cnt;
			}
		}
		playRound(B, R);
		cnt = 0;
		for (int i = 0; i < N; i++) {
			B[i] = (B[i] > 0 && R[i] > B[i]);
			cnt += B[i];
		}
	}
	for (int i = 0; i < N; i++) {
		if (B[i] == 1) {
			return i;
		}
	}
	return -1;
}

int greaterValue(int N, int W, int x, int y) {
	// TODO: Implement Subtask 3 solution here.
	// You may leave this function unmodified if you are not attempting this
	// subtask.
	vector<int> vals = {2, 4, 8};
	for (auto v: vals) {
		for (int i = 0; i < N; i++) {
			B[i] = 0;
		}
		B[x] = v;
		B[y] = v;
		playRound(B, R);
		if ((R[x] > B[x]) != (R[y] > B[y])) {
			if (R[x] > B[x]) {
				return x;
			}
			else {
				return y;
			}
		}
		else {
			if (v == 2 && R[x] <= B[x]) {
				return minValue(N, W) ^ (x ^ y);
			}
		}
	}
	return -1;
}

int greaterValue(int N, int W) {
	return greaterValue(N, W, 0, 1);
}

int merge(int N, int W, int x, int y) {
	if (x == -1) {
		return y;
	}
	else if (y == -1) {
		return x;
	}
	else {
		return greaterValue(N, W, x, y);
	}
}

int order[maxn];
int pos[maxn];

void build(int N, int W, int id, int lt, int rt) {
	if (lt == rt) {
		tr[id] = order[lt];
		pos[order[lt]] = lt;
		return;
	}
	int mt = (lt + rt) / 2;
	build(N, W, id * 2, lt, mt);
	build(N, W, id * 2 + 1, mt + 1, rt);
	tr[id] = merge(N, W, tr[id * 2], tr[id * 2 + 1]);
}

void update(int N, int W, int id, int lt, int rt, int pos) {
	if (lt == rt) {
		tr[id] = -1;
		return;
	}
	int mt = (lt + rt) / 2;
	if (pos <= mt) {
		update(N, W, id * 2, lt, mt, pos);
	}
	else {
		update(N, W, id * 2 + 1, mt + 1, rt, pos);
	}
	tr[id] = merge(N, W, tr[id * 2], tr[id * 2 + 1]);
}

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

void allValues(int N, int W, int *P) {
	if (W == 2*N) {
		// TODO: Implement Subtask 4 solution here.
		// You may leave this block unmodified if you are not attempting this
		// subtask.
	} else {
		// TODO: Implement Subtask 5 solution here.
		// You may leave this block unmodified if you are not attempting this
		// subtask.
		for (int i = 1; i <= N; i++) {
			order[i] = i - 1;
		}
		shuffle(order + 1, order + N + 1, gen);
		build(N, W, 1, 1, N);
		for (int i = N; i >= 1; i--) {
			P[tr[1]] = i;
			if (i == 1) {
				break;
			}
			update(N, W, 1, 1, N, pos[tr[1]]);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 3 ms 324 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 320 KB Output is correct
2 Correct 16 ms 324 KB Output is correct
3 Correct 12 ms 328 KB Output is correct
4 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 320 KB Output is correct
2 Correct 77 ms 324 KB Output is correct
3 Correct 77 ms 336 KB Output is correct
4 Correct 77 ms 336 KB Output is correct
5 Correct 74 ms 336 KB Output is correct
6 Correct 76 ms 340 KB Output is correct
7 Correct 74 ms 328 KB Output is correct
8 Correct 77 ms 332 KB Output is correct
9 Correct 77 ms 336 KB Output is correct
10 Correct 79 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 40 ms 304 KB Output is partially correct
2 Partially correct 39 ms 208 KB Output is partially correct
3 Partially correct 40 ms 208 KB Output is partially correct
4 Partially correct 39 ms 208 KB Output is partially correct
5 Partially correct 37 ms 208 KB Output is partially correct
6 Partially correct 37 ms 320 KB Output is partially correct
7 Partially correct 39 ms 208 KB Output is partially correct
8 Partially correct 39 ms 208 KB Output is partially correct
9 Partially correct 39 ms 208 KB Output is partially correct
10 Partially correct 37 ms 208 KB Output is partially correct
11 Partially correct 37 ms 208 KB Output is partially correct
12 Partially correct 37 ms 208 KB Output is partially correct
13 Partially correct 38 ms 208 KB Output is partially correct
14 Partially correct 35 ms 304 KB Output is partially correct
15 Partially correct 36 ms 208 KB Output is partially correct
16 Partially correct 38 ms 208 KB Output is partially correct
17 Partially correct 38 ms 208 KB Output is partially correct
18 Partially correct 40 ms 208 KB Output is partially correct
19 Partially correct 44 ms 300 KB Output is partially correct
20 Partially correct 41 ms 208 KB Output is partially correct
21 Partially correct 36 ms 320 KB Output is partially correct
22 Partially correct 38 ms 208 KB Output is partially correct
23 Partially correct 36 ms 296 KB Output is partially correct
24 Partially correct 35 ms 208 KB Output is partially correct
25 Partially correct 35 ms 296 KB Output is partially correct
26 Partially correct 34 ms 208 KB Output is partially correct
27 Partially correct 37 ms 208 KB Output is partially correct
28 Partially correct 39 ms 208 KB Output is partially correct
29 Partially correct 34 ms 208 KB Output is partially correct
30 Partially correct 34 ms 208 KB Output is partially correct
31 Partially correct 34 ms 304 KB Output is partially correct
32 Partially correct 35 ms 208 KB Output is partially correct
33 Partially correct 34 ms 208 KB Output is partially correct
34 Partially correct 35 ms 208 KB Output is partially correct
35 Partially correct 35 ms 208 KB Output is partially correct
36 Partially correct 35 ms 304 KB Output is partially correct
37 Partially correct 38 ms 312 KB Output is partially correct
38 Partially correct 37 ms 208 KB Output is partially correct
39 Partially correct 35 ms 208 KB Output is partially correct
40 Partially correct 34 ms 208 KB Output is partially correct