Submission #627358

#TimeUsernameProblemLanguageResultExecution timeMemory
627358Cross_RatioRarest Insects (IOI22_insects)C++17
53.16 / 100
156 ms1192 KiB
#include "insects.h" #include <bits/stdc++.h> using namespace std; map<int,set<int>> MS; void move_inside(int); void move_outside(int); int press_button(); int min_cardinality(int N) { int i, j; set<int> S; move_inside(0); S.insert(0); for(i=1;i<N;i++) { move_inside(i); S.insert(i); int c = press_button(); if(c >= 2) { move_outside(i); S.erase(i); } } int k = S.size(); MS[1] = S; int s = 1, e = N/k+1; if(e==s+1) return s; int mid = (s+e)/2; for(i=0;i<N;i++) { if(S.find(i)==S.end()) { move_inside(i); S.insert(i); int c = press_button(); if(c >= mid+1) { move_outside(i); S.erase(i); } if(S.size()==k*mid) break; } if(S.size()==k*mid) break; } MS[mid] = S; while(s+1<e) { int mid = (s+e)/2; if(S.size()==k*mid) { s = mid; if(mid+1>=e) break; mid = (s+e)/2; for(i=0;i<N;i++) { if(S.size()==k*mid) break; if(S.find(i)==S.end()) { move_inside(i); S.insert(i); int c = press_button(); if(c >= mid+1) { move_outside(i); S.erase(i); } if(S.size()==k*mid) break; } if(S.size()==k*mid) break; } MS[mid] = S; } else { e = mid; if(s+1>=e) break; mid = (s+e)/2; auto it = MS.upper_bound(mid); it--; set<int> S2 = it->second; for(i=0;i<N;i++) { if(S2.find(i)!=S2.end()&&S.find(i)==S.end()) { move_inside(i); S.insert(i); } if(S2.find(i)==S2.end()&&S.find(i)!=S.end()) { move_outside(i); S.erase(i); } } for(i=0;i<N;i++) { if(S.find(i)==S.end()) { move_inside(i); S.insert(i); int c = press_button(); if(c >= mid+1) { move_outside(i); S.erase(i); } if(S.size()==k*mid) break; } if(S.size()==k*mid) break; } MS[mid] = S; } } return s; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:36:24: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |             if(S.size()==k*mid) break;
      |                ~~~~~~~~^~~~~~~
insects.cpp:38:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if(S.size()==k*mid) break;
      |            ~~~~~~~~^~~~~~~
insects.cpp:43:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         if(S.size()==k*mid) {
      |            ~~~~~~~~^~~~~~~
insects.cpp:48:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
insects.cpp:57:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |                     if(S.size()==k*mid) break;
      |                        ~~~~~~~~^~~~~~~
insects.cpp:59:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
insects.cpp:89:32: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |                     if(S.size()==k*mid) break;
      |                        ~~~~~~~~^~~~~~~
insects.cpp:91:28: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   91 |                 if(S.size()==k*mid) break;
      |                    ~~~~~~~~^~~~~~~
insects.cpp:9:12: warning: unused variable 'j' [-Wunused-variable]
    9 |     int i, j;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...