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 "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];
void randomise_switches(int N) {
for (int i = 0; i < N; i++) if (not is_fixed[i])
swit[i] = rnd() & 1;
}
bool exploreCave(int N) {
fill(is_fixed, is_fixed + N, false);
while (true) {
randomise_switches(N);
int p = tryCombination(swit);
if (p == -1)
break;
int j = -1;
for (int i = 0; i < N; i++) if (not is_fixed[i]) {
swit[i] ^= 1;
int p2 = tryCombination(swit);
if (p2 > p or p2 == -1)
j = i;
else if (p2 < p)
is_fixed[i] = true;
swit[i] ^= 1;
}
swit[j] ^= 1;
is_fixed[j] = true;
}
for (int i = 0; i < N; i++) {
swit[i] ^= 1;
door[i] = tryCombination(swit);
swit[i] ^= 1;
}
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... |