답안 #933965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933965 2024-02-26T15:41:25 Z EJIC_B_KEDAX 버섯 세기 (IOI20_mushrooms) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#include "mushrooms.h"

using ll = long long;

using namespace std;

mt19937 mt(time(nullptr));

int count_mushrooms(int n) {
    vector<int> p(n - 1);
    for (int i = 0; i < n - 1; i++) {
        p[i] = i + 1;
    }
    shuffle(p.begin(), p.end(), mt);
    vector<int> a(1, 0), b;
    int x = 0, ans = 1;
    while (x < n - 1) {
        vector<int> ask;
        if (a.size() > b.size()) {
            int ind = 0, len = -1, start = x;
            while (x < n - 1 && ind < a.size()) {
                ask.push_back(a[ind++]);
                ask.push_back(p[x++]);
                len++;
            }
            int cnt = use_machine(ask);
            if (cnt & 1) {
                b.push_back(p[x - 1]);
                cnt--;
            } else {
                a.push_back(p[x - 1]);
                ans++;
            }
            if (!cnt) {
                for (int i = start; i < x - 1; i++) {
                    ans++;
                    a.push_back(p[i]);
                }
            } else if (cnt == 2 * len) {
                for (int i = start; i < x - 1; i++) {
                    b.push_back(p[i]);
                }
            }
        } else {
            int ind = 0, len = -1, start = x;
            while (x < n - 1 && ind < b.size()) {
                ask.push_back(b[ind++]);
                ask.push_back(p[x++]);
                len++;
            }
            int cnt = use_machine(ask);
            if (cnt & 1) {
                a.push_back(p[x - 1]);
                ans++;
                cnt--;
            } else {
                b.push_back(p[x - 1]);
            }
            if (!cnt) {
                for (int i = start; i < x - 1; i++) {
                    b.push_back(p[i]);
                }
            } else if (cnt == 2 * len) {
                for (int i = start; i < x - 1; i++) {
                    a.push_back(p[i]);
                    ans++;
                }
            }
        }
    }
    return ans;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:22:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |             while (x < n - 1 && ind < a.size()) {
      |                                 ~~~~^~~~~~~~~~
mushrooms.cpp:47:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             while (x < n - 1 && ind < b.size()) {
      |                                 ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Answer is not correct.
4 Halted 0 ms 0 KB -