Submission #810498

# Submission time Handle Problem Language Result Execution time Memory
810498 2023-08-06T10:26:44 Z oscar1f Koala Game (APIO17_koala) C++17
85 / 100
43 ms 460 KB
#include<bits/stdc++.h>
#include "koala.h"

using namespace std;

int coeff;
int posVal[100];
vector<int> init(100);

vector<int> jouer(vector<int> a) {
    /*for (int i:a) {
        cout<<i<<" ";
    }
    cout<<endl;*/
    vector<int> b(100);
    playRound(a.data(),b.data());
    return b;
}

int minValue(int N, int W) {
    vector<int> rep(N),quest(N);
    quest[0]=1;
    rep=jouer(quest);
    for (int i=1;i<N;i++) {
        if (rep[i]==0) {
            return i;
        }
    }
    return 0;
}

int maxValue(int N, int W) {
    vector<int> rep(N),quest(N);
    vector<int> listeGrand,nouv;
    int nbMis;
    for (int i=0;i<N;i++) {
        quest[i]=1;
        listeGrand.push_back(i);
    }
    vector<int> tailleTour={1,2,4,11};
    reverse(tailleTour.begin(),tailleTour.end());
    while (listeGrand.size()>1) {
        /*cout<<listeGrand.size()<<" : ";
        for (int i:listeGrand) {
            cout<<i<<" ";
        }
        cout<<endl;*/
        nbMis=tailleTour.back();
        tailleTour.pop_back();
        nouv.clear();
        quest=init;
        for (int i:listeGrand) {
            quest[i]=nbMis;
        }
        rep=jouer(quest);
        for (int i:listeGrand) {
            if (rep[i]>nbMis) {
                nouv.push_back(i);
            }
        }
        listeGrand=nouv;
    }
    return listeGrand.back();
}

int greaterValue(int N, int W) {
    vector<int> rep(N),quest(N);
    int deb=1,fin=13,mid;
    while (1>0) {
        mid=(deb+fin)/2;
        quest[0]=mid;
        quest[1]=mid;
        rep=jouer(quest);
        if (rep[0]>mid and rep[1]<=mid) {
            return 0;
        }
        if (rep[1]>mid and rep[0]<=mid) {
            return 1;
        }
        if (rep[0]>mid) {
            deb=mid+1;
        }
        else {
            fin=mid-1;
        }
    }
    return 42;
}

void solve(int deb,int fin,vector<int> pos) {
    /*cout<<deb<<" "<<fin<<" : ";
    for (int i:pos) {
        cout<<i<<" ";
    }
    cout<<endl;*/
    if (deb>fin) {
        return ;
    }
    if (deb==fin) {
        posVal[pos[0]]=deb;
        return;
    }
    vector<int> petit,grand,quest,rep;
    for (int i=1;i<=26;i++) {
        petit.clear();
        grand.clear();
        quest=init;
        for (int j:pos) {
            quest[j]=i;
        }
        rep=jouer(quest);
        for (int j:pos) {
            if (rep[j]>i) {
                grand.push_back(j);
            }
            else {
                petit.push_back(j);
            }
        }
        //cout<<petit.size()<<" "<<grand.size()<<endl;
        if (!grand.empty() and !petit.empty()) {
            solve(deb,deb+petit.size()-1,petit);
            solve(deb+petit.size(),fin,grand);
            return;
        }
    }
}

bool plusGrand(int a,int b) {
    vector<int> quest(100),rep(100);
    quest[a]=100;
    quest[b]=100;
    rep=jouer(quest);
    if (rep[a]<=100) {
        return true;
    }
    return false;
}

vector<int> trier(vector<int> v) {
    if (v.size()<=1) {
        return v;
    }
    vector<int> a,b;
    for (int i=0;i<(int)v.size()/2;i++) {
        a.push_back(v[i]);
    }
    for (int i=(int)v.size()/2;i<(int)v.size();i++) {
        b.push_back(v[i]);
    }
    v.clear();
    a=trier(a);
    b=trier(b);
    while (!a.empty() or !b.empty()) {
        if (a.empty()) {
            v.push_back(b.back());
            b.pop_back();
        }
        else if (b.empty()) {
            v.push_back(a.back());
            a.pop_back();
        }
        else if (plusGrand(a.back(),b.back())) {
            v.push_back(b.back());
            b.pop_back();
        }
        else {
            v.push_back(a.back());
            a.pop_back();
        }
    }
    reverse(v.begin(),v.end());
    return v;
}

void allValues(int N, int W, int *P) {
    if (W==200) {
        vector<int> ans;
        for (int i=0;i<N;i++) {
            ans.push_back(i);
        }
        ans=trier(ans);
        for (int i=0;i<N;i++) {
            P[ans[i]]=i+1;
        }
        return;
    }
    vector<int> deb;
    if (W==100) {
        coeff=1;
    }
    else {
        coeff=2;
    }
    for (int i=0;i<N;i++) {
        deb.push_back(i);
    }
    solve(1,N,deb);
    /*for (int i:posVal) {
        cout<<i<<" ";
    }*/
    for (int i=0;i<N;i++) {
        P[i]=posVal[i];
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 320 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 10 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 328 KB Output is correct
2 Correct 39 ms 328 KB Output is correct
3 Correct 35 ms 348 KB Output is correct
4 Correct 39 ms 340 KB Output is correct
5 Correct 43 ms 456 KB Output is correct
6 Correct 34 ms 340 KB Output is correct
7 Correct 34 ms 336 KB Output is correct
8 Correct 34 ms 336 KB Output is correct
9 Correct 34 ms 336 KB Output is correct
10 Correct 33 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 316 KB Output is correct
2 Correct 26 ms 296 KB Output is correct
3 Correct 27 ms 320 KB Output is correct
4 Correct 24 ms 320 KB Output is correct
5 Correct 24 ms 316 KB Output is correct
6 Correct 25 ms 208 KB Output is correct
7 Correct 26 ms 208 KB Output is correct
8 Correct 24 ms 208 KB Output is correct
9 Correct 24 ms 208 KB Output is correct
10 Correct 25 ms 324 KB Output is correct
11 Correct 25 ms 296 KB Output is correct
12 Correct 14 ms 320 KB Output is correct
13 Correct 24 ms 296 KB Output is correct
14 Correct 23 ms 316 KB Output is correct
15 Correct 25 ms 308 KB Output is correct
16 Correct 22 ms 208 KB Output is correct
17 Correct 22 ms 296 KB Output is correct
18 Correct 22 ms 316 KB Output is correct
19 Correct 22 ms 312 KB Output is correct
20 Correct 25 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 9 ms 336 KB Output is partially correct
2 Partially correct 8 ms 332 KB Output is partially correct
3 Partially correct 8 ms 332 KB Output is partially correct
4 Partially correct 8 ms 336 KB Output is partially correct
5 Partially correct 8 ms 460 KB Output is partially correct
6 Partially correct 8 ms 336 KB Output is partially correct
7 Partially correct 8 ms 328 KB Output is partially correct
8 Partially correct 9 ms 340 KB Output is partially correct
9 Partially correct 8 ms 336 KB Output is partially correct
10 Partially correct 8 ms 332 KB Output is partially correct
11 Partially correct 8 ms 336 KB Output is partially correct
12 Partially correct 8 ms 328 KB Output is partially correct
13 Partially correct 8 ms 336 KB Output is partially correct
14 Partially correct 8 ms 336 KB Output is partially correct
15 Partially correct 9 ms 336 KB Output is partially correct
16 Partially correct 8 ms 336 KB Output is partially correct
17 Partially correct 8 ms 336 KB Output is partially correct
18 Partially correct 8 ms 336 KB Output is partially correct
19 Partially correct 8 ms 328 KB Output is partially correct
20 Partially correct 8 ms 328 KB Output is partially correct
21 Partially correct 8 ms 336 KB Output is partially correct
22 Partially correct 8 ms 336 KB Output is partially correct
23 Partially correct 8 ms 336 KB Output is partially correct
24 Partially correct 8 ms 316 KB Output is partially correct
25 Partially correct 8 ms 324 KB Output is partially correct
26 Partially correct 9 ms 332 KB Output is partially correct
27 Partially correct 8 ms 336 KB Output is partially correct
28 Partially correct 9 ms 332 KB Output is partially correct
29 Partially correct 11 ms 392 KB Output is partially correct
30 Partially correct 11 ms 336 KB Output is partially correct
31 Partially correct 8 ms 336 KB Output is partially correct
32 Partially correct 8 ms 328 KB Output is partially correct
33 Partially correct 8 ms 336 KB Output is partially correct
34 Partially correct 8 ms 336 KB Output is partially correct
35 Partially correct 8 ms 336 KB Output is partially correct
36 Partially correct 8 ms 328 KB Output is partially correct
37 Partially correct 8 ms 336 KB Output is partially correct
38 Partially correct 8 ms 328 KB Output is partially correct
39 Partially correct 8 ms 336 KB Output is partially correct
40 Partially correct 8 ms 336 KB Output is partially correct