Submission #1074284

#TimeUsernameProblemLanguageResultExecution timeMemory
1074284TheQuantiX버섯 세기 (IOI20_mushrooms)C++17
68.69 / 100
7 ms600 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"

using namespace std;
using ll = long long;

constexpr ll C = 142;

ll n, m, q, k, x, y, a, b, c;

int count_mushrooms(int n) {
    mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
    vector<int> va(1, 0), vb;
    deque<int> left;
    for (int i = 1; i < n; i++) {
        left.push_back(i);
    }
    for (int i = 0; i < n - 1; i++) {
        swap(left[i], left[gen() % (i + 1)]);
    }
    while (max(va.size(), vb.size()) < C && !left.empty()) {
        if (left.size() == 1) {
            if (use_machine({0, left[0]}) == 0) {
                va.push_back(left[0]);
            }
            else {
                vb.push_back(left[0]);
            }
            left.pop_front();
        }
        else {
            int x = left[0];
            int y = left[1];
            left.pop_front();
            left.pop_front();
            if (gen() % 2) {
                swap(x, y);
            }
            ll num = use_machine({0, x, y});
            if (num == 0) {
                va.push_back(x);
                va.push_back(y);
            }
            else if (num == 2) {
                vb.push_back(x);
                va.push_back(y);
            }
            else {
                left.push_back(x);
                vb.push_back(y);
            }
        }
    }
    int ans = va.size();
    if (va.size() > vb.size()) {
        while (!left.empty()) {
            vector<int> vec;
            ll cnt = 0;
            while (!left.empty() && cnt != va.size()) {
                vec.push_back(va[cnt]);
                vec.push_back(left[0]);
                cnt++;
                left.pop_front();
            }
            ll num = use_machine(vec);
            ans += cnt - (num + 1) / 2;
        }
    }
    else {
        while (!left.empty()) {
            vector<int> vec;
            ll cnt = 0;
            while (!left.empty() && cnt != vb.size()) {
                vec.push_back(vb[cnt]);
                vec.push_back(left[0]);
                cnt++;
                left.pop_front();
            }
            ll num = use_machine(vec);
            ans += (num + 1) / 2;
        }
    }
    return ans;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:59:41: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             while (!left.empty() && cnt != va.size()) {
      |                                     ~~~~^~~~~~~~~~~~
mushrooms.cpp:73:41: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             while (!left.empty() && cnt != vb.size()) {
      |                                     ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...