Submission #1025183

# Submission time Handle Problem Language Result Execution time Memory
1025183 2024-07-16T17:12:13 Z vjudge1 Rarest Insects (IOI22_insects) C++17
0 / 100
1 ms 596 KB
#include <bits/stdc++.h>
#define ent '\n'

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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;

bool used[maxn];
vector<int> d;
int n, m, c, cnt = 0;

bool check(int x){
    x -= cnt;
    vector<int> a, b;
    for(int i=0;i<n;i++){
        if(used[i]) continue;
        move_inside(i);
        if(press_button() > x){
            move_outside(i);
            b.push_back(i);
        }
        else a.push_back(i);
    }
    if(a.size() == x * m){
        cnt += x;
        for(int x:a){
            used[x] = 1;
            c--;
        }
        return 1;
    }
    for(int x:b){
        used[x] = 1;
        c--;
    }
    return 0;
}

int min_cardinality(int N){
    n = N;
    c = n;
    for(int i=0;i<n;i++){
        move_inside(i);
        if(press_button() != 1){
            move_outside(i);
        }
        else d.push_back(i);
    }
    for(int i:d){
        move_outside(i);
    }
    m = d.size();
    int ans = 0;
    for(int l = 1, r = (c + m - 1) / m; l <= r;){
        int mid = l + r >> 1;
        if(check(mid)){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}

Compilation message

insects.cpp: In function 'bool check(int)':
insects.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |     if(a.size() == x * m){
      |        ~~~~~~~~~^~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 596 KB Wrong answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 596 KB Wrong answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong answer.
3 Halted 0 ms 0 KB -