제출 #628611

#제출 시각아이디문제언어결과실행 시간메모리
628611galca드문 곤충 (IOI22_insects)C++17
25 / 100
375 ms336 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); } vector<int> distinct; for (int i = 0; i < vec1.size(); i++) { move_inside(vec1[i]); int res = press_button(); if (res != 1) { move_outside(vec1[i]); vec2.push_back(vec1[i]); } else { distinct.push_back(vec1[i]); } } int num_sets = distinct.size(); if (num_sets == N) { return 1; } for (int i = 0; i < distinct.size(); i++) { move_outside(distinct[i]); } int sqrtN = 1; for (sqrtN = 1; sqrtN*sqrtN < N; sqrtN++); if (num_sets > sqrtN) { distinct.erase(distinct.begin(), distinct.end()); vec1.erase(vec1.begin(), vec1.end()); int dir = 1; int iter = 1; while ((vec1.size() + vec2.size()) > 0) { vector<int>& src = dir ? vec2 : vec1; vector<int>& dst = dir ? vec1 : vec2; vector<int> distinct; for (int i = 0; i < src.size(); i++) { move_inside(src[i]); int res = press_button(); if (res != 1) { move_outside(src[i]); dst.push_back(src[i]); } else { distinct.push_back(src[i]); } } if (distinct.size() != num_sets) { return iter; } for (int i = 0; i < distinct.size(); i++) { move_outside(distinct[i]); } distinct.erase(distinct.begin(), distinct.end()); src.erase(src.begin(), src.end()); dir ^= 1; ++iter; } return iter; } else { int min_card = N; int dir = 0; vec2.erase(vec2.begin(), vec2.end()); while ((vec1.size() + vec2.size()) > 0) { vector<int>& src = dir ? vec2 : vec1; vector<int>& dst = dir ? vec1 : vec2; move_inside(src[0]); int size = 1; for (int i = 1; i < src.size(); i++) { move_inside(src[i]); int res = press_button(); if (res != 2) { dst.push_back(src[i]); } else { ++size; } move_outside(src[i]); } move_outside(src[0]); if (size < min_card) { min_card = size; } src.erase(src.begin(), src.end()); dir ^= 1; if (size == 1) { return 1; } } return min_card; } }

컴파일 시 표준 에러 (stderr) 메시지

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for (int i = 0; i < vec1.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
insects.cpp:32:20: 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 < distinct.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
insects.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |    for (int i = 0; i < src.size(); i++) {
      |                    ~~^~~~~~~~~~~~
insects.cpp:62:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |    if (distinct.size() != num_sets) {
      |        ~~~~~~~~~~~~~~~~^~~~~~~~~~~
insects.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for (int i = 0; i < distinct.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
insects.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |    for (int i = 1; i < src.size(); i++) {
      |                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...