Submission #1047462

# Submission time Handle Problem Language Result Execution time Memory
1047462 2024-08-07T13:21:13 Z nightfal Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
1 ms 344 KB
#include <vector>
#include <iostream>
#include <tuple>
using namespace std;
int use_machine(std::vector<int> x);

int count2(vector<int> &a, vector<int> &b, int &now, int n, int letter) {
    vector<int> m;
    int numA=0, numB=0;
    for(int i=0; i<a.size() && now < n; i++, now++) {
        m.push_back(a[i]); 
        m.push_back(now);
    }
    int result = use_machine(m);
    if (result%2) numB++; 
    else numA++;
    numB += result/2; 
    numA += m.size()/2-1-result/2;
    
    if (letter) return numA;
    else return numB;
}

void count1(vector<int> &a, vector<int> &b, int num, int n) {
    int k = min(num,n);
    for(int i=3; i+1<k;  i+=2) {
        int result = use_machine({a[0],i,a[1],i+1});
        if (result%2) b.push_back(i+1);
        else a.push_back(i+1);
        if (result/2) b.push_back(i);
        else a.push_back(i);
    }
    if (k%2==0) {
        if(use_machine({a[0],k-1})) b.push_back(k-1);
        else a.push_back(k-1);
    }
    return;
}

int count_mushrooms(int n) {
    vector<int>a, b; a.push_back(0);
    int numA=0, number1=100;

    for(int i=1; i<min(3,n); i++)
        if (use_machine({0,i})) b.push_back(i);
        else a.push_back(i);
    if (n<=3) return a.size();

    if(a.size()>=b.size()) count1(a,b,number1,n);
    else count1(b,a,number1,n);

    if (n<=100) return a.size();

    while (number1 < n-1) {
        if(a.size()>=b.size()) numA += count2(a,b,number1,n,0);
        else numA += count2(b,a,number1,n,1);
    }
    return numA;
}

Compilation message

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