이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
using ll = long long;
int n;
int sz = 0;
bool mark[2020];
void putin(int x) {
move_inside(x);
sz++;
}
void putout(int x) {
move_outside(x);
sz--;
}
int val() {
return press_button();
}
int min_cardinality(int N) {
n = N;
putin(0);
mark[0] = 1;
for (int i = 1;i < n;i++) {
putin(i);
if (val() == 2) {
putout(i);
}
else {
mark[i] = 1;
}
}
int type = sz;
if (type == n) return 1;
int l = 1, r = n / sz + 1;
while (l < r) {
int mid = (l + r + 1) / 2;
stack<int> st, st2;
for (int i = 0;i < n;i++) {
if (sz == type * mid) break;
if (mark[i]) continue;
putin(i);
if (val() > mid) {
putout(i);
mark[i] = 1;
st2.push(i);
}
else {
st.push(i);
}
}
if (sz == type * mid) {
while (!st.empty()) {
mark[st.top()] ^= 1;
st.pop();
}
while (!st2.empty()) {
mark[st2.top()] ^= 1;
st2.pop();
}
l = mid;
}
else {
while (!st.empty()) {
putout(st.top());
st.pop();
}
r = mid - 1;
}
}
return l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |