//#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<N;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + P[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=N-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
}
#include <bits/stdc++.h>
#include "koala.h"
using namespace std;
int minValue(int N, int W) {
int res[N];
int in[N];
for(int i = 0; i < N; i++){
in[i] = 0;
}
in[0] = 1;
playRound(in,res);
int p = -1;
for(int i = 0; i < N; i++){
if(res[i] <= in[i]){
p = i;
}
}
return p;
}
int maxValue(int N, int W) {
set<int> sat;
int res[N];
int in[N];
for(int i = 0; i < N; i++){
sat.insert(i);
in[i] = 0;
}
while(sat.size() != 1){
int num = 100 / sat.size();
for(int i = 0; i < N; i++){
in[i] = 0;
}
for(int i : sat){
in[i] = num;
}
playRound(in,res);
for(int i = 0; i < N; i++){
if(res[i] <= in[i] && sat.find(i) != sat.end()){
sat.erase(i);
}
}
}
for(int i : sat) return i;
}
//9 5 3
int greaterValue(int N, int W) {
int in[N];
int res[N];
int it = minValue(N, W);
if(it == 0) return 1;
if(it == 1) return 0;
for(int i = 0; i < N; i++){
in[i] = 0;
}
in[0] = 4;
in[1] = 4;
playRound(in,res);
if(res[0] > in[0] && res[1] <= in[1]) return 0;
if(res[1] > in[1] && res[0] <= in[0]) return 1;
if(res[0] > in[0]){
in[0] = 8;
in[1] = 8;
}
else{
in[0] = 2;
in[1] = 2;
}
playRound(in,res);
if(res[0] > in[0] && res[1] <= in[1]) return 0;
if(res[1] > in[1] && res[0] <= in[0]) return 1;
in[0] = 2;
in[1] = 2;
playRound(in,res);
if(res[0] > in[0] && res[1] <= in[1]) return 0;
if(res[1] > in[1] && res[0] <= in[0]) return 1;
}
bool breater(int a, int b){
int in[100];
int res[100];
for(int i = 0; i < 100; i++){
in[i] = 0;
}
in[a] = 100;
in[b] = 100;
playRound(in,res);
return in[b] < res[b];
}
void allValues(int N, int W, int *P) {
if (W == 2*N) {
vector<int> v;
for(int i = 0; i < N; i++){
v.push_back(i);
}
sort(v.begin(),v.end(),breater);
for(int i = 0; i < N; i++){
P[v[i]] = i + 1;
}
} else {
// TODO: Implement Subtask 5 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
}
}
static void runGame(int F) {
int i;
scanf("%d %d",&N,&W);
for (i=0;i<N;++i) {
P[i] = i + 1;
}
swap(P[0],P[2]);
swap(P[1],P[32]);
printf("%d %d\n",P[0],P[1]);
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
printf("%d\n", greaterValue(N, W));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}
/*
4 1
100 200
*/
Compilation message
koala.cpp: In function 'void grader()':
koala.cpp:258:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
258 | scanf("%d %d",&F,&G);
| ~~~~~^~~~~~~~~~~~~~~
koala.cpp: In function 'void runGame(int)':
koala.cpp:227:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
227 | scanf("%d %d",&N,&W);
| ~~~~~^~~~~~~~~~~~~~~
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:106:14: warning: control reaches end of non-void function [-Wreturn-type]
106 | set<int> sat;
| ^~~
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:183:1: warning: control reaches end of non-void function [-Wreturn-type]
183 | }
| ^
/usr/bin/ld: /tmp/cckzna5Q.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc4H1GJP.o:koala.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cckzna5Q.o: in function `playRound(int*, int*)':
grader.cpp:(.text+0x280): multiple definition of `playRound(int*, int*)'; /tmp/cc4H1GJP.o:koala.cpp:(.text+0x1d0): first defined here
collect2: error: ld returned 1 exit status