답안 #728700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728700 2023-04-22T21:35:54 Z grogu 드문 곤충 (IOI22_insects) C++17
100 / 100
67 ms 456 KB
#include "insects.h"
#define dbg(x) cerr<<#x<<": "<<x<<endl
#include <bits/stdc++.h>
#define ll int
#define pll pair<ll,ll>

using namespace std;
#define maxn 2005
ll n;
set<ll> s;
ll uniq = 0;
ll a[maxn];
ll F[maxn];
bool ok[maxn];
ll val[maxn];
ll cur = 0;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void add(ll i){
    if(s.find(i)!=s.end()) return;
    move_inside(a[i]);
    s.insert(i);
}
void del(ll i){
    if(s.find(i)==s.end()){
        cerr<<"out"<<endl;
        return;
    }
    move_outside(a[i]);
    s.erase(i);
}
ll get(){return press_button();}
void klir(){
    while(s.size()) del(*s.begin());
}
set<ll> newe;
bool bad[maxn];
ll f(ll x){
    if(F[x]!=-1) return F[x];
    cur = get();
    newe.clear();
    for(ll i = 0;i<n;i++){
        if(ok[i]) continue;
        add(i);
        cur = get();
        if(cur>x) del(i);
        else newe.insert(i);
        if(s.size()==uniq*x) return F[x] = s.size();
    }
    return F[x] = s.size();
}
ll min_cardinality(ll N) {
    for(ll i = 0;i<maxn;i++) F[i] = -1;
    n = N;
    for(ll i = 0;i<n;i++) a[i] = i;
    shuffle(a,a+n,rng);
    uniq = f(1);
    for(ll x : s) ok[x] = 1;
    //dbg(uniq);
    ll l = 2, r = n/uniq,mid,rez = 1;
    while(l<=r){
        mid = (l+r)/2;
        if(f(mid)==uniq*mid){
            l = mid+1,rez = mid;
            for(ll x : s) ok[x] = 1;
        }else{
            r = mid-1;
            for(ll i = 0;i<n;i++){
                if(s.find(i)==s.end()) ok[i] = 1;
                else if(!ok[i]) del(i);
            }
        }
    }
    return rez;
}
/**
6
5 8 9 5 9 9
**/

Compilation message

insects.cpp: In function 'int f(int)':
insects.cpp:47:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |         if(s.size()==uniq*x) return F[x] = s.size();
      |            ~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 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 5 ms 328 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 5 ms 324 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 328 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 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 5 ms 328 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 5 ms 324 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 7 ms 328 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 6 ms 208 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 4 ms 208 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 3 ms 336 KB Output is correct
23 Correct 19 ms 340 KB Output is correct
24 Correct 6 ms 392 KB Output is correct
25 Correct 23 ms 340 KB Output is correct
26 Correct 29 ms 344 KB Output is correct
27 Correct 22 ms 320 KB Output is correct
28 Correct 12 ms 368 KB Output is correct
29 Correct 26 ms 336 KB Output is correct
30 Correct 31 ms 320 KB Output is correct
31 Correct 25 ms 320 KB Output is correct
32 Correct 21 ms 336 KB Output is correct
33 Correct 30 ms 344 KB Output is correct
34 Correct 20 ms 328 KB Output is correct
35 Correct 15 ms 320 KB Output is correct
36 Correct 27 ms 320 KB Output is correct
37 Correct 23 ms 324 KB Output is correct
38 Correct 29 ms 336 KB Output is correct
39 Correct 24 ms 340 KB Output is correct
40 Correct 15 ms 352 KB Output is correct
41 Correct 9 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 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 34 ms 316 KB Output is correct
8 Correct 20 ms 456 KB Output is correct
9 Correct 49 ms 316 KB Output is correct
10 Correct 47 ms 360 KB Output is correct
11 Correct 54 ms 316 KB Output is correct
12 Correct 26 ms 336 KB Output is correct
13 Correct 57 ms 304 KB Output is correct
14 Correct 39 ms 336 KB Output is correct
15 Correct 67 ms 328 KB Output is correct
16 Correct 38 ms 344 KB Output is correct
17 Correct 47 ms 308 KB Output is correct
18 Correct 51 ms 304 KB Output is correct
19 Correct 45 ms 328 KB Output is correct
20 Correct 43 ms 308 KB Output is correct
21 Correct 62 ms 328 KB Output is correct
22 Correct 56 ms 396 KB Output is correct
23 Correct 41 ms 348 KB Output is correct
24 Correct 45 ms 356 KB Output is correct
25 Correct 31 ms 364 KB Output is correct
26 Correct 18 ms 388 KB Output is correct
27 Correct 47 ms 324 KB Output is correct
28 Correct 54 ms 340 KB Output is correct
29 Correct 40 ms 328 KB Output is correct
30 Correct 49 ms 328 KB Output is correct
31 Correct 53 ms 328 KB Output is correct
32 Correct 32 ms 328 KB Output is correct
33 Correct 65 ms 336 KB Output is correct
34 Correct 58 ms 328 KB Output is correct
35 Correct 46 ms 392 KB Output is correct
36 Correct 54 ms 320 KB Output is correct
37 Correct 43 ms 320 KB Output is correct
38 Correct 43 ms 312 KB Output is correct
39 Correct 45 ms 336 KB Output is correct
40 Correct 48 ms 456 KB Output is correct
41 Correct 45 ms 324 KB Output is correct
42 Correct 35 ms 396 KB Output is correct
43 Correct 10 ms 328 KB Output is correct
44 Correct 41 ms 308 KB Output is correct
45 Correct 27 ms 312 KB Output is correct
46 Correct 30 ms 392 KB Output is correct
47 Correct 30 ms 344 KB Output is correct
48 Correct 33 ms 340 KB Output is correct