답안 #1115686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115686 2024-11-20T19:14:14 Z Numberz 버섯 세기 (IOI20_mushrooms) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int count_cocaine(int n) {
    vector<int> A_count = {0};
    vector<int> B_count;
    int total = 1;

    // Handle small cases directly
    if (n <= 90) {
        int sum = 1;
        for (int i = 1; i < n; i++) {
            if (use_machine({0, i}) == 0) sum++;
        }
        return sum;
    }

    // Initial partitioning
    for (int i = 1; i <= 2; i++) {
        if (use_machine({0, i}) == 0) {
            A_count.push_back(i);
            total++;
        } else {
            B_count.push_back(i);
        }
    }

    // Efficiently partition the first 88 elements
    for (int j = 3; j < 88; j += 2) {
        int sum;
        if (A_count.size() > 1) {
            sum = use_machine({j, 0, j + 1, A_count[1]});
        } else {
            sum = use_machine({j, B_count[0], j + 1, B_count[1]});
        }

        if (sum == 3) {
            B_count.push_back(j);
            B_count.push_back(j + 1);
        } else if (sum == 2) {
            A_count.push_back(j);
            B_count.push_back(j + 1);
            total++;
        } else if (sum == 1) {
            B_count.push_back(j);
            A_count.push_back(j + 1);
            total++;
        } else {
            A_count.push_back(j);
            A_count.push_back(j + 1);
            total += 2;
        }
    }

    // Process remaining elements
    int i = 89;
    while (i < n) {
        vector<int> temp;
        int d = 0;

        // Use the smaller group to minimize calls
        if (A_count.size() >= B_count.size()) {
            while (i < n && d < A_count.size()) {
                temp.push_back(i);
                temp.push_back(A_count[d]);
                i++;
                d++;
            }
            int sum = use_machine(temp);
            if (sum % 2 == 1) {
                B_count.push_back(temp[0]);
            } else {
                A_count.push_back(temp[0]);
            }
            total += (temp.size() / 2 - ((sum + 1) / 2));
        } else {
            while (i < n && d < B_count.size()) {
                temp.push_back(i);
                temp.push_back(B_count[d]);
                i++;
                d++;
            }
            int sum = use_machine(temp);
            if (sum % 2 == 1) {
                A_count.push_back(temp[0]);
            } else {
                B_count.push_back(temp[0]);
            }
            total += ((sum + 1) / 2);
        }
    }

    return total;
}

Compilation message

mushrooms.cpp: In function 'int count_cocaine(int)':
mushrooms.cpp:14:17: error: 'use_machine' was not declared in this scope
   14 |             if (use_machine({0, i}) == 0) sum++;
      |                 ^~~~~~~~~~~
mushrooms.cpp:21:13: error: 'use_machine' was not declared in this scope
   21 |         if (use_machine({0, i}) == 0) {
      |             ^~~~~~~~~~~
mushrooms.cpp:33:19: error: 'use_machine' was not declared in this scope
   33 |             sum = use_machine({j, 0, j + 1, A_count[1]});
      |                   ^~~~~~~~~~~
mushrooms.cpp:35:19: error: 'use_machine' was not declared in this scope
   35 |             sum = use_machine({j, B_count[0], j + 1, B_count[1]});
      |                   ^~~~~~~~~~~
mushrooms.cpp:64:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             while (i < n && d < A_count.size()) {
      |                             ~~^~~~~~~~~~~~~~~~
mushrooms.cpp:70:23: error: 'use_machine' was not declared in this scope
   70 |             int sum = use_machine(temp);
      |                       ^~~~~~~~~~~
mushrooms.cpp:78:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             while (i < n && d < B_count.size()) {
      |                             ~~^~~~~~~~~~~~~~~~
mushrooms.cpp:84:23: error: 'use_machine' was not declared in this scope
   84 |             int sum = use_machine(temp);
      |                       ^~~~~~~~~~~