이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 2000
lli ini,fin,n,last,a,mitad,c_inval,c_excedentes;
lli inval[MAX+2];
int min_cardinality(int N) {
n = N;
//poda
//rep(i,0,n-1) move_inside(i);
//fin = press_button();
//rep(i,0,n-1) move_outside(i);
fin = n;
//if (fin == n) return n;
//fin = min(fin,n-fin);
ini = 1;
while (ini <= fin) {
//debugsl(ini);
//debug(fin);
mitad = (ini+fin)/2;
c_excedentes = 0;
rep(i,0,n-1) {
if(inval[i] == 1) continue;
move_inside(i);
a = press_button();
if (a > mitad) {
move_outside(i);
inval[i] = 2;
c_excedentes++;
}
}
rep(i,0,n-1) {
if(inval[i] == 1 || inval[i] == 2) continue;
move_outside(i);
}
//correcto, no hay ningun bicho en la maquina
if(c_excedentes == 0) {
last = mitad;
fin = mitad-1;
continue;
}
//meto aquellos que sean los excedentes y marco todas sus parejas
repa(i,n-1,0) {
if (inval[i] == 1) continue;
move_inside(i);
a = press_button();
if (inval[i] == 2) {
if (a == 2) {
move_outside(i);
inval[i] = 3;
}
}
else {
move_outside(i);
if (a == 2) {
inval[i] = 3;
c_excedentes++;
}
}
}
//rep(i,0,n-1) cout << inval[i] << ' ';
//cout << endl;
a = c_excedentes + c_inval;
if (a == n) {
rep(i,0,n-1) {
if(inval[i] == 2) move_outside(i);
if(inval[i] != 1) inval[i] = 0;
}
ini = mitad+1;
}
else {
last = mitad;
c_inval += c_excedentes;
rep(i,0,n-1) {
if(inval[i] == 2) move_outside(i);
if(inval[i] > 1) inval[i] = 1;
}
fin = mitad-1;
}
}
return last;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |