답안 #1063791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063791 2024-08-18T02:38:28 Z baldwinhuang1 드문 곤충 (IOI22_insects) C++17
25 / 100
226 ms 676 KB
#include <bits/stdc++.h>

using namespace std;

void move_inside(int i);
void move_outside(int i);
int press_button();

vector<int> memo(2000, -1);

bool check(int N, int mid, int uniqueValues) {
    if (memo[mid] != -1) {
        return memo[mid];
    }
    int amountInside = 0;
    // cout << "Mid: " << mid << '\n';
    // cout << press_button() << '\n';
    vector<int> trackInside;
    for (int i = 0; i < N; i++) {
        move_inside(i);
        amountInside++;
        trackInside.push_back(i);
        int curr = press_button();
        if (curr > mid) {
            move_outside(i);
            amountInside--;
        }
        else if (curr == mid && amountInside == (uniqueValues * mid)) {
            for (auto &i: trackInside) {
                move_outside(i);
            }
            memo[mid] = true;
            return true;
        }
    }
    for (auto &i: trackInside) {
        move_outside(i);
    }
    memo[mid] = false;
    return false;
}

int min_cardinality(int N) {
    vector<int> mask(N, false);
    int uniqueValues = 0;
    for (int i = 0; i < N; i++) {
        move_inside(i);
        if (press_button() == 1) {
            mask[i] = true;
            uniqueValues++;
            continue;
        }
        else {
            move_outside(i);
        }
    }
    for (int i = 0; i < N; i++) {
        if (mask[i] == true) {
            move_outside(i);
        }
        // cout << mask[i] << ' ';
    }
    // cout << check(N, 1000, uniqueValues) << '\n';
    // cout << check(N, 500, uniqueValues) << '\n';

    int high = 2000;
    int low = 0;
    while (low <= high) {
        int mid = (high + low) / 2;
        // cout << low << ' ' << high << ' ' << mid << ' ' <<  check(N, mid, uniqueValues) << '\n';
        if (low == high) {
            return mid;
        }
        else {
            if ((check(N, mid, uniqueValues) && mid == (N)) || (check(N, mid, uniqueValues) && !check(N, mid + 1, uniqueValues))) {
                return mid;

            }
            else if (check(N, mid, uniqueValues)) {
                low = mid + 1;
            }
            else {
                high = mid;
            }
        }
    }
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:44:30: warning: control reaches end of non-void function [-Wreturn-type]
   44 |     vector<int> mask(N, false);
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 14 ms 344 KB Output is correct
7 Correct 10 ms 440 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 9 ms 344 KB Output is correct
10 Correct 10 ms 344 KB Output is correct
11 Correct 13 ms 344 KB Output is correct
12 Correct 12 ms 344 KB Output is correct
13 Correct 9 ms 344 KB Output is correct
14 Correct 17 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 10 ms 344 KB Output is correct
19 Correct 11 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 11 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 14 ms 344 KB Output is correct
7 Correct 10 ms 440 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 9 ms 344 KB Output is correct
10 Correct 10 ms 344 KB Output is correct
11 Correct 13 ms 344 KB Output is correct
12 Correct 12 ms 344 KB Output is correct
13 Correct 9 ms 344 KB Output is correct
14 Correct 17 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 10 ms 344 KB Output is correct
19 Correct 11 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 11 ms 444 KB Output is correct
23 Correct 8 ms 344 KB Output is correct
24 Correct 69 ms 344 KB Output is correct
25 Correct 81 ms 592 KB Output is correct
26 Correct 64 ms 600 KB Output is correct
27 Correct 78 ms 600 KB Output is correct
28 Correct 79 ms 592 KB Output is correct
29 Correct 73 ms 444 KB Output is correct
30 Correct 72 ms 344 KB Output is correct
31 Correct 78 ms 344 KB Output is correct
32 Correct 45 ms 344 KB Output is correct
33 Correct 72 ms 600 KB Output is correct
34 Correct 76 ms 344 KB Output is correct
35 Correct 78 ms 592 KB Output is correct
36 Correct 72 ms 424 KB Output is correct
37 Correct 57 ms 432 KB Output is correct
38 Correct 52 ms 600 KB Output is correct
39 Correct 81 ms 344 KB Output is correct
40 Correct 55 ms 600 KB Output is correct
41 Correct 82 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Partially correct 0 ms 344 KB Output is partially correct
3 Partially correct 1 ms 344 KB Output is partially correct
4 Partially correct 0 ms 344 KB Output is partially correct
5 Partially correct 0 ms 344 KB Output is partially correct
6 Partially correct 1 ms 344 KB Output is partially correct
7 Incorrect 226 ms 676 KB Wrong answer.
8 Halted 0 ms 0 KB -