Submission #420705

#TimeUsernameProblemLanguageResultExecution timeMemory
420705ioiCounting Mushrooms (IOI20_mushrooms)C++14
56.36 / 100
15 ms324 KiB
#include "mushrooms.h"

#include<bits/stdc++.h>

using namespace std ;

int count_mushrooms(int n) {
    int ans = 1 ;

    if (n <= 226){

        for(int i = 1 ; i < n ; i ++)
        ans += !use_machine({0 , i});

        return ans ;


    }

    vector<int> A , B ;
    A .push_back(0);


    for(int i = 1 ; i <= 226 ; i ++){
        if(!use_machine({0 , i}))A.push_back(i) , ans ++ ;
        else B.push_back(i);
    }


    if(A.size() > B.size()){


        int p = 227 ;
        while(p < n){
            vector<int> tocheck ;
            tocheck.push_back(0);
            int curr = 0 ;

            for(int i = 1 ; i < A.size() && p < n ; i ++){
                tocheck.push_back(p++);
                tocheck.push_back(A[i]);
                curr ++ ;
            }

            int c = use_machine(tocheck);

            ans += (curr - c / 2);


       }


    }

    else {
        int p = 227 ;
        while(p < n){
            vector<int> tocheck ;
            tocheck.push_back(B[0]);
            int curr = 0 ;

            for(int i = 1 ; i < B.size() && p < n ; i ++){
                tocheck.push_back(p++);
                tocheck.push_back(B[i]);
                curr ++ ;
            }

            int c = use_machine(tocheck);

            ans += c / 2;


       }


    }

    return ans ;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for(int i = 1 ; i < A.size() && p < n ; i ++){
      |                             ~~^~~~~~~~~~
mushrooms.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for(int i = 1 ; i < B.size() && p < n ; i ++){
      |                             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...