답안 #399581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399581 2021-05-06T07:00:13 Z oolimry 코알라 (APIO17_koala) C++17
100 / 100
92 ms 328 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 B[100]; int R[100];
int minValue(int N, int W) {
	fill(B,B+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) {
	fill(B,B+n,1);
	int b[4] = {2,4,11,100};
	for(int t = 0;t < 4;t++){
		playRound(B,R);
		for(int i = 0;i < n;i++){
			if(R[i] == 0 or B[i] == 0) B[i] = 0;
			else B[i] = b[t];
		}
	}
    for(int i = 0;i < n;i++) if(R[i] == 12) return i;
}

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;
}


vector<int> precompX = {1,1,1,1,1,1,1,1,1,2,1,1,2,3,3,1,3,1,1,2,3,4,2,3,4,4,1,2,3,3,4,1,5,1,2,2,3,5,3,4,5,2,5,2,3,4,5,4,4,6,1,2,3,5,6,3,4,6,5,6,1,4,5,6,1,7,1,2,2,2,3,4,5,7,3,4,7,5,6,7,2,5,6,7,2,2,3,4,5,6,8,3,4,6,8,5,8,6,8};
int ptr = 0;

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

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:14:1: warning: control reaches end of non-void function [-Wreturn-type]
   14 | }
      | ^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^
# 결과 실행 시간 메모리 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 7 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 320 KB Output is correct
2 Correct 18 ms 200 KB Output is correct
3 Correct 18 ms 200 KB Output is correct
4 Correct 18 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 324 KB Output is correct
2 Correct 92 ms 320 KB Output is correct
3 Correct 80 ms 324 KB Output is correct
4 Correct 79 ms 316 KB Output is correct
5 Correct 80 ms 320 KB Output is correct
6 Correct 85 ms 320 KB Output is correct
7 Correct 84 ms 328 KB Output is correct
8 Correct 81 ms 324 KB Output is correct
9 Correct 79 ms 324 KB Output is correct
10 Correct 79 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 316 KB Output is correct
2 Correct 53 ms 204 KB Output is correct
3 Correct 51 ms 200 KB Output is correct
4 Correct 49 ms 200 KB Output is correct
5 Correct 48 ms 200 KB Output is correct
6 Correct 49 ms 200 KB Output is correct
7 Correct 49 ms 296 KB Output is correct
8 Correct 49 ms 200 KB Output is correct
9 Correct 50 ms 200 KB Output is correct
10 Correct 48 ms 200 KB Output is correct
11 Correct 50 ms 200 KB Output is correct
12 Correct 22 ms 200 KB Output is correct
13 Correct 47 ms 200 KB Output is correct
14 Correct 43 ms 200 KB Output is correct
15 Correct 44 ms 200 KB Output is correct
16 Correct 45 ms 200 KB Output is correct
17 Correct 45 ms 200 KB Output is correct
18 Correct 46 ms 320 KB Output is correct
19 Correct 46 ms 200 KB Output is correct
20 Correct 51 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 328 KB Output is correct
2 Correct 5 ms 200 KB Output is correct
3 Correct 5 ms 200 KB Output is correct
4 Correct 5 ms 328 KB Output is correct
5 Correct 6 ms 328 KB Output is correct
6 Correct 5 ms 200 KB Output is correct
7 Correct 5 ms 328 KB Output is correct
8 Correct 5 ms 328 KB Output is correct
9 Correct 5 ms 200 KB Output is correct
10 Correct 8 ms 200 KB Output is correct
11 Correct 5 ms 200 KB Output is correct
12 Correct 5 ms 316 KB Output is correct
13 Correct 5 ms 328 KB Output is correct
14 Correct 5 ms 200 KB Output is correct
15 Correct 5 ms 320 KB Output is correct
16 Correct 5 ms 328 KB Output is correct
17 Correct 5 ms 328 KB Output is correct
18 Correct 5 ms 328 KB Output is correct
19 Correct 5 ms 328 KB Output is correct
20 Correct 5 ms 328 KB Output is correct
21 Correct 5 ms 316 KB Output is correct
22 Correct 5 ms 328 KB Output is correct
23 Correct 5 ms 200 KB Output is correct
24 Correct 5 ms 200 KB Output is correct
25 Correct 5 ms 200 KB Output is correct
26 Correct 5 ms 200 KB Output is correct
27 Correct 5 ms 200 KB Output is correct
28 Correct 5 ms 328 KB Output is correct
29 Correct 5 ms 328 KB Output is correct
30 Correct 5 ms 200 KB Output is correct
31 Correct 5 ms 200 KB Output is correct
32 Correct 5 ms 204 KB Output is correct
33 Correct 5 ms 312 KB Output is correct
34 Correct 5 ms 328 KB Output is correct
35 Correct 5 ms 328 KB Output is correct
36 Correct 5 ms 212 KB Output is correct
37 Correct 5 ms 328 KB Output is correct
38 Correct 5 ms 328 KB Output is correct
39 Correct 5 ms 200 KB Output is correct
40 Correct 5 ms 328 KB Output is correct