Submission #1325373

#TimeUsernameProblemLanguageResultExecution timeMemory
1325373adiyerKoala Game (APIO17_koala)C++20
64 / 100
32 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;
}

bool comp2(int n, int i, int j){
    int b[n] = {}, r[n] = {};
    b[i] = b[j] = 100;
    playRound(b, r);
    return r[i] <= 100; 
}

void allValues(int n, int w, int *p) {
    for(int i = 0; i < n; i++) p[i] = 0;    
    int b[n], r[n], pos = -1;
    memset(b, 0, sizeof(b));
    if(w == 100){
        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;
        }
    }
    else{
        for(int i = 0; i < 100; i++) p[i] = 1;
        b[0] = 2;
        playRound(b, r);
        for(int i = 0; i < n; i++)
            if(r[i] == 0)
                pos = i;
        if(pos == -1){
            memset(b, 0, sizeof(b));
            for(int i = 0; i < 100; i++) p[i] = 1;
            b[1] = 2;
            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, tr = vals.size();
        while(tr - l > 1){
            int m = (l + tr) / 2;
            if(w == 200){
                if(comp2(n, vals[m], i)) l = m;
                else tr = m;
            }
            else{
                if(comp(n, vals[m], i)) l = m;
                else tr = m;
            }
        }
        vector < int > upd;
        for(int j = 0; j <= l; j++) upd.push_back(vals[j]);
        upd.push_back(i), p[i] = tr + 1;
        if(w == 200) p[i]--;
        for(int j = tr; 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...