이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "insects.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>V, usun, Q;
int n;
int solve(int l, int r, vector<int>czy) {
if(l==r) return l;
int mid=(l+r+1)/2;
if(r-l>3) ++mid;
if(r-l>20) ++mid;
vector<int>P;
rep(i, n) if(czy[i]) {
move_inside(Q[i]);
if(press_button()==mid+1) move_outside(Q[i]);
else P.pb(i);
}
bool ok=true;
vector<int>A, B;
rep(j, V.size()) if(!usun[j]) {
int i=V[j];
move_inside(Q[i]);
if(press_button()<=mid) {
ok=false;
A.pb(j);
} else B.pb(j);
move_outside(Q[i]);
}
if(ok) {
for(auto i : P) czy[i]=0;
return solve(mid, r, czy);
}
for(auto i : B) usun[i]=1;
rep(i, n) czy[i]=0;
for(auto i : P) czy[i]=1;
for(auto i : P) move_outside(Q[i]);
return solve(l, mid-1, czy);
}
int min_cardinality(int _n) {
n=_n;
rep(i, n) Q.pb(i);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
rep(i, n) swap(Q[i], Q[rng()%(i+1)]);
rep(i, n) {
move_inside(Q[i]);
if(press_button()==1) V.pb(i);
else move_outside(Q[i]);
}
for(auto i : V) move_outside(Q[i]);
vector<int>czy(n, 1);
for(auto i : V) czy[i]=0;
rep(i, V.size()) usun.pb(0);
return solve(0, (n-V.size())/V.size(), czy)+1;
}
컴파일 시 표준 에러 (stderr) 메시지
insects.cpp: In function 'int solve(int, int, std::vector<int>)':
insects.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
insects.cpp:24:2: note: in expansion of macro 'rep'
24 | rep(j, V.size()) if(!usun[j]) {
| ^~~
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
insects.cpp:56:2: note: in expansion of macro 'rep'
56 | rep(i, V.size()) usun.pb(0);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |