Submission #668530

#TimeUsernameProblemLanguageResultExecution timeMemory
668530hoanghq2004Rarest Insects (IOI22_insects)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "insects.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 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()); } int min_cardinality(int n) { vector <int> flag(n); for (int i = 0; i < n; ++i) { move_inside(i); if (press_button() == 1) flag[i] = 1; else move_outside(i); } int cnt = 0; for (int i = 0; i < n; ++i) if (flag[i]) move_outside(i), ++cnt; auto check = [&](int k) { vector <int> a; for (int i = 0; i < n; ++i) if (!flag[i]) { move_inside(i); if (press_button() >= k) move_outside(i); else a.push_back(i); } int ok = 1; for (int i = 0; i < n; ++i) { if (flag[i]) { move_inside(i); int cur = press_button(); move_outside(i); if (cur < k) { ok = 0; break; } } } for (auto i: a) move_outside(i); return ok; }; int L = 1, R = n / cnt; while (L < R) { int mid = L + R + 1 >> 1; if (check(mid)) L = mid; else R = mid - 1; } return L; } 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; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:107:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  107 |         int mid = L + R + 1 >> 1;
      |                   ~~~~~~^~~
/usr/bin/ld: /tmp/ccJrBScK.o: in function `move_inside(int)':
stub.cpp:(.text+0x0): multiple definition of `move_inside(int)'; /tmp/cc0fv1zK.o:insects.cpp:(.text+0x290): first defined here
/usr/bin/ld: /tmp/ccJrBScK.o: in function `move_outside(int)':
stub.cpp:(.text+0xe0): multiple definition of `move_outside(int)'; /tmp/cc0fv1zK.o:insects.cpp:(.text+0x510): first defined here
/usr/bin/ld: /tmp/ccJrBScK.o: in function `press_button()':
stub.cpp:(.text+0x1c0): multiple definition of `press_button()'; /tmp/cc0fv1zK.o:insects.cpp:(.text+0x200): first defined here
/usr/bin/ld: /tmp/ccJrBScK.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc0fv1zK.o:insects.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status