답안 #848563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
848563 2023-09-12T22:10:51 Z Itamar 드문 곤충 (IOI22_insects) C++17
0 / 100
2000 ms 600 KB
#include <cassert>
#include <cstdio>
#include <insects.h>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
#define vi vector<int>
#include <random>
/*
 int kMaxQueries = 40000;

static int N;
// Insect types are compressed to colors in the range [0, N).
static std::vector<int> color;
static std::vector<bool> in_box;

static std::vector<int> color_occurrences;
static std::multiset<int> max_occurrences;

static std::vector<int> op_counter(3, 0);

static inline void protocol_violation(std::string message) {
    printf("Protocol Violation: %s\n", message.c_str());
    exit(0);
}

void move_inside(int i) {
    if (i < 0 || i >= N) {
        protocol_violation("invalid parameter");
    }
    ++op_counter[0];
    if (op_counter[0] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    if (!in_box[i]) {
        in_box[i] = true;
        max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
        ++color_occurrences[color[i]];
        max_occurrences.insert(color_occurrences[color[i]]);
    }
}

void move_outside(int i) {
    if (i < 0 || i >= N) {
        protocol_violation("invalid parameter");
    }
    ++op_counter[1];
    if (op_counter[1] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    if (in_box[i]) {
        in_box[i] = false;
        max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
        --color_occurrences[color[i]];
        max_occurrences.insert(color_occurrences[color[i]]);
    }
}

int press_button() {
    ++op_counter[2];
    if (op_counter[2] > kMaxQueries) {
        protocol_violation("too many calls");
    }
    return *(max_occurrences.rbegin());
}

*/



int min_cardinality(int N) {
    int sum = 0;
    vector<bool> in(N);
    for (int i = 0; i < N; i++) {
        move_inside(i);
        sum++;
        in[i] = 1;
        if (press_button() > 1) {
            move_outside(i);
            sum--;
            in[i] = 0;
        }
    }
    const int n = N;
    const int num = sum;

    //int cur = 1;

    int s = 1, e = N / num;
    vi col_siz(N);
    vi my_col(N, -1);
    vi good;
    for (int i = 0; i < n; i++)if (in[i])good.push_back(i);
    if (num <= 5) {
        for (int i = 0; i < n; i++) {
            if (in[i]) {
                my_col[i] = i;
                col_siz[i]++;
                move_outside(i);
            }
        }
        for (int i = 0; i < n; i++) {
            if (!in[i]) {
                move_inside(i);
                random_shuffle(good.begin(), good.end());
                for(int j : good){
                        move_inside(j);
                        if (press_button() == 2) {
                            my_col[i] = j;
                            col_siz[j]++;
                            move_outside(j);
                            move_outside(i);
                            break;
                        }
                        move_outside(j);
                }
                
            }
        }
        int mini = 1e9;
        for (int i = 0; i < n; i++) {
            if (col_siz[i] > 0 && col_siz[i] < mini) {
                mini = col_siz[i];
            }
        }
        return mini;
    }
    else {
        while (s != e) {
            int mid = (4 * s + 1 * e + 3) / 5;
            vi ne;
            for (int i = 0; i < n; i++) {
                if (!in[i]) {
                    move_inside(i);
                    if (press_button() > mid) {
                        move_outside(i);
                    }
                    else {
                        in[i] = 1;
                        ne.push_back(i);
                        sum++;
                    }
                }
                if (sum == mid * num)break;
                if (sum + n - i - 1 < mid * num)break;
            }
            if (sum == mid * num) {
                s = mid;
            }
            else {
                e = mid - 1;

                for (int x : ne) {
                    move_outside(x);
                    sum--;
                    in[x] = 0;
                }
            }
        }

        return s;
    }
}

Compilation message

insects.cpp:9: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    9 | #pragma warning(disable : 4996)
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Execution timed out 3008 ms 600 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Execution timed out 3008 ms 600 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Partially correct 0 ms 344 KB Output is partially correct
7 Correct 22 ms 400 KB Output is correct
8 Correct 9 ms 396 KB Output is correct
9 Execution timed out 3095 ms 592 KB Time limit exceeded
10 Halted 0 ms 0 KB -