이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5000 + 7;
int swit[MAX], door[MAX];
namespace Subtask1 {
bool exploreCave(int N) {
iota(door, door + N, 0);
fill(swit, swit + N, 0);
int cnt = 0;
while (cnt <= N) {
int i = tryCombination(swit);
if (i == -1) {
answer(swit, door);
return true;
}
swit[i] ^= 1;
cnt++;
}
return false;
}
}
namespace Subtask2 {
bool exploreCave(int N) {
fill(swit, swit + N, 0);
for (int i = 0; i < N; i++) {
swit[i] = 1;
door[i] = tryCombination(swit);
swit[i] = 0;
}
answer(swit, door);
return true;
}
}
namespace Subtask3 {
bool exploreCave(int N) {
mt19937 rnd(20050701);
generate(swit, swit + N, [&]() {
return rnd() & 1;
});
int p = tryCombination(swit);
while (p != -1) {
for (int i = 0; i < N; i++) {
swit[i] ^= 1;
int p2 = tryCombination(swit);
if (p2 > p or p2 == -1) {
p = p2;
break;
}
swit[i] ^= 1;
}
}
for (int i = 0; i < N; i++) {
swit[i] ^= 1;
door[i] = tryCombination(swit);
swit[i] ^= 1;
}
answer(swit, door);
return true;
}
}
namespace Subtask4 {
mt19937 rnd(20050701);
bool is_fixed[MAX];
int INIT_COMB;
pair<int, int> find_switch_for_door(int i, int l, int r) {
if (l == r) {
if (not is_fixed[r])
swit[r] ^= 1;
int p = INIT_COMB = tryCombination(swit);
// cerr << "try " << i << " " << l << " " << r << " -> " << p << endl;
if (not is_fixed[r])
swit[r] ^= 1;
if (p == i)
return make_pair(swit[r], r);
return make_pair(swit[r] ^ 1, r);
}
int p1 = INIT_COMB;
int m = (l + r) >> 1;
bool ok = false;
for (int x = l; x <= m; x++) if (not is_fixed[x]) {
swit[x] ^= 1;
ok = true;
}
int p2 = ok ? tryCombination(swit) : p1;
for (int x = l; x <= m; x++) if (not is_fixed[x])
swit[x] ^= 1;
if ((p1 == i) xor (p2 == i))
return find_switch_for_door(i, l, m);
return find_switch_for_door(i, m + 1, r);
}
bool exploreCave(int N) {
fill(is_fixed, is_fixed + N, false);
for (int i = 0; i < N; i++) {
INIT_COMB = tryCombination(swit);
int res, p;
tie(res, p) = find_switch_for_door(i, 0, N - 1);
door[p] = i;
swit[p] = res;
is_fixed[p] = true;
}
answer(swit, door);
return true;
}
}
void exploreCave(int N) {
Subtask4::exploreCave(N);
}
# | 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... |