This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "insects.h"
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <algorithm>
#include <cassert>
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pi;
//vector<int> ans;
//stack<pi> S, v;
vector<int> v, w;
set<int> s, u[2020];
int min_cardinality(int N) {
// v.clear(); w.clear(); s.clear();
// for(int i = 0; i < 2020; i++) u[i].clear();
int num = 0;
for(int i = 0; i < N; i++) {
move_inside(i);
num++;
if(press_button() > 1) {
move_outside(i);
num--;
s.insert(i);
}
}
int sum = num;
for(int i : s) {
move_inside(i);
u[press_button()].insert(i);
sum++;
}
//cout<<num<<endl;
int lb = 1, ub = N, mid;
while(lb < ub) {
mid = lb+ub+1>>1;
// for(int i = lb+1; i <= ub+1; i++) {
// cout<<i<<" : ";
// for(int t:u[i])cout<<t<<" ";
// cout<<endl;
// }
// cout<<endl;
for(int i = ub+1; i > mid; i--) {
for(int t : u[i]) {
move_outside(t);
sum--;
}
}
//assert(press_button() == mid);
for(int i = mid+1; i <= ub+1; i++) {
for(int t : u[i]) {
move_inside(t);
if(press_button() > mid) {
move_outside(t);
w.push_back(t);
}
else {
sum++;
u[mid].insert(t);
v.push_back(t);
}
}
for(int t : v) u[i].erase(t);
v.clear();
}
if(sum == mid*num) {
for(int i = lb+1; i <= mid; i++)
for(int t : u[i])
s.erase(t);
for(int i : s) {
move_inside(i);
sum++;
}
lb = mid;
}
else {
for(int t : w) s.erase(t);
// for(int t : u[mid]) move_outside(t);
// sum -= u[mid].size();
ub = mid-1;
}
w.clear();
}
return lb;
}
Compilation message (stderr)
insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:43:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | mid = lb+ub+1>>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... |