#include "insects.h"
#include <variant>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define sz(x) (ll)x.size()
#define endl "\n"
#define ins insert
typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
typedef set <ll> si;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
#define MID ((l+r)/2)
// void solve(vi &u, ll l, ll r, vi test_subjects, vi &id){
// if (l == r){
// for (ll i =0; i<sz(test_subjects); i++){
// id[test_subjects[i]] = u[l];
// }
// }
// else{
// vi remaining_test_subjects, opposite_remaining_test_subjects;
// //go left:
// for (ll i =MID+1; i<r; i++){
// move_outside(u[i]);
// }
// for (ll i = 0; i<sz(test_subjects); i++){
// move_inside(test_subjects[i]);
// ll x = press_button();
// if (x == 2){
// remaining_test_subjects.pb(test_subjects[i]);
// }
// else{
// opposite_remaining_test_subjects.pb(test_subjects[i]);
// }
// move_outside(test_subjects[i]);
// }
// solve(u, l, MID, remaining_test_subjects, id);
// for (ll i =MID+1; i<r; i++){
// move_inside(u[i]);
// }
// //go right:
// for (ll i =l; i<=MID; i++){
// move_outside(u[i]);
// }
// solve(u, MID+1, r, opposite_remaining_test_subjects, id);
// for (ll i =l; i<=MID; i++){
// move_inside(u[i]);
// }
// }
// }
void tabb(ll n){
for (ll i =0; i<n; i++) cout<<"\t";
}
void solve(vi &u, si &machine_u, ll l, ll r, vi test_subjects, vi &id, ll tab = 0){
// tabb(tab);
// cout<<"l:"<<l<<" r:"<<r<<" test_subjects:";
// printVct(test_subjects);
if (!sz(test_subjects)) return;
if (l == r){
for (ll i =0; i<sz(test_subjects); i++){
id[test_subjects[i]] = u[l];
}
}
else{
vi remaining_test_subjects, opposite_remaining_test_subjects;
//left:
for (ll i = 0; i<sz(u); i++){
if (l <= i && i <= MID){ //wanted
if (machine_u.find(u[i]) == machine_u.end()){
//add
move_inside(u[i]);
machine_u.ins(u[i]);
}
}
else{ //unwanted
if (machine_u.find(u[i]) != machine_u.end()){
//remove
move_outside(u[i]);
machine_u.erase(u[i]);
}
}
}
for (ll i = 0; i<sz(test_subjects); i++){
move_inside(test_subjects[i]);
ll x = press_button();
if (x == 2){
remaining_test_subjects.pb(test_subjects[i]);
}
else{
opposite_remaining_test_subjects.pb(test_subjects[i]);
}
move_outside(test_subjects[i]);
}
solve(u, machine_u, l, MID, remaining_test_subjects, id, tab+1);
//right:
solve(u, machine_u, MID+1, r, opposite_remaining_test_subjects, id, tab+1);
}
}
int min_cardinality(int N){
ll n = N;
vi v(n);
//step 1: make list of unique elements
vi u(1,0);
move_inside(0);
for (ll i =1; i<n;i++){
move_inside(i);
ll x = press_button();
if (x == 2){
move_outside(i);
}
else{
u.pb(i);
}
}
// printVct(u);
//step 2: binary search
set <ll> st;
for (ll i =0; i<sz(u); i++){
st.insert(u[i]);
}
vi test_subjects, id(n);
for (ll i =0; i<n; i++){
if (st.find(i) == st.end()){
test_subjects.pb(i);
id[i] = -1;
}
else{
id[i] = i;
}
}
si machine_u;
for (ll i = 0; i<sz(u); i++) machine_u.insert(u[i]);
solve(u, machine_u, 0, sz(u)-1, test_subjects, id);
// printVct(id);
sort(id.begin(), id.end());
vi f(n,0);
for (ll i =0; i<n; i++){
f[id[i]]++;
}
ll ans = 1000000000;
for (ll i =0; i<n; i++){
if (f[i]){
ans = min(ans, f[i]);
}
}
return ans;
}
/*
6
5 8 9 5 9 9
5
1 2 2 3 4
10
1 2 2 6 1 3 3 2 6 1
60
1 2 2 6 1 3 3 2 6 1 1 2 2 6 1 3 3 2 6 1 1 2 2 6 1 3 3 2 8 6 1 1 2 2 6 1 3 3 9 6 1 1 15 2 6 1 3 3 2 6 1 1 2 2 6 1 3 3 2 6 1
6
1 2 3 4 5 6
1
1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
688 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
4 ms |
600 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
612 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
4 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
692 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
688 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
4 ms |
600 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
612 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
4 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
4 ms |
344 KB |
Output is correct |
18 |
Correct |
4 ms |
604 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
1108 KB |
Output is correct |
21 |
Correct |
4 ms |
692 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
5 ms |
600 KB |
Output is correct |
24 |
Correct |
4 ms |
856 KB |
Output is correct |
25 |
Correct |
27 ms |
600 KB |
Output is correct |
26 |
Correct |
35 ms |
696 KB |
Output is correct |
27 |
Correct |
10 ms |
600 KB |
Output is correct |
28 |
Correct |
27 ms |
1244 KB |
Output is correct |
29 |
Correct |
17 ms |
936 KB |
Output is correct |
30 |
Correct |
29 ms |
448 KB |
Output is correct |
31 |
Correct |
17 ms |
616 KB |
Output is correct |
32 |
Correct |
16 ms |
600 KB |
Output is correct |
33 |
Correct |
20 ms |
932 KB |
Output is correct |
34 |
Correct |
19 ms |
696 KB |
Output is correct |
35 |
Correct |
21 ms |
700 KB |
Output is correct |
36 |
Correct |
29 ms |
700 KB |
Output is correct |
37 |
Correct |
39 ms |
1112 KB |
Output is correct |
38 |
Correct |
31 ms |
936 KB |
Output is correct |
39 |
Correct |
38 ms |
732 KB |
Output is correct |
40 |
Correct |
30 ms |
856 KB |
Output is correct |
41 |
Correct |
23 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
12 ms |
436 KB |
Output is correct |
8 |
Correct |
13 ms |
852 KB |
Output is correct |
9 |
Partially correct |
72 ms |
708 KB |
Output is partially correct |
10 |
Partially correct |
69 ms |
1104 KB |
Output is partially correct |
11 |
Correct |
28 ms |
692 KB |
Output is correct |
12 |
Partially correct |
59 ms |
1076 KB |
Output is partially correct |
13 |
Partially correct |
35 ms |
1392 KB |
Output is partially correct |
14 |
Partially correct |
73 ms |
696 KB |
Output is partially correct |
15 |
Partially correct |
35 ms |
1108 KB |
Output is partially correct |
16 |
Partially correct |
34 ms |
716 KB |
Output is partially correct |
17 |
Partially correct |
42 ms |
688 KB |
Output is partially correct |
18 |
Partially correct |
50 ms |
732 KB |
Output is partially correct |
19 |
Partially correct |
60 ms |
940 KB |
Output is partially correct |
20 |
Partially correct |
54 ms |
976 KB |
Output is partially correct |
21 |
Partially correct |
64 ms |
1104 KB |
Output is partially correct |
22 |
Partially correct |
75 ms |
732 KB |
Output is partially correct |
23 |
Partially correct |
83 ms |
936 KB |
Output is partially correct |
24 |
Partially correct |
77 ms |
508 KB |
Output is partially correct |
25 |
Partially correct |
62 ms |
600 KB |
Output is partially correct |
26 |
Partially correct |
52 ms |
460 KB |
Output is partially correct |
27 |
Partially correct |
66 ms |
1192 KB |
Output is partially correct |
28 |
Partially correct |
66 ms |
932 KB |
Output is partially correct |
29 |
Partially correct |
52 ms |
1112 KB |
Output is partially correct |
30 |
Partially correct |
57 ms |
852 KB |
Output is partially correct |
31 |
Partially correct |
64 ms |
952 KB |
Output is partially correct |
32 |
Partially correct |
66 ms |
716 KB |
Output is partially correct |
33 |
Partially correct |
79 ms |
1104 KB |
Output is partially correct |
34 |
Partially correct |
68 ms |
704 KB |
Output is partially correct |
35 |
Partially correct |
70 ms |
1204 KB |
Output is partially correct |
36 |
Partially correct |
72 ms |
732 KB |
Output is partially correct |
37 |
Partially correct |
65 ms |
864 KB |
Output is partially correct |
38 |
Partially correct |
69 ms |
720 KB |
Output is partially correct |
39 |
Partially correct |
69 ms |
592 KB |
Output is partially correct |
40 |
Partially correct |
80 ms |
932 KB |
Output is partially correct |
41 |
Partially correct |
67 ms |
940 KB |
Output is partially correct |
42 |
Partially correct |
88 ms |
688 KB |
Output is partially correct |
43 |
Partially correct |
10 ms |
856 KB |
Output is partially correct |
44 |
Partially correct |
36 ms |
964 KB |
Output is partially correct |
45 |
Correct |
24 ms |
344 KB |
Output is correct |
46 |
Partially correct |
58 ms |
1336 KB |
Output is partially correct |
47 |
Partially correct |
54 ms |
1052 KB |
Output is partially correct |
48 |
Partially correct |
55 ms |
1056 KB |
Output is partially correct |