Submission #630047

#TimeUsernameProblemLanguageResultExecution timeMemory
630047_Avocado_Rarest Insects (IOI22_insects)C++17
96.54 / 100
61 ms432 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; int min_cardinality(int n){ vector<int>unique(n); int unique_cnt = 0; for(int i = 0; i<n; ++i){ move_inside(i); int q = press_button(); if(q == 1){ unique[i] = 1; ++unique_cnt; } else move_outside(i); } int r = n/unique_cnt+1; int l = 0; vector<int>cur; set<int>in_box; for(int i = 0; i<n; ++i){ if(!unique[i]) cur.push_back(i); else in_box.insert(i); } while(r-l > 1){ int m = (r+l)/2; //cout<<"m "<<m<<endl; vector<int>high, low; for(int i = 0; i<cur.size(); ++i){ if(in_box.size() == m*unique_cnt){ high.push_back(cur[i]); continue; } move_inside(cur[i]); int q = press_button(); if(q > m){ high.push_back(cur[i]); move_outside(cur[i]); } else{ low.push_back(cur[i]); in_box.insert(cur[i]); } } if(in_box.size() != m*unique_cnt){ for(int i = 0; i<cur.size(); ++i){ move_outside(cur[i]); in_box.erase(cur[i]); } cur = low; r = m; } else{ cur = high; l = m; } } return l; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |    if(in_box.size() == m*unique_cnt){
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:48:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |   if(in_box.size() != m*unique_cnt){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for(int i = 0; i<cur.size(); ++i){
      |                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...