제출 #630155

#제출 시각아이디문제언어결과실행 시간메모리
630155nextgenxing드문 곤충 (IOI22_insects)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define F0R(i, n) for(int i = 0; i < (n); i++) #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define F0Rd(i, n) for(int i = (n)-1; i >= 0; i--) #define FORd(i, a, b) for(int i = (b)-1; i >= (a); i--) #define ff first #define ss second const int MAX_N = 2e5+5; const ll MOD = 1e9+7; //#define LOCAL #ifdef LOCAL static inline constexpr int kMaxQueries = 40000; static int N; // Insect types are compressed to colors in the range [0, N). static std::vector<int> color; static std::vector<bool> in_box; static std::vector<int> color_occurrences; static std::multiset<int> max_occurrences; static std::vector<int> op_counter(3, 0); static inline void protocol_violation(std::string message) { printf("Protocol Violation: %s\n", message.c_str()); exit(0); } void move_inside(int i) { if (i < 0 || i >= N) { protocol_violation("invalid parameter"); } ++op_counter[0]; if (op_counter[0] > kMaxQueries) { protocol_violation("too many calls"); } if (!in_box[i]) { in_box[i] = true; max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); ++color_occurrences[color[i]]; max_occurrences.insert(color_occurrences[color[i]]); } } void move_outside(int i) { if (i < 0 || i >= N) { protocol_violation("invalid parameter"); } ++op_counter[1]; if (op_counter[1] > kMaxQueries) { protocol_violation("too many calls"); } if (in_box[i]) { in_box[i] = false; max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); --color_occurrences[color[i]]; max_occurrences.insert(color_occurrences[color[i]]); } } int press_button() { ++op_counter[2]; if (op_counter[2] > kMaxQueries) { protocol_violation("too many calls"); } return *(max_occurrences.rbegin()); } #endif int n, colors; bool check(int x){ vector<int> inserted; F0R(i, n){ move_inside(i); if(press_button() > x) move_outside(i); else inserted.push_back(i); } int num1 = inserted.size(); for(auto x : inserted) move_outside(x); if(num1 == x*colors) return true; else return false; } int min_cardinality(int N){ n = N; vector<int> inserted, non; F0R(i, n){ move_inside(i); if(press_button() > 1) move_outside(i), non.push_back(i); else inserted.push_back(i); } colors = inserted.size(); inserted.clear(); bool f = 0; int l = 0, r = n+1; while(l+1 < r){ int m = (l+r)/2; if(!f){ vector<int> b; inserted.clear(); for(auto x : non){ move_inside(x); if(press_button() > m) move_outside(x), b.push_back(x); else inserted.push_back(x); } non = b; } else{ non.clear(); for(auto x : inserted) move_outside(x); vector<int> a; for(auto x : inserted){ move_inside(x); if(press_button() > m) move_outside(x), non.push_back(x); else a.push_back(x); } inserted = a; } int num1 = inserted.size(); if(num1 == (m-1)*colors) l = m, f = 0; else r = m, f = 1; } return l; } #ifdef LOCAL int main() { assert(1 == scanf("%d", &N)); color.resize(N); in_box.assign(N, false); std::map<int, int> type_to_color; for (int i = 0; i < N; ++i) { int Ti; assert(1 == scanf("%d", &Ti)); if (type_to_color.find(Ti) == type_to_color.end()) { int new_color = type_to_color.size(); type_to_color[Ti] = new_color; max_occurrences.insert(0); } color[i] = type_to_color[Ti]; } color_occurrences.assign(type_to_color.size(), 0); int answer = min_cardinality(N); int Q = *std::max_element(op_counter.begin(), op_counter.end()); printf("%d\n", answer); printf("%d\n", Q); return 0; } #endif

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

insects.cpp: In function 'bool check(int)':
insects.cpp:84:9: error: 'move_inside' was not declared in this scope
   84 |         move_inside(i);
      |         ^~~~~~~~~~~
insects.cpp:85:12: error: 'press_button' was not declared in this scope
   85 |         if(press_button() > x) move_outside(i);
      |            ^~~~~~~~~~~~
insects.cpp:85:32: error: 'move_outside' was not declared in this scope
   85 |         if(press_button() > x) move_outside(i);
      |                                ^~~~~~~~~~~~
insects.cpp:89:28: error: 'move_outside' was not declared in this scope
   89 |     for(auto x : inserted) move_outside(x);
      |                            ^~~~~~~~~~~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:98:9: error: 'move_inside' was not declared in this scope
   98 |         move_inside(i);
      |         ^~~~~~~~~~~
insects.cpp:99:12: error: 'press_button' was not declared in this scope
   99 |         if(press_button() > 1) move_outside(i), non.push_back(i);
      |            ^~~~~~~~~~~~
insects.cpp:99:32: error: 'move_outside' was not declared in this scope
   99 |         if(press_button() > 1) move_outside(i), non.push_back(i);
      |                                ^~~~~~~~~~~~
insects.cpp:112:17: error: 'move_inside' was not declared in this scope
  112 |                 move_inside(x);
      |                 ^~~~~~~~~~~
insects.cpp:113:20: error: 'press_button' was not declared in this scope
  113 |                 if(press_button() > m) move_outside(x), b.push_back(x);
      |                    ^~~~~~~~~~~~
insects.cpp:113:40: error: 'move_outside' was not declared in this scope
  113 |                 if(press_button() > m) move_outside(x), b.push_back(x);
      |                                        ^~~~~~~~~~~~
insects.cpp:119:36: error: 'move_outside' was not declared in this scope
  119 |             for(auto x : inserted) move_outside(x);
      |                                    ^~~~~~~~~~~~
insects.cpp:122:17: error: 'move_inside' was not declared in this scope
  122 |                 move_inside(x);
      |                 ^~~~~~~~~~~
insects.cpp:123:20: error: 'press_button' was not declared in this scope
  123 |                 if(press_button() > m) move_outside(x), non.push_back(x);
      |                    ^~~~~~~~~~~~
insects.cpp:123:40: error: 'move_outside' was not declared in this scope
  123 |                 if(press_button() > m) move_outside(x), non.push_back(x);
      |                                        ^~~~~~~~~~~~