Submission #630049

#TimeUsernameProblemLanguageResultExecution timeMemory
630049_Avocado_Rarest Insects (IOI22_insects)C++17
96.54 / 100
64 ms592 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; 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:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |    if(in_box.size() == m*unique_cnt){
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
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(in_box.size() != m*unique_cnt){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
insects.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    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...