이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
void move_inside(int i);
void move_outside(int i);
int press_button();
int brute(const vector<int>& basis, int n)
{
set<int> selected;
for (int i : basis)
{
selected.insert(i);
move_outside(i);
}
int count = 1;
while (true)
{
vector<int> next_basis;
for (int i = 0; i < n; i++)
{
if (selected.find(i) == selected.end())
{
move_inside(i);
if (press_button() > 1)
move_outside(i);
else
next_basis.pb(i);
}
}
if (next_basis.size() != basis.size())
return count;
count++;
for (int i : next_basis)
{
selected.insert(i);
move_outside(i);
}
}
}
int find(const vector<int>& basis, int l, int r, const vector<int>& permutation)
{
if (r - l == 1)
{
move_outside(basis[l]);
return permutation.size() + 1;
}
int m = l+r>>1;
for (int i = m; i < r; i++)
move_outside(basis[i]);
vector<int> lp, rp;
for (int i : permutation)
{
move_inside(i);
if (press_button() == 1)
rp.pb(i);
else
lp.pb(i);
move_outside(i);
}
int lr = find(basis, l, m, lp);
for (int i = m; i < r; i++)
move_inside(basis[i]);
int rr = find(basis, m, r, rp);
return min(lr, rr);
}
int min_cardinality(int n)
{
vector<int> basis;
for (int i = 0; i < n; i++)
{
move_inside(i);
int q = press_button();
if (q != 1)
move_outside(i);
else
basis.pb(i);
}
if (basis.size() * 6 >= n)
return brute(basis, n);
vector<int> permutation;
for (int i = 0; i < n; i++)
if (*lower_bound(basis.begin(), basis.end(), i) != i)
permutation.pb(i);
return find(basis, 0, basis.size(), permutation);
}
컴파일 시 표준 에러 (stderr) 메시지
insects.cpp: In function 'int find(const std::vector<int>&, int, int, const std::vector<int>&)':
insects.cpp:50:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int m = l+r>>1;
| ~^~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:82:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
82 | if (basis.size() * 6 >= n)
| ~~~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |