Submission #1306824

#TimeUsernameProblemLanguageResultExecution timeMemory
1306824TymondKoala Game (APIO17_koala)C++20
72 / 100
23 ms1004 KiB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

int minValue(int N, int W) {
    int B[N];
    for(int i = 0; i < N; i++){
        B[i] = 0;
    }
    B[0] = 1;
    int X[N];
    playRound(B, X);

    for(int i = 0; i < N; i++){
        if(i == 0){
            if(X[i] <= 1){
                return i;
            }
        }else{
            if(X[i] == 0){
                return i;
            }
        }
    }
    return 0;
}

int maxValue(int N, int W) {
    int X[N];
    vi vec = {};
    for(int i = 0; i < N; i++){
        vec.pb(i);
    }

    for(int j = 0; j < 4; j++){
        int val = 1;
        while(sz(vec) * (val + 1) <= W && N > (val + 1) * (val + 2) / 2){
            val++;
        }
        for(int i = 0; i < N; i++){
            X[i] = 0;
        }
        for(auto ele : vec){
            X[ele] = val;
        }
        int W[N];
        playRound(X, W);

        vi nvec = {};
        for(auto ele : vec){
            if(W[ele] > X[ele]){
                nvec.pb(ele);
            }
        }
        vec = nvec;
        //debug(vec);
    }

    return vec[0];
}

int greaterValue(int N, int W) {
    // TODO: Implement Subtask 3 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    return 0;
}


const int MAXN = 107;
int Val[MAXN][MAXN];
void calc(int N, int W){
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            for(int X = 1; X <= (j + W - N) / (j - i + 1); X++){
                if(j > X * (X + 1) / 2 && i <= X * (j - i) + X * (X + 1) / 2){
                    Val[i][j] = X;
                }
            }
        }
    }
}

void f(int l, int p, vi vec, int *P, int N){
    //cerr << l << ' ' << p << ' ' << Val[l][p] << '\n';
   // debug(vec);
    if(l == p){
        P[vec[0]] = l;
        return;
    }

    int X[N];
    for(int i = 0; i < N; i++){
        X[i] = 0;
    }
    for(auto ele : vec){
        X[ele] = Val[l][p];
    }

    // for(int j = 0; j < N; j++){
    //     cerr << X[j] << ' ';
    // }
    // cerr << '\n';

    int W[N];
    playRound(X, W);
    // for(int j = 0; j < N; j++){
    //     cerr << W[j] << ' ';
    // }
    // cerr << '\n';

    vi big = {};
    vi small = {};
    for(auto ele : vec){
        if(W[ele] > X[ele]){
            big.pb(ele);
        }else{
            small.pb(ele);
        }
    }

    f(l, l + sz(small) - 1, small, P, N);
    f(l + sz(small), p, big, P, N);
}

void allValues(int N, int W, int *P) {
    vi vec = {};
    for(int i = 0; i < N; i++){
        vec.pb(i);
    }
    calc(N, W);
    f(1, N, vec, P, N);           
}
#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...