Submission #605058

#TimeUsernameProblemLanguageResultExecution timeMemory
605058lcjCounting Mushrooms (IOI20_mushrooms)C++17
10 / 100
296 ms336 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#include "mushrooms.h"

static int aim = 2;

int count_mushrooms(int n) {
    vector<int> a;
    vector<int> b;
    a.push_back(0);
    int last;
    for (int i = 1; i < n; i++)
    {
        last = i;
        int res = use_machine({0, i});
        if (res) {
            b.push_back(i);
        }
        else {
            a.push_back(i);
        }
        if (a.size() == aim || b.size() == aim) break;
    }
    int rcount = a.size();
    int bcount = b.size();
    for (int i = last+1; i < n; i += aim-1)
    {
        vector<int> &inter = a.size() == aim ? a : b;
        vector<int> q;
        for (int j = 0; j < min(aim-1, n-i); j++)
        {
            q.push_back(inter[j]);
            q.push_back(i+j);
        }
        q.push_back(inter.back());
        int res = use_machine(q);
        if (a.size() == aim) {
            bcount += res/2;
        }
        else {
            rcount += res/2;
        }
    }
    if (a.size() == aim) {
        return n-bcount;
    }
	return rcount;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:28:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (a.size() == aim || b.size() == aim) break;
      |             ~~~~~~~~~^~~~~~
mushrooms.cpp:28:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (a.size() == aim || b.size() == aim) break;
      |                                ~~~~~~~~~^~~~~~
mushrooms.cpp:34:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         vector<int> &inter = a.size() == aim ? a : b;
      |                              ~~~~~~~~~^~~~~~
mushrooms.cpp:43:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         if (a.size() == aim) {
      |             ~~~~~~~~~^~~~~~
mushrooms.cpp:50:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     if (a.size() == aim) {
      |         ~~~~~~~~~^~~~~~
mushrooms.cpp:32:14: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     for (int i = last+1; i < n; i += aim-1)
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...