Submission #1325366

#TimeUsernameProblemLanguageResultExecution timeMemory
1325366adiyerKoala Game (APIO17_koala)C++20
64 / 100
33 ms456 KiB
#include "koala.h"
#include <bits/stdc++.h>

using namespace std;

int minValue(int n, int w) {
    int b[n], r[n];
    memset(b, 0, sizeof(b));
    b[0] = 1;
    playRound(b, r);
    for(int i = 0; i < n; i++)
        if(r[i] == 0)
            return i;
    memset(b, 0, sizeof(b));
    b[1] = 1;
    playRound(b, r);
    for(int i = 0; i < n; i++)
        if(r[i] == 0)
            return i;
    return 0;
}

int maxValue(int n, int w) {
    int b[n], r[n];
    memset(b, 0, sizeof(b));
    for(int i = 0; i < n; i++) 
        b[i] = 1;
    playRound(b, r);
    memset(b, 0, sizeof(b));
    for(int i = 0; i < n; i++)
        if(r[i] > 1)
            b[i] = 2;
    playRound(b, r);
    memset(b, 0, sizeof(b));
    for(int i = 0; i < n; i++)
        if(r[i] > 1)
            b[i] = 4;
    playRound(b, r);
    memset(b, 0, sizeof(b));
    for(int i = 0; i < n; i++)
        if(r[i] > 1)
            b[i] = 11;
    playRound(b, r);
    for(int i = 0; i < n; i++)
        if(r[i] > 1)
            return i;
    return 0;
}

int greaterValue(int n, int w) {
    int b[n], r[n];
    memset(b, 0, sizeof(b));
    b[0] = b[1] = 5;
    playRound(b, r);
    if(r[0] > 5 && r[1] <= 5) return 0;
    if(r[0] <= 5 && r[1] > 5) return 1;
    if(r[0] <= 5 && r[1] <= 5){
        memset(b, 0, sizeof(b));
        b[0] = b[1] = 3;
        playRound(b, r);
        if(r[0] > 3 && r[1] <= 3) return 0;
        if(r[0] <= 3 && r[1] > 3) return 1;
        memset(b, 0, sizeof(b));
        b[0] = b[1] = 1;
        playRound(b, r);
        if(r[0] > 1 && r[1] <= 1) return 0;
        if(r[0] <= 1 && r[1] > 1) return 1;
    }

    if(r[0] > 5 && r[1] > 5){
        memset(b, 0, sizeof(b));
        b[0] = b[1] = 8;
        playRound(b, r);
        if(r[0] > 8 && r[1] <= 8) return 0;
        if(r[0] <= 8 && r[1] > 8) return 1;
    }
    return 0;
}

bool comp(int n, int i, int j){
    int b[n], r[n];
    memset(b, 0, sizeof(b));
    b[i] = b[j] = 5;
    playRound(b, r);
    if(r[i] > 5 && r[j] <= 5) return 0;
    if(r[i] <= 5 && r[j] > 5) return 1;
    if(r[i] <= 5 && r[j] <= 5){
        memset(b, 0, sizeof(b));
        b[i] = b[j] = 3;
        playRound(b, r);
        if(r[i] > 3 && r[j] <= 3) return 0;
        if(r[i] <= 3 && r[j] > 3) return 1;
        memset(b, 0, sizeof(b));
        b[i] = b[j] = 1;
        playRound(b, r);
        if(r[i] > 1 && r[j] <= 1) return 0;
        if(r[i] <= 1 && r[j] > 1) return 1;
    }
    if(r[i] > 5 && r[j] > 5){
        memset(b, 0, sizeof(b));
        b[i] = b[j] = 8;
        playRound(b, r);
        if(r[i] > 8 && r[j] <= 8) return 0;
        if(r[i] <= 8 && r[j] > 8) return 1;
    }
    return 0;
}

void allValues(int n, int w, int *p) {
    for(int i = 0; i < n; i++) p[i] = 0;
    if (w == 2 * n) {
    } else {
        int b[n], r[n], pos = -1;
        memset(b, 0, sizeof(b));
        b[0] = 1;
        playRound(b, r);
        for(int i = 0; i < n; i++)
            if(r[i] == 0)
                pos = i;
        if(pos == -1){
            memset(b, 0, sizeof(b));
            b[1] = 1;
            playRound(b, r);
            for(int i = 0; i < n; i++)
                if(r[i] == 0)
                    pos = i;
        }
        p[pos] = 1;
        vector < int > vals;
        vals.push_back(pos);
        for(int i = 0; i < n; i++){
            if(i == pos) continue;
            int l = 0, r = vals.size();
            while(r - l > 1){
                int m = (l + r) / 2;
                if(comp(n, vals[m], i)) l = m;
                else r = m;
            }
            vector < int > upd;
            for(int j = 0; j <= l; j++) upd.push_back(vals[j]);
            upd.push_back(i), p[i] = r + 1;
            for(int j = r; j < vals.size(); j++) upd.push_back(vals[j]), p[vals[j]]++;
            vals = upd;
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...