Submission #668536

#TimeUsernameProblemLanguageResultExecution timeMemory
668536hoanghq2004Rarest Insects (IOI22_insects)C++17
50 / 100
174 ms420 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), used(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; int k = 1; for (int lg = 13; lg >= 0; --lg) { if (k + (1 << lg) > n / cnt) continue; int _k = k + (1 << lg); vector <int> a; for (int i = 0; i < n; ++i) { if (!flag[i] && !used[i]) { move_inside(i); if (press_button() >= _k) move_outside(i); else used[i] = 1, 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; } } if (ok) k = _k; else for (auto i: a) move_outside(i), used[i] = 0; } return k; } // //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; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...