답안 #810511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810511 2023-08-06T10:35:38 Z oscar1f 코알라 (APIO17_koala) C++17
100 / 100
42 ms 540 KB
#include<bits/stdc++.h>
#include "koala.h"

using namespace std;

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;
    int mini=100/(fin-deb+1);
    while (fin<=mini*(mini+1)/2) {
        mini--;
    }
    for (int i=mini;i<=13;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()) {
            //cout<<deb<<" "<<fin<<" : "<<i<<endl;
            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;
    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];
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 3 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 208 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
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 324 KB Output is correct
2 Correct 40 ms 332 KB Output is correct
3 Correct 34 ms 320 KB Output is correct
4 Correct 37 ms 332 KB Output is correct
5 Correct 42 ms 320 KB Output is correct
6 Correct 38 ms 336 KB Output is correct
7 Correct 36 ms 336 KB Output is correct
8 Correct 34 ms 328 KB Output is correct
9 Correct 41 ms 324 KB Output is correct
10 Correct 39 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 208 KB Output is correct
2 Correct 26 ms 320 KB Output is correct
3 Correct 28 ms 328 KB Output is correct
4 Correct 27 ms 208 KB Output is correct
5 Correct 25 ms 208 KB Output is correct
6 Correct 25 ms 208 KB Output is correct
7 Correct 26 ms 316 KB Output is correct
8 Correct 24 ms 208 KB Output is correct
9 Correct 24 ms 208 KB Output is correct
10 Correct 28 ms 208 KB Output is correct
11 Correct 26 ms 320 KB Output is correct
12 Correct 14 ms 208 KB Output is correct
13 Correct 25 ms 316 KB Output is correct
14 Correct 23 ms 316 KB Output is correct
15 Correct 22 ms 208 KB Output is correct
16 Correct 22 ms 316 KB Output is correct
17 Correct 22 ms 316 KB Output is correct
18 Correct 22 ms 296 KB Output is correct
19 Correct 22 ms 308 KB Output is correct
20 Correct 23 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Correct 3 ms 336 KB Output is correct
5 Correct 3 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 3 ms 336 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 3 ms 336 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 3 ms 336 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 3 ms 336 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 3 ms 336 KB Output is correct
28 Correct 3 ms 336 KB Output is correct
29 Correct 3 ms 336 KB Output is correct
30 Correct 3 ms 208 KB Output is correct
31 Correct 3 ms 328 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 328 KB Output is correct
34 Correct 3 ms 336 KB Output is correct
35 Correct 3 ms 328 KB Output is correct
36 Correct 3 ms 336 KB Output is correct
37 Correct 3 ms 336 KB Output is correct
38 Correct 3 ms 208 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 3 ms 208 KB Output is correct