Submission #632554

#TimeUsernameProblemLanguageResultExecution timeMemory
632554_Avocado_Rarest Insects (IOI22_insects)C++17
0 / 100
0 ms208 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; int l = 2; int ans = 1; 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(l <= r){ int m = (r+l)/2; vector<int>high, low; for(int i = 0; i<cur.size(); ++i){ if(in_box.size() == (m-ans)*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-ans)*unique_cnt){ for(int i = 0; i<cur.size(); ++i){ move_outside(cur[i]); in_box.erase(cur[i]); } cur = low; r = m-1; } else{ cur = high; l = m+1; ans = m; } } return ans; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:33:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |    if(in_box.size() == (m-ans)*unique_cnt){
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
insects.cpp:49:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |   if(in_box.size() != (m-ans)*unique_cnt){
      |      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
insects.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    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...