Submission #584273

#TimeUsernameProblemLanguageResultExecution timeMemory
584273LucaIlieCounting Mushrooms (IOI20_mushrooms)C++17
56.64 / 100
10 ms392 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int use_machine( vector <int> x );

int count_mushrooms( int n ) {
    int k, bs, nrA, p;
    vector <int> a, s( n );

    k = min( n, max( 3, 200 ) );
    s[0] = 0;
    nrA = 1;
    for ( int i = 1; i < k; i++ ) {
        s[i] = use_machine( { 0, i } );
        nrA += (s[i] == 0);
    }

    if ( nrA > k / 2 ) {
        bs = nrA - 1;
        p = 0;
    } else {
        bs = k - nrA - 1;
        p = 1;
    }
    for ( int i = 0; i < k; i++ ) {
        if ( s[i] == p )
            a.push_back( i );
    }

    for ( int i = k; i < n; i += bs ) {
        int j;
        vector <int> m;

        for ( j = 0; j < a.size() - 1 && i + j < n; j++ ) {
            m.push_back( a[j] );
            m.push_back( i + j );
        }
        m.push_back( a.back() );

        if ( p == 0 )
            nrA += j - use_machine( m ) / 2;
        else
            nrA += use_machine( m ) / 2;
    }

    return nrA;
}

Compilation message (stderr)

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