Submission #632560

#TimeUsernameProblemLanguageResultExecution timeMemory
632560_Avocado_Rarest Insects (IOI22_insects)C++17
96.45 / 100
56 ms428 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; for(int i = 0; i<n; ++i){ if(!unique[i]) cur.push_back(i); } random_shuffle(cur.begin(), cur.end()); while(l <= r){ int m = (r+l)/2; vector<int>high, low; for(int i = 0; i<cur.size(); ++i){ if(low.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]); } } if(low.size() != (m-ans)*unique_cnt){ for(int i = 0; i<cur.size(); ++i){ move_outside(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:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for(int i = 0; i<cur.size(); ++i){
      |                  ~^~~~~~~~~~~
insects.cpp:34:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |    if(low.size() == (m-ans)*unique_cnt){
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
insects.cpp:49:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |   if(low.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...