Submission #1073843

# Submission time Handle Problem Language Result Execution time Memory
1073843 2024-08-24T23:51:45 Z ngrace Koala Game (APIO17_koala) C++14
100 / 100
53 ms 596 KB
#include "koala.h"
#include<bits/stdc++.h>
using namespace std;
#define v vector

v<int> query(v<int> q){
    int R[100],B[100];
    for(int i=0;i<q.size();i++) R[i]=q[i];
    playRound(R,B);
    v<int> res(q.size());
    for(int i=0;i<q.size();i++)res[i]=B[i];
    return res;
}

int minValue(int N, int W) {
    v<int> q(N,1);
    v<int> r = query(q);
    q = v<int>(N,0);
    for(int i=0;i<N;i++){
        if(r[i]!=0){
            q[i]=1;
            break;
        }
    }
    r = query(q);
    for(int i=0; i<N; i++){
        if(r[i]==0) return i;
    }
}

int maxValue(int N, int W) {
    v<int> poss;
    for(int i=0;i<N;i++) poss.push_back(i);
    while(poss.size()>1){
        v<int> q(N,0);
        for(int i:poss) q[i] = (W / (int)poss.size());
        v<int> r=query(q);
        v<int> nposs;
        for(int i:poss){
            if(r[i]>(W/(int)poss.size())) nposs.push_back(i);
        }
        poss = nposs;
    }
    return poss[0];
}

int greaterValueInd(int x, int y){
    int l=1,r=9;
    while(l<=r){
        int m=(l+r)/2;
        v<int> q(100,0);
        q[x]=m;
        q[y]=m;
        v<int> rr = query(q);
        
        if(rr[x]>m && rr[y]<=m) return 0;
        else if(rr[y]>m && rr[x]<=m) return 1;
        
        if(rr[x]<=m && rr[y]<=m) r=m-1;
        else l=m+1;
    }
}

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

int comp(int x, int y){
    v<int> q(100, 0);
    q[x] = 100;
    q[y] = 100;
    v<int> r = query(q);
    if(r[x]==0) return 1;
    else return 0;
}

void split(v<int> inds, int l, int r, int N, int W, int *P){
    if(l==r){
        P[inds[0]] = l;
        return;
    }
    int w = min((int)sqrt(2*l), W/(r-l+1));
    v<int> q(N,0);
    for(int i:inds) q[i] = w;
    v<int> rr = query(q);
    v<int> le, gr;
    for(int i:inds){
        if(rr[i]>w) gr.push_back(i);
        else le.push_back(i);
    }
    split(le, l, l+le.size()-1, N, W, P);
    split(gr, l+le.size(), r, N, W, P);
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        v<int> ind;
        for(int i=0; i<N; i++) ind.push_back(i);
        stable_sort(ind.begin(), ind.end(), comp);
        for(int i=0; i<N; i++) P[ind[i]] = i+1;
    } else {
        v<int> ind;
        for(int i=0; i<N; i++) ind.push_back(i);
        split(ind, 1, N, N, W, P);
    }
}

Compilation message

koala.cpp: In function 'std::vector<int> query(std::vector<int>)':
koala.cpp:8:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i=0;i<q.size();i++) R[i]=q[i];
      |                 ~^~~~~~~~~
koala.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<q.size();i++)res[i]=B[i];
      |                 ~^~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:17: warning: control reaches end of non-void function [-Wreturn-type]
   16 |     v<int> q(N,1);
      |                 ^
koala.cpp: In function 'int greaterValueInd(int, int)':
koala.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 596 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 344 KB Output is correct
2 Correct 53 ms 344 KB Output is correct
3 Correct 37 ms 344 KB Output is correct
4 Correct 40 ms 344 KB Output is correct
5 Correct 40 ms 344 KB Output is correct
6 Correct 38 ms 344 KB Output is correct
7 Correct 41 ms 344 KB Output is correct
8 Correct 38 ms 468 KB Output is correct
9 Correct 38 ms 464 KB Output is correct
10 Correct 38 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 344 KB Output is correct
2 Correct 29 ms 344 KB Output is correct
3 Correct 29 ms 344 KB Output is correct
4 Correct 27 ms 344 KB Output is correct
5 Correct 29 ms 344 KB Output is correct
6 Correct 28 ms 456 KB Output is correct
7 Correct 28 ms 344 KB Output is correct
8 Correct 28 ms 344 KB Output is correct
9 Correct 27 ms 344 KB Output is correct
10 Correct 30 ms 344 KB Output is correct
11 Correct 28 ms 344 KB Output is correct
12 Correct 12 ms 344 KB Output is correct
13 Correct 27 ms 344 KB Output is correct
14 Correct 24 ms 344 KB Output is correct
15 Correct 24 ms 344 KB Output is correct
16 Correct 25 ms 344 KB Output is correct
17 Correct 25 ms 344 KB Output is correct
18 Correct 25 ms 452 KB Output is correct
19 Correct 27 ms 344 KB Output is correct
20 Correct 25 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 2 ms 468 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 2 ms 344 KB Output is correct
9 Correct 2 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 2 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 344 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 472 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 3 ms 472 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 2 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 2 ms 344 KB Output is correct
31 Correct 2 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 2 ms 344 KB Output is correct
37 Correct 3 ms 344 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 3 ms 344 KB Output is correct
40 Correct 2 ms 344 KB Output is correct