Submission #977515

# Submission time Handle Problem Language Result Execution time Memory
977515 2024-05-08T06:06:59 Z siewjh Koala Game (APIO17_koala) C++17
90 / 100
53 ms 600 KB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 105;
int qa[MAXN], ra[MAXN];

int minValue(int N, int W){ // N = 100, W = 100, 2 times
    qa[0] = 1;
    for (int i = 1; i < N; i++) qa[i] = 0;
    playRound(qa, ra);
    if (ra[0] <= 1) return 0;
    for (int i = 1; i < N; i++)
		if (ra[i] == 0)
			return i;
}

int maxValue(int N, int W){ // N = 100, W = 100, 4 times
    vector<int> loc;
    for (int i = 0; i < N; i++) loc.push_back(i);
    while (loc.size() > 1){ // 100, 50, 25, 9, 1
		int amt = W / loc.size();
		for (int i = 0; i < N; i++) qa[i] = 0;
		for (int x : loc) qa[x] = amt;
		playRound(qa, ra);
		vector<int> ori; swap(ori, loc);
		for (int x : ori) 
			if (ra[x] > amt)
				loc.push_back(x);
	}
	return loc[0];
}

int greaterValue(int N, int W){ // N = 100, W = 100, 3 times
	for (int i = 0; i < N; i++) qa[i] = 0;
	int lo = 0, hi = 4;
	int amt[] = {1, 2, 4, 6, 8};
	while (lo <= hi){
		int m = (lo + hi) >> 1;
		qa[0] = qa[1] = amt[m];
		playRound(qa, ra);
		if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m];
		else if (ra[0] > amt[m]) lo = m + 1;
		else hi = m - 1;
	}
}

void dnc(int l, int r, vector<int> &vind, int *P){
	if (l == r){
		P[vind[0]] = l;
		return;
	}
	int sz = r - l + 1, lo = 1, hi = 100 / sz, sh = -1;
	vector<int> rem;
	for (int i = 1; i < l; i++) rem.push_back(i);
	for (int i = r + 1; i <= 100; i++) rem.push_back(i);
	while (lo <= hi){
		int m = (lo + hi) >> 1, stone = sz, ind = 0, choose = 0;
		for (int x = r; x >= l; x--){
			int sum = 0;
			for (int i = 0; i <= m; i++){
				if (stone) stone--;
				else if (ind != rem.size()){
					sum += rem[ind]; ind++;
				}
				else{
					sum = 1e9; break;
				}
			}
			if (sum > x) break;
			else if (sum == x){
				if (choose) choose++;
				break;
			}
			else choose++;
		}
		if (choose == 0) hi = m - 1;
		else if (choose == sz) lo = m + 1;
		else{
			sh = m;
			break;
		}
	}
	vector<int> lv, rv;
	for (int i = 0; i < 100; i++) qa[i] = 0;
	for (int x : vind) qa[x] = sh;
	playRound(qa, ra);
	for (int x : vind){
		if (ra[x] > sh) rv.push_back(x);
		else lv.push_back(x);
	}
	dnc(l, l + lv.size() - 1, lv, P); dnc(l + lv.size(), r, rv, P);
}

void allValues(int N, int W, int *P){ // N = 100, W = 100, 100 times
    vector<int> vind(100);
    for (int i = 0; i < 100; i++) vind[i] = i;
    dnc(1, 100, vind, P);
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:42:13: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
   42 |   if (ra[0] > amt[m] != ra[1] > amt[m]) return ra[1] > amt[m];
      |       ~~~~~~^~~~~~~~
koala.cpp: In function 'void dnc(int, int, std::vector<int>&, int*)':
koala.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     else if (ind != rem.size()){
      |              ~~~~^~~~~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
   16 | }
      | ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 11 ms 460 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 452 KB Output is correct
2 Correct 53 ms 596 KB Output is correct
3 Correct 47 ms 472 KB Output is correct
4 Correct 46 ms 472 KB Output is correct
5 Correct 47 ms 468 KB Output is correct
6 Correct 50 ms 492 KB Output is correct
7 Correct 48 ms 600 KB Output is correct
8 Correct 48 ms 488 KB Output is correct
9 Correct 47 ms 464 KB Output is correct
10 Correct 46 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 464 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 4 ms 344 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 3 ms 344 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 3 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 344 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 344 KB Output is correct
29 Correct 3 ms 344 KB Output is correct
30 Correct 3 ms 464 KB Output is correct
31 Correct 3 ms 344 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 344 KB Output is correct
34 Correct 3 ms 344 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 3 ms 344 KB Output is correct
39 Correct 3 ms 344 KB Output is correct
40 Correct 3 ms 344 KB Output is correct