답안 #742107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742107 2023-05-15T15:31:20 Z fanwen 드문 곤충 (IOI22_insects) C++17
100 / 100
64 ms 456 KB
#define ONLINE_JUDGE
#include <bits/stdc++.h>
#include "insects.h"

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()

#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

mt19937 jdg(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) { return l + jdg() % (r - l + 1); }

vector <int> insects;
int min_cardinality(int n) {
    insects.assign(n, 0); iota(ALL(insects), 0);
    shuffle(ALL(insects), jdg);
    int cnt = 0;
    vector <int> remain;
    REP(i, n) {
        move_inside(insects[i]);
        if(press_button() > 1) {
            move_outside(insects[i]);
            remain.push_back(insects[i]);
        } else cnt++;
    }
    if(cnt == 1) return n;
    if(cnt == 2) {
        REP(i, n) move_inside(insects[i]);
        return n - press_button();
    }
    int l = 2, r = n / cnt, last = 1, ans = 1;
    while(r >= l) {
        int mid = l + r >> 1;
        vector <int> new_remain, removing;
        int res = 0, id = 0;
        for (auto &x : remain) {
            ++id;
            move_inside(x);
            if(press_button() > mid) {
                move_outside(x);
                new_remain.push_back(x);
            } else res++, removing.push_back(x);
            if(res == cnt * (mid - last)) {
                FOR(i, id, (int) remain.size() - 1) new_remain.push_back(remain[i]);
                break;
            }
        }
        if(res == cnt * (mid - last)) {
            ans = last = mid;
            l = mid + 1;
            swap(remain, new_remain);
        } else {
            r = mid - 1;
            for (auto x : removing) move_outside(x);
            swap(remain, removing);
        }
    }
    return ans;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         int mid = l + r >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 336 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 6 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 7 ms 296 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 6 ms 304 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 6 ms 336 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 4 ms 208 KB Output is correct
12 Correct 6 ms 208 KB Output is correct
13 Correct 6 ms 300 KB Output is correct
14 Correct 5 ms 208 KB Output is correct
15 Correct 7 ms 296 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 6 ms 300 KB Output is correct
18 Correct 6 ms 208 KB Output is correct
19 Correct 6 ms 208 KB Output is correct
20 Correct 6 ms 304 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 2 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 19 ms 208 KB Output is correct
26 Correct 32 ms 208 KB Output is correct
27 Correct 10 ms 312 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 25 ms 284 KB Output is correct
30 Correct 28 ms 208 KB Output is correct
31 Correct 35 ms 316 KB Output is correct
32 Correct 27 ms 312 KB Output is correct
33 Correct 26 ms 336 KB Output is correct
34 Correct 20 ms 308 KB Output is correct
35 Correct 23 ms 208 KB Output is correct
36 Correct 30 ms 208 KB Output is correct
37 Correct 26 ms 296 KB Output is correct
38 Correct 21 ms 312 KB Output is correct
39 Correct 24 ms 208 KB Output is correct
40 Correct 8 ms 308 KB Output is correct
41 Correct 8 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 16 ms 316 KB Output is correct
8 Correct 20 ms 208 KB Output is correct
9 Correct 41 ms 208 KB Output is correct
10 Correct 61 ms 304 KB Output is correct
11 Correct 21 ms 312 KB Output is correct
12 Correct 27 ms 312 KB Output is correct
13 Correct 46 ms 316 KB Output is correct
14 Correct 62 ms 208 KB Output is correct
15 Correct 38 ms 312 KB Output is correct
16 Correct 64 ms 312 KB Output is correct
17 Correct 26 ms 456 KB Output is correct
18 Correct 63 ms 312 KB Output is correct
19 Correct 54 ms 308 KB Output is correct
20 Correct 38 ms 308 KB Output is correct
21 Correct 51 ms 320 KB Output is correct
22 Correct 62 ms 304 KB Output is correct
23 Correct 53 ms 300 KB Output is correct
24 Correct 35 ms 304 KB Output is correct
25 Correct 26 ms 316 KB Output is correct
26 Correct 21 ms 208 KB Output is correct
27 Correct 36 ms 312 KB Output is correct
28 Correct 46 ms 308 KB Output is correct
29 Correct 52 ms 312 KB Output is correct
30 Correct 39 ms 336 KB Output is correct
31 Correct 55 ms 316 KB Output is correct
32 Correct 63 ms 208 KB Output is correct
33 Correct 43 ms 208 KB Output is correct
34 Correct 55 ms 300 KB Output is correct
35 Correct 52 ms 308 KB Output is correct
36 Correct 49 ms 208 KB Output is correct
37 Correct 44 ms 304 KB Output is correct
38 Correct 54 ms 208 KB Output is correct
39 Correct 41 ms 320 KB Output is correct
40 Correct 47 ms 316 KB Output is correct
41 Correct 45 ms 340 KB Output is correct
42 Correct 47 ms 208 KB Output is correct
43 Correct 16 ms 208 KB Output is correct
44 Correct 51 ms 208 KB Output is correct
45 Correct 22 ms 320 KB Output is correct
46 Correct 32 ms 312 KB Output is correct
47 Correct 18 ms 312 KB Output is correct
48 Correct 34 ms 316 KB Output is correct