Submission #399577

# Submission time Handle Problem Language Result Execution time Memory
399577 2021-05-06T06:47:25 Z oolimry Koala Game (APIO17_koala) C++17
85 / 100
93 ms 336 KB
#include "koala.h"
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
using namespace std;
int minValue(int N, int W) {
    int B[N];
    int R[N];
    fill(B,B+N,0);
    fill(R,R+N,0);
    B[0] = 1;
    playRound(B,R);
    for(int i = 0;i < N;i++){
        if(R[i] == 0) return i;
    }
}

int maxValue(int N, int W) {
    int B1[N], B2[N], B3[N], B4[N];
    int R1[N], R2[N], R3[N], R4[N];
    for(int i = 0;i < N;i++){
        B1[i] = 1;
    }
    playRound(B1,R1);
    for(int i = 0;i < N;i++){
        B2[i] = R1[i];
    }
    playRound(B2,R2);
    for(int i = 0;i < N;i++){
        if(R2[i] == 3) B3[i] = 4;
        else B3[i] = 0;
    }
    playRound(B3,R3);
    for(int i = 0;i < N;i++){
        if(R3[i] == 5) B4[i] = 11;
        else B4[i] = 0;
    }
    playRound(B4,R4);
    for(int i = 0;i < N;i++){
        if(R4[i] == 12) return i;
    }
    return 0;
}

int comp(int N, int W, int a, int b) {
	int B[N];
	int R[N];

	fill(B,B+N,0);
	B[a] = 4; B[b] = 4;
	playRound(B,R);
	if(R[a] == 0 && R[b] > 0) return 1; ///something stands out
	else if(R[a] > 0 && R[b] == 0) return 0; ///something stands out
	else if(R[a] == 0 && R[b] == 0){
		fill(B,B+N,0);
		B[a] = 1; B[b] = 1;
		playRound(B,R);
		if(R[a] == 0) return 1;
		if(R[b] == 0) return 0;

		fill(B,B+N,0);
		B[a] = 3;
		B[b] = 3;
		playRound(B,R);
		if(R[a] == 0) return 1;
		if(R[b] == 0) return 0;
	}

	fill(B,B+N,0);
	B[a] = 7; B[b] = 7;
	playRound(B,R);
	if(R[a] == 0 && R[b] > 0) return 1; ///something stands out
	else if(R[a] > 0 && R[b] == 0) return 0; ///something stands out
	else if(R[a] == 0 && R[b] == 0){
		fill(B,B+N,0);
		B[a] = 5; B[b] = 5;
		playRound(B,R);
		if(R[a] == 0 && R[b] > 0) return 1; ///something stands out
		else if(R[a] > 0 && R[b] == 0) return 0; ///something stands out
	}
	else{
		fill(B,B+N,0);
		B[a] = 10; B[b] = 10;
		playRound(B,R);
		if(R[a] == 0 && R[b] > 0) return 1; ///something stands out
		else if(R[a] > 0 && R[b] == 0) return 0; ///something stands out
	}
	return 1;
}

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

void allValues1(int n, int W, int *P){
	int B[n]; int R[n]; int A[n];
	for(int i = 0;i < n;i++) A[i] = i;
	
	stable_sort(A, A+n, [&](int a, int b){
		fill(B,B+n,0);
		B[a] = n, B[b] = n;
		playRound(B,R);

		if(R[a] == 0) return true;
		else return false;
	});
	
	for(int i = 0;i < n;i++) P[A[i]] = i+1;
}

int B[100]; int R[100];

void play(){
	playRound(B,R);
}

void allValues2(int n, int *P, int s, int e, vector<int> stuff){
	if(sz(stuff) == 1){
		P[stuff[0]] = s;
		return;
	}
	
	fill(B,B+n,0);
	for(int X = 1;sz(stuff)*X <= n;X++){
		for(int i : stuff) B[i] = X;
		play();
		
		vector<int> left, right;
		for(int i : stuff){
			if(R[i] == 0) left.push_back(i);
			else right.push_back(i);
		}
		
		if(sz(left) == 0 or sz(right) == 0) continue;
		int m = s + sz(left);
		allValues2(n, P, s, m-1, left);
		allValues2(n, P, m, e, right);
		return;
	}
	
	assert(false);
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) allValues1(N, W, P);
    else{
		vector<int> stuff;
		for(int i = 0;i < N;i++) stuff.push_back(i);
		allValues2(N, P, 1, N, stuff);
	}
}

Compilation message

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
   16 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 200 KB Output is correct
2 Correct 6 ms 200 KB Output is correct
3 Correct 6 ms 200 KB Output is correct
4 Correct 6 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 200 KB Output is correct
2 Correct 18 ms 320 KB Output is correct
3 Correct 18 ms 316 KB Output is correct
4 Correct 19 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 312 KB Output is correct
2 Correct 93 ms 320 KB Output is correct
3 Correct 81 ms 336 KB Output is correct
4 Correct 80 ms 320 KB Output is correct
5 Correct 82 ms 316 KB Output is correct
6 Correct 81 ms 328 KB Output is correct
7 Correct 82 ms 320 KB Output is correct
8 Correct 81 ms 320 KB Output is correct
9 Correct 80 ms 320 KB Output is correct
10 Correct 81 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 304 KB Output is correct
2 Correct 51 ms 256 KB Output is correct
3 Correct 50 ms 200 KB Output is correct
4 Correct 50 ms 200 KB Output is correct
5 Correct 48 ms 200 KB Output is correct
6 Correct 54 ms 200 KB Output is correct
7 Correct 55 ms 200 KB Output is correct
8 Correct 50 ms 200 KB Output is correct
9 Correct 49 ms 200 KB Output is correct
10 Correct 47 ms 200 KB Output is correct
11 Correct 50 ms 200 KB Output is correct
12 Correct 22 ms 256 KB Output is correct
13 Correct 47 ms 200 KB Output is correct
14 Correct 46 ms 200 KB Output is correct
15 Correct 45 ms 200 KB Output is correct
16 Correct 46 ms 200 KB Output is correct
17 Correct 44 ms 292 KB Output is correct
18 Correct 44 ms 200 KB Output is correct
19 Correct 45 ms 292 KB Output is correct
20 Correct 45 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 16 ms 328 KB Output is partially correct
2 Partially correct 16 ms 324 KB Output is partially correct
3 Partially correct 15 ms 328 KB Output is partially correct
4 Partially correct 15 ms 316 KB Output is partially correct
5 Partially correct 17 ms 320 KB Output is partially correct
6 Partially correct 15 ms 316 KB Output is partially correct
7 Partially correct 16 ms 320 KB Output is partially correct
8 Partially correct 15 ms 200 KB Output is partially correct
9 Partially correct 15 ms 200 KB Output is partially correct
10 Partially correct 15 ms 200 KB Output is partially correct
11 Partially correct 15 ms 200 KB Output is partially correct
12 Partially correct 14 ms 200 KB Output is partially correct
13 Partially correct 15 ms 316 KB Output is partially correct
14 Partially correct 15 ms 320 KB Output is partially correct
15 Partially correct 15 ms 320 KB Output is partially correct
16 Partially correct 15 ms 328 KB Output is partially correct
17 Partially correct 15 ms 320 KB Output is partially correct
18 Partially correct 15 ms 324 KB Output is partially correct
19 Partially correct 15 ms 316 KB Output is partially correct
20 Partially correct 15 ms 328 KB Output is partially correct
21 Partially correct 15 ms 316 KB Output is partially correct
22 Partially correct 15 ms 316 KB Output is partially correct
23 Partially correct 16 ms 320 KB Output is partially correct
24 Partially correct 15 ms 324 KB Output is partially correct
25 Partially correct 17 ms 328 KB Output is partially correct
26 Partially correct 16 ms 200 KB Output is partially correct
27 Partially correct 17 ms 320 KB Output is partially correct
28 Partially correct 15 ms 328 KB Output is partially correct
29 Partially correct 17 ms 320 KB Output is partially correct
30 Partially correct 15 ms 332 KB Output is partially correct
31 Partially correct 15 ms 328 KB Output is partially correct
32 Partially correct 15 ms 200 KB Output is partially correct
33 Partially correct 15 ms 320 KB Output is partially correct
34 Partially correct 15 ms 320 KB Output is partially correct
35 Partially correct 15 ms 320 KB Output is partially correct
36 Partially correct 17 ms 316 KB Output is partially correct
37 Partially correct 16 ms 312 KB Output is partially correct
38 Partially correct 15 ms 320 KB Output is partially correct
39 Partially correct 16 ms 200 KB Output is partially correct
40 Partially correct 15 ms 200 KB Output is partially correct