Submission #711163

#TimeUsernameProblemLanguageResultExecution timeMemory
711163PoonYaPat드문 곤충 (IOI22_insects)C++17
100 / 100
66 ms308 KiB
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
 
queue<int> out,in,temp,temp2;
int type;
 
int min_cardinality(int n) {
    for (int i=0; i<n; ++i) {
        move_inside(i);
        if (press_button()>1) move_outside(i), out.push(i);
        else ++type, in.push(i);
    }
 
    int l=1,r=n/type;
    int cnt=0;
    while (l<r) {
            ++cnt;
            assert(cnt<12);
        int mid=(l+r+1)/2;
        //check whether ans is less than mid or not
 
        while (!out.empty()) {
            move_inside(out.front());
 
            if (press_button()>mid) move_outside(out.front()), temp2.push(out.front());
            else temp.push(out.front());
            out.pop();
 
            if (in.size()+temp.size()==type*mid) break;
        }
        while (!temp2.empty()) {
            out.push(temp2.front());
            temp2.pop();
        }
 
        if (in.size()+temp.size()==type*mid) {
            l=mid;
            while (!temp.empty()) {
                in.push(temp.front());
                temp.pop();
            }
        } else {
            r=mid-1;
            while (!out.empty()) out.pop();
            while (!temp.empty()) {
                out.push(temp.front());
                move_outside(temp.front());
                temp.pop();
            }
        }
    }
    return l;
}

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:30:38: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |             if (in.size()+temp.size()==type*mid) break;
      |                 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
insects.cpp:37:34: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         if (in.size()+temp.size()==type*mid) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...