# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
783975 | Boas | 동굴 (IOI13_cave) | C++17 | 0 ms | 0 KiB |
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>
#include "cave.h"
#include "grader.c"
using namespace std;
constexpr bool debug = false;
typedef vector<int> vi;
// map<vi, int> tryCombi;
int ownTryCombination(vi &switches)
{
if (debug)
{
cerr << endl
<< "TryCombination: ";
for (int t : switches)
{
cerr << t << " ";
}
cerr << endl;
}
int res;
// if (tryCombi.find(switches) != tryCombi.end())
//{
// res = tryCombi[switches];
//}
// else
{
res = tryCombination(switches.data());
// tryCombi[switches] = res;
}
if (debug)
cerr << "Result: " << res << endl;
return res;
}
void exploreCave(int N)
{
vi switches(N, 0);
vi minDist(N);
vi maxDist(N, N);
int d = ownTryCombination(switches);
int nd = 0;
while (d != -1)
{
if (nd == -1)
break;
for (int i = 0; i < N; i++)
{
if (minDist[i] == maxDist[i])
continue;
switches[i] = !switches[i];
nd = ownTryCombination(switches);
if (nd == -1)
break;
if (nd == d)
{
if (debug)
cerr << "minDist[" << i << "] = " << d + 1 << endl;
minDist[i] = d + 1;
switches[i] = !switches[i];
d = nd;
}
else if (nd > d)
{
if (debug)
cerr << "min&maxDist[" << i << "] = " << d << endl;
minDist[i] = d;
maxDist[i] = d;
d = nd;
}
else
{
if (debug)
cerr << "min&maxDist[" << i << "] = " << nd << endl;
minDist[i] = nd;
maxDist[i] = nd;
switches[i] = !switches[i];
// i--;
}
}
if (nd == -1)
break;
}
for (int i = 0; i < N; i++)
{
if (minDist[i] == maxDist[i])
continue;
switches[i] = !switches[i];
int d = ownTryCombination(switches);
minDist[i] = d;
maxDist[i] = d;
switches[i] = !switches[i];
}
answer(switches.data(), minDist.data());
cerr << endl;
}