Submission #1070091

# Submission time Handle Problem Language Result Execution time Memory
1070091 2024-08-22T11:37:34 Z Unforgettablepl Rarest Insects (IOI22_insects) C++17
0 / 100
2000 ms 1032 KB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;

int min_cardinality(int N){
    vector<int> uniques = {0};
    move_inside(0);
    vector<bool> isCommon(N);
    vector<int> ans(N,-1);
    ans[0]=1;
    for(int i=1;i<N;i++) {
        move_inside(i);
        if(press_button()==1) {
            uniques.emplace_back(i);
            ans[i]=1;
        } else {
            move_outside(i);
            isCommon[i]=true;
        }
    }
    for(int&i:uniques)move_outside(i);
    int added = -1;
    for(int jump=1024;jump;jump/=2) {
        vector<pair<int,int>> queries;
        for(int i=0;i<N;i++)if(isCommon[i]) {
            if(ans[i]+jump>=uniques.size()-1)continue;
            if((ans[i]+1)&(jump<<1))continue;
            queries.emplace_back(ans[i]+jump,i);
        }
        sort(queries.begin(),queries.end());
        for(int i=0;i<queries.size();i++) {
            auto [x,idx] = queries[i];
            while(added<x)move_inside(uniques[++added]);
            while(added>x)move_outside(uniques[added--]);
            move_inside(idx);
            if(press_button()==1) {
                ans[idx]=x;
                int y = x+1;
                queries.emplace_back(x+((y&-y)>>1),idx);
                sort(queries.begin(), queries.end());
            }
            move_outside(idx);
        }
    }
    for(int i=0;i<N;i++)if(isCommon[i])ans[uniques[ans[i]+1]]++;
    int siz = N;
    for(int i=0;i<N;i++)if(!isCommon[i])siz=min(siz,ans[i]);
    return siz;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:26:27: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if(ans[i]+jump>=uniques.size()-1)continue;
insects.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i=0;i<queries.size();i++) {
      |                     ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 3064 ms 1032 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 3064 ms 1032 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 3027 ms 912 KB Time limit exceeded
5 Halted 0 ms 0 KB -