이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define set(x, v) fill(ALL(x), v)
typedef vector<int> vi;
// map<vi, int> tryCombi;
constexpr bool debug = false;
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 revS(N, 0); // the correct position of each switch corresponding to door i
// vi S(N, 0); // the correct position of each switch
vi D(N, -1); // element D[i] should contain the door number that switch i is connected to
vi revD(N, -1); // element revD[i] should contain the switch number that door i is connected to
bool done = false;
for (int i = 0; i < N; i++)
{
if (i > 0)
set(switches, 0);
for (int j = 0; j < N; j++)
{
if (revD[j] == -1)
break;
switches[revD[j]] = revS[j];
}
revS[i] = ownTryCombination(switches) == i;
int min = 0, max = N - 1;
while (max - min > 0)
{
int s = (max + min) / 2;
set(switches, !revS[i]);
fill(switches.begin() + min, switches.begin() + s + 1, revS[i]);
for (int j = 0; j < N; j++)
{
if (revD[j] == -1)
break;
switches[revD[j]] = revS[j];
}
int d = ownTryCombination(switches);
if (d == -1)
{
done = true;
break;
}
if (d > i)
{
max = s;
}
else
{
min = s + 1;
}
}
if (done)
break;
if (debug)
cerr << "inx is " << min << endl;
revD[i] = min;
D[min] = i;
}
for (int i = 0; i < N; i++)
{
if (D[i] != -1)
continue;
switches[i] = !switches[i];
int d = ownTryCombination(switches);
D[i] = d;
switches[i] = !switches[i];
}
for (int i = 0; i < N; i++)
{
if (switches[i] == -1 || D[i] == -1)
throw;
}
answer(switches.data(), D.data());
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |