Submission #1065941

# Submission time Handle Problem Language Result Execution time Memory
1065941 2024-08-19T13:21:47 Z vjudge1 Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
1 ms 432 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

set<int> A, B; /// indici despre care stim sigur ca sunt A sau B
int nra = 0;
set<int> PozRamase;

int get_poz() {
    int u = *PozRamase.begin();
    PozRamase.erase(u);
    return u;
}

int get_k() {
    int lm = max(A.size(), B.size());
    return lm;
}

int do_query(vi poz, vi weight) {
    int len = int(poz.size());
    int cul;
    vi P;
    if(A.size() > B.size()) {
        copy(A.begin(), A.end(), back_inserter(P));
        cul = 0;
    }
    else {
        copy(B.begin(), B.end(), back_inserter(P));
        cul = 1;
    }
    vi poz1, poz2;
    for(int i = 0; i < len; ++i)
        if(weight[i] == 1) poz1.push_back(poz[i]);
        else if(weight[i] == 2) poz2.push_back(poz[i]);
    vi QRY;
    int valmax = poz2.size() * 2 + poz1.size();
    if(!poz1.empty()) {
        QRY.push_back(poz1.back());
        poz1.pop_back();
    }
    QRY.push_back(P.back());
    P.pop_back();
    for(auto it : poz2) {
        QRY.push_back(it);
        QRY.push_back(P.back());
        P.pop_back();
    }
    if(!poz1.empty()) {
        QRY.push_back(poz1.back());
        poz1.pop_back();
    }
    int nr = use_machine(QRY);
    if(cul) nr = valmax - nr;
    return nr;
}

void op1() {
    if(PozRamase.empty()) return;
    if(PozRamase.size() == 1 || get_k() == 1) {
        int nou = get_poz();
        int tip = use_machine(vi{0, nou});
        if(!tip) A.insert(nou), ++nra;
        else B.insert(nou);
        return;
    }

    int nou1 = get_poz(), nou2 = get_poz();

    int nr = do_query(vi{nou1, nou2}, vi{1, 2});

    if(nr & 1) B.insert(nou2);
    else A.insert(nou2), ++nra;
    
    if(nr & 2) B.insert(nou1);
    else A.insert(nou1), ++nra;
}

void op1_improved(int q) {

}

void op2() {
    if(PozRamase.size() < 2) {
        op1();
        return;
    }
    int cul = 0;
    vi P;
    vi Noi;
    if(A.size() > B.size()) {
        copy(A.begin(), A.end(), back_inserter(P));
        cul = 0;
    }
    else {
        copy(B.begin(), B.end(), back_inserter(P));
        cul = 1;
    }
    while(PozRamase.size() > 1 && P.size() >= Noi.size() + 2) {
        Noi.push_back(get_poz());
    }
    P.resize(Noi.size() + 1);
    vi QRY;
    for(int i = 0; i < P.size(); ++i) {
        if(i) QRY.push_back(Noi[i - 1]);
        QRY.push_back(P[i]);
    }
    int ultp = get_poz();
    QRY.push_back(ultp);

    int nr = use_machine(QRY);

    int cul_ult = (nr & 1) ^ cul;
    if(!cul_ult) A.insert(ultp), ++nra;
    else B.insert(ultp);

    nr /= 2;

    if(!cul) nr = Noi.size() - nr;
    nra += nr;
    ///and that's about it;
}

int count_mushrooms(int n) {
    A.insert(0);
    nra = 1;
    for(int i = 1; i < n; ++i) {
        PozRamase.insert(i);
    }
    for(int i = 0; i < 160; ++i)
        op1();
    while(!PozRamase.empty()) op2();
    return nra;
}

Compilation message

mushrooms.cpp: In function 'void op2()':
mushrooms.cpp:107:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for(int i = 0; i < P.size(); ++i) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 0 ms 344 KB Answer is not correct.
5 Halted 0 ms 0 KB -