Submission #884757

# Submission time Handle Problem Language Result Execution time Memory
884757 2023-12-08T11:18:13 Z weajink Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
int znajdz_czarny(int n){
    int p = 1;
    int k = n;
    int s;
    while (p < k){
        s = (p+k)/2;
        vector<int> zap;
        for (int i = 0; i <= s; i++) zap.push_back(i);
        if (!use_machine(zap)) p = s+1;
        else{
            k = s;
        }
    }
    s = (p+k)/2;
    return s;
}
int count_mushrooms(int n){
    vector<int> znane[2];
    znane[0].push_back(0);
    int czarny = znajdz_czarny(n);
    if (czarny == n) return n;
    znane[1].push_back(czarny);
    int ile[2];
    ile[0] = 1;
    ile[1] = 1;
    int akt = 1;
    while (akt < n){
        bool better = (znane[0].size()<znane[1].size());
        int pt = 0;
        vector<int> zap;
        for (; akt < n && pt < znane[better].size(); pt++){
            zap.push_back(znane[better][pt]);
            zap.push_back(akt);
            akt++;
            if (akt == czarny) akt++;
        }
        int wy = use_machine(zap);
        if (wy%2) znane[!better].push_back(akt-1);
        else znane[better].push_back(akt-1);
        ile[better] += pt-(wy+1)/2;
        ile[!better] += (wy+1)/2;
    }
    return ile[0];
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:40:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (; akt < n && pt < znane[better].size(); pt++){
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Duplicate value 1 in the query array.
3 Halted 0 ms 0 KB -