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 <bits/stdc++.h>
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forsn(i,s,n) for(int i = int(s); i < int(n); i++)
#define dforn(i,n) for(int i = int(n)-1; i >= 0; i--)
#define dforsn(i,s,n) for(int i = int(n)-1; i >= int(s); i--)
#define fst first
#define snd second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define FAST_IO ios::sync_with_stdio(false);cin.tie(nullptr);
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;
int const MAXN = 2005;
bitset<MAXN> done;
void move_inside(int i);
void move_outside(int i);
int press_button();
int min_cardinality(int N) {
srand(time(NULL));
int avail = N;
int prv = -1, rounds = 0;
while (avail > 0) {
vi alive;
forn(i,N) if (!done[i]) alive.pb(i);
random_shuffle(all(alive));
move_inside(alive[0]);
done[alive[0]] = true;
int cnt = 1;
vi pass;
forsn(i,1,(int)alive.size()) {
move_inside(alive[i]);
int aux = press_button();
if (aux == 2) {
move_outside(alive[i]);
}
else done[alive[i]] = true, cnt++, pass.pb(alive[i]);
}
while (!pass.empty()) {
move_outside(pass.back()); pass.pop_back();
}
move_outside(alive[0]);
if (prv != -1 && prv != cnt) break;
prv = cnt;
rounds++;
avail -= cnt;
}
return rounds;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |