Submission #1090593

# Submission time Handle Problem Language Result Execution time Memory
1090593 2024-09-18T13:35:14 Z onlk97 Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
const int Q=2;
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]=0;
    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;
    cout<<cnt0<<' '<<cnt1<<'\n';
    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=ask.size()-1-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=ask.size()-1-use_machine(ask);
            ans+=(int)ths.size()-(ret+1)/2;
        }
    }
    return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int j=0; j<ths.size(); j++){
      |                           ~^~~~~~~~~~~
mushrooms.cpp:47:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for (int j=0; j<ths.size(); j++){
      |                           ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 0 ms 344 KB Execution failed because the return code was nonzero
3 Halted 0 ms 0 KB -