답안 #1074330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074330 2024-08-25T09:45:51 Z c2zi6 드문 곤충 (IOI22_insects) C++17
47.5 / 100
172 ms 1264 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "insects.h"

mt19937 rng;
VI rngind;
void movein(int i) {
    move_inside(rngind[i]);
}
void moveout(int i) {
    move_outside(rngind[i]);
}

int n, D;

int solution1() {
    VI vis(n);
    int ans = 2e9;
    replr(i, 0, n-1) if (!vis[i]) {
        vis[i] = true;
        movein(i);
        int cnt = 1;
        replr(j, i+1, n-1) if (!vis[j]) {
            movein(j);
            if (press_button() == 2) {
                vis[j] = true;
                cnt++;
            }
            moveout(j);
        }
        setmin(ans, cnt);
        moveout(i);
    }
    return ans;
}
int solution2() {
    VI vis(n);
    int k = -1;
    int ans = 0;
    replr(i, 0, n-1) if (!vis[i]) {
        vis[i] = true;
        movein(i);
        VI a;
        a.pb(i);
        replr(j, i+1, n-1) if (!vis[j]) {
            movein(j);
            if (press_button() == 2) {
                moveout(j);
            } else {
                vis[j] = true;
                a.pb(j);
            }
        }
        for (int i : a) moveout(i);
        if (k == -1) {
            k = a.size();
        } else if (a.size() != k) break;
        ans++;
    }
    return ans;
}

bool check(int k) {
    // is answer >= k
    VI a;
    rep(i, n) {
        movein(i);
        if (press_button() > k) moveout(i);
        else a.pb(i);
    }
    bool ret = (a.size() == D * k);
    for (int i : a) moveout(i);
    return ret;
}

int min_cardinality(int N) {
    rng = mt19937(chrono::steady_clock().now().time_since_epoch().count());
    n = N;
    rngind = VI(n);
    rep(i, n) rngind[i] = i;
    /*shuffle(all(rngind), rng);*/
    if (true) {
        movein(0);
        VI a;
        a.pb(0);
        replr(j, 1, n-1) {
            movein(j);
            if (press_button() == 2) moveout(j);
            else a.pb(j);
        }
        for (int i : a) moveout(i);
        D = a.size();
    }

    /*cout << D << endl;*/
    /*replr(k, 0, n-1) cout << check(k) << " ";*/
    /*cout << endl;*/
    
    int l = 1, r = n+1;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m)) l = m;
        else r = m;
    }
    return l;

    if (D < sqrt(n)) return solution1();
    return solution2();


    return -1;

}







Compilation message

insects.cpp: In function 'int solution2()':
insects.cpp:86:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |         } else if (a.size() != k) break;
      |                    ~~~~~~~~~^~~~
insects.cpp: In function 'bool check(int)':
insects.cpp:100:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |     bool ret = (a.size() == D * k);
      |                 ~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 10 ms 600 KB Output is correct
7 Correct 12 ms 344 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 10 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 12 ms 440 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 7 ms 440 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 15 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 10 ms 600 KB Output is correct
22 Correct 11 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 10 ms 600 KB Output is correct
7 Correct 12 ms 344 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 10 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 12 ms 440 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 7 ms 440 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 15 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 10 ms 600 KB Output is correct
22 Correct 11 ms 344 KB Output is correct
23 Correct 68 ms 344 KB Output is correct
24 Correct 50 ms 344 KB Output is correct
25 Correct 52 ms 600 KB Output is correct
26 Correct 70 ms 600 KB Output is correct
27 Correct 62 ms 444 KB Output is correct
28 Correct 69 ms 688 KB Output is correct
29 Correct 63 ms 444 KB Output is correct
30 Correct 56 ms 344 KB Output is correct
31 Correct 54 ms 700 KB Output is correct
32 Correct 56 ms 344 KB Output is correct
33 Correct 70 ms 344 KB Output is correct
34 Correct 55 ms 344 KB Output is correct
35 Correct 59 ms 600 KB Output is correct
36 Correct 68 ms 344 KB Output is correct
37 Correct 68 ms 600 KB Output is correct
38 Correct 64 ms 596 KB Output is correct
39 Correct 58 ms 344 KB Output is correct
40 Correct 61 ms 428 KB Output is correct
41 Correct 51 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Partially correct 1 ms 344 KB Output is partially correct
7 Partially correct 152 ms 448 KB Output is partially correct
8 Partially correct 157 ms 580 KB Output is partially correct
9 Partially correct 168 ms 1264 KB Output is partially correct
10 Partially correct 146 ms 936 KB Output is partially correct
11 Partially correct 134 ms 344 KB Output is partially correct
12 Partially correct 131 ms 456 KB Output is partially correct
13 Partially correct 155 ms 444 KB Output is partially correct
14 Partially correct 147 ms 660 KB Output is partially correct
15 Partially correct 143 ms 936 KB Output is partially correct
16 Partially correct 168 ms 444 KB Output is partially correct
17 Partially correct 150 ms 936 KB Output is partially correct
18 Partially correct 161 ms 648 KB Output is partially correct
19 Partially correct 163 ms 688 KB Output is partially correct
20 Partially correct 164 ms 688 KB Output is partially correct
21 Partially correct 148 ms 672 KB Output is partially correct
22 Partially correct 153 ms 460 KB Output is partially correct
23 Partially correct 128 ms 592 KB Output is partially correct
24 Partially correct 138 ms 656 KB Output is partially correct
25 Partially correct 148 ms 440 KB Output is partially correct
26 Partially correct 146 ms 880 KB Output is partially correct
27 Partially correct 159 ms 904 KB Output is partially correct
28 Partially correct 146 ms 680 KB Output is partially correct
29 Partially correct 147 ms 900 KB Output is partially correct
30 Partially correct 151 ms 596 KB Output is partially correct
31 Partially correct 155 ms 684 KB Output is partially correct
32 Partially correct 141 ms 848 KB Output is partially correct
33 Partially correct 170 ms 876 KB Output is partially correct
34 Partially correct 142 ms 684 KB Output is partially correct
35 Partially correct 145 ms 688 KB Output is partially correct
36 Partially correct 172 ms 1124 KB Output is partially correct
37 Partially correct 146 ms 664 KB Output is partially correct
38 Partially correct 161 ms 552 KB Output is partially correct
39 Partially correct 139 ms 1116 KB Output is partially correct
40 Partially correct 157 ms 888 KB Output is partially correct
41 Partially correct 147 ms 1064 KB Output is partially correct
42 Partially correct 140 ms 688 KB Output is partially correct
43 Partially correct 27 ms 344 KB Output is partially correct
44 Partially correct 150 ms 424 KB Output is partially correct
45 Partially correct 164 ms 664 KB Output is partially correct
46 Partially correct 132 ms 696 KB Output is partially correct
47 Partially correct 133 ms 688 KB Output is partially correct
48 Partially correct 140 ms 940 KB Output is partially correct