이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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> s, root(n);
for (int i = 0; i < n; ++i) {
move_inside(i);
if (press_button() == 1) s.push_back(i), ++root[i];
else move_outside(i);
}
auto calc = [&]() {
int ans = n;
for (int i = 0; i < n; ++i)
if (root[i]) ans = min(ans, root[i]);
return ans;
};
vector <int> a;
for (int i = 0; i < n; ++i) if (!root[i]) a.push_back(i);
function <void(int, int, vector <int>)> divide = [&](int L, int R, vector <int> a) {
if (L > R || a.empty()) return;
int flag = 1;
int cur = calc();
for (int i = L; i <= R; ++i) if (root[s[i]] - (R - L + 1) < cur) flag = 0;
if (flag) return;
if (L == R) {
for (auto x: a) ++root[s[L]];
return;
}
int mid = L + R >> 1;
for (int i = mid + 1; i <= R; ++i) move_outside(s[i]);
vector <int> l, r;
for (auto x: a) {
move_inside(x);
if (press_button() > 1) l.push_back(x);
else r.push_back(x);
move_outside(x);
}
divide(L, mid, l);
for (int i = mid + 1; i <= R; ++i) move_inside(s[i]);
divide(mid + 1, R, r);
};
divide(0, s.size() - 1, a);
return calc();
}
//
//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;
//}
컴파일 시 표준 에러 (stderr) 메시지
insects.cpp: In lambda function:
insects.cpp:95:23: warning: unused variable 'x' [-Wunused-variable]
95 | for (auto x: a) ++root[s[L]];
| ^
insects.cpp:98:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
98 | int mid = L + R >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |