Submission #628698

#TimeUsernameProblemLanguageResultExecution timeMemory
628698galcaRarest Insects (IOI22_insects)C++17
0 / 100
1 ms208 KiB
#include "insects.h" #include <vector> using namespace std; int min_cardinality(int N) { vector<int> vec1; vector<int> vec2; for (int i = 0; i < N; i++) { vec1.push_back(i); } int dir = 0; int iter = 0; int rem; int prev_num_sets; bool first = true; int max_card; do { vector<int>& src = dir ? vec2 : vec1; vector<int>& dst = dir ? vec1 : vec2; vector<int> distinct; vector<int> tmpvec1; vector<int> tmpvec2; vector<int> pos1; vector<int> pos2; for (int i = 0; i < src.size(); i++) { move_inside(src[i]); int res = press_button(); if (res != 1) { move_outside(src[i]); tmpvec1.push_back(src[i]); } else { distinct.push_back(src[i]); } } int num_sets = distinct.size(); if (num_sets == src.size()) { return 1; } // step 2: find all elements belonging to max sets //for (int i = 0; i < tmpvec1.size(); i++) { // move_inside(tmpvec1[i]); //} max_card = press_button(); //if (!first && (num_sets < prev_num_sets)) { // return iter; //} for (int i = 0; i < distinct.size(); i++) { move_outside(distinct[i]); int res = press_button(); if (res < max_card) { tmpvec2.push_back(distinct[i]); pos1.push_back(i); } else { pos2.push_back(i); } move_inside(distinct[i]); } // now we have 1 representative from every set, can remove greedily all sets in 1 shot for (int i = 0; i < pos2.size(); i++) { move_outside(distinct[pos2[i]]); } for (int i = 0; i < tmpvec1.size(); i++) { move_inside(tmpvec1[i]); int res = press_button(); if (res != 2) { dst.push_back(tmpvec1[i]); } move_outside(tmpvec1[i]); } for (int i = 0; i < pos1.size(); i++) { move_outside(pos1[i]); } for (int i = 0; i < pos2.size(); i++) { move_inside(pos2[i]); } prev_num_sets = num_sets - pos1.size(); dir ^= 1; src.erase(src.begin(), src.end()); rem = dst.size(); first = true; if (rem == 0) { return max_card; } ++iter; first = false; } while (rem > 0); return max_card; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:33:21: 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 < src.size(); i++) {
      |                   ~~^~~~~~~~~~~~
insects.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   if (num_sets == src.size()) {
      |       ~~~~~~~~~^~~~~~~~~~~~~
insects.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for (int i = 0; i < distinct.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~
insects.cpp:76:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (int i = 0; i < pos2.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
insects.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |   for (int i = 0; i < tmpvec1.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~
insects.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for (int i = 0; i < pos1.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
insects.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (int i = 0; i < pos2.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
insects.cpp:17:6: warning: variable 'prev_num_sets' set but not used [-Wunused-but-set-variable]
   17 |  int prev_num_sets;
      |      ^~~~~~~~~~~~~
insects.cpp:18:7: warning: variable 'first' set but not used [-Wunused-but-set-variable]
   18 |  bool first = true;
      |       ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...