Submission #1090590

# Submission time Handle Problem Language Result Execution time Memory
1090590 2024-09-18T13:30:49 Z onlk97 Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
1 ms 444 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
const int Q=186;
int count_mushrooms(int n){
    if (n<=Q+1){
        vector <int> v(n);
        v[0]=0;
        for (int i=1; i<n; i++){
            int tp=use_machine({i-1,i});
            if (tp) v[i]=v[i-1]^1;
            else v[i]=v[i-1];
        }
        return count(v.begin(),v.end(),0);
    }
    vector <int> v(Q+1);
    v[0]=1;
    for (int i=1; i<=Q; i++){
        int tp=use_machine({i-1,i});
        if (tp) v[i]=v[i-1]^1;
        else v[i]=v[i-1];
    }
    int cnt0=count(v.begin(),v.end(),0),cnt1=count(v.begin(),v.end(),1);
    int ans=cnt0;
    if (cnt0>=cnt1){
        vector <int> pos;
        for (int i=0; i<=Q; i++) if (!v[i]) pos.push_back(i);
        for (int i=Q+1; i<n; i+=pos.size()){
            vector <int> ths;
            for (int j=i; j<min(n,i+(int)pos.size()); j++) ths.push_back(j);
            vector <int> ask;
            for (int j=0; j<ths.size(); j++){
                ask.push_back(pos[j]);
                ask.push_back(ths[j]);
            }
            int ret=use_machine(ask);
            ans+=(ret+1)/2;
        }
    } else {
        vector <int> pos;
        for (int i=0; i<=Q; i++) if (v[i]) pos.push_back(i);
        for (int i=Q+1; i<n; i+=pos.size()){
            vector <int> ths;
            for (int j=i; j<min(n,i+(int)pos.size()); j++) ths.push_back(j);
            vector <int> ask;
            for (int j=0; j<ths.size(); j++){
                ask.push_back(pos[j]);
                ask.push_back(ths[j]);
            }
            int ret=use_machine(ask);
            ans+=(int)ths.size()-(ret+1)/2;
        }
    }
    return ans;
}

Compilation message

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