# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1025544 | dozer | 동굴 (IOI13_cave) | C++14 | 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"
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define LL node * 2
#define RR node * 2 + 1
#define mid (l + r) / 2
#define ll long long
#define MAXN 200005
#define LOGN 12
#define MAX_N 5000
#define MAX_CALLS 70000
#define fail(s, x...) do { \
fprintf(stderr, s "\n", ## x); \
exit(1); \
} while(0)
/* Symbol obfuscation */
#define N koala
#define realS kangaroo
#define realD possum
#define inv platypus
#define num_calls echidna
static int N;
static int realS[MAX_N];
static int realD[MAX_N];
static int inv[MAX_N];
static int num_calls;
void answer(int S[], int D[]) {
int i;
int correct = 1;
for (i = 0; i < N; ++i)
if (S[i] != realS[i] || D[i] != realD[i]) {
correct = 0;
break;
}
if (correct)
printf("CORRECT\n");
else
printf("INCORRECT\n");
for (i = 0; i < N; ++i) {
if (i > 0)
printf(" ");
printf("%d", S[i]);
}
printf("\n");
for (i = 0; i < N; ++i) {
if (i > 0)
printf(" ");
printf("%d", D[i]);
}
printf("\n");
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
exit(0);
}
int tryCombination(int S[]) {
int i;
if (num_calls >= MAX_CALLS) {
printf("INCORRECT\nToo many calls to tryCombination().\n");
exit(0);
}
++num_calls;
for (i = 0; i < N; ++i)
if (S[inv[i]] != realS[inv[i]])
return i;
return -1;
}
int init() {
int i, res;
freopen("output.txt", "w", stdout);
FILE *f = fopen("input.txt", "r");
if (!f)
fail("Failed to open input file.");
res = fscanf(f, "%d", &N);
for (i = 0; i < N; ++i) {
res = fscanf(f, "%d", &realS[i]);
}
for (i = 0; i < N; ++i) {
res = fscanf(f, "%d", &realD[i]);
inv[realD[i]] = i;
}
num_calls = 0;
return N;
}
void exploreCave(int N) {
int done[N], curr[N];
for (int i = 0; i < N; i++)
done[i] = -1, curr[i] = 0;
auto question = [&](int x, int val){
int tmpx = x;
int lst = -1;
for (int i = 0; i < N; i++){
if (x > 0 && done[i] == -1) curr[i] = val, x--, lst = i;
else if (done[i] == -1) curr[i] = 1 - val;
}
int res = tryCombination(curr);
return res;
};
for (int i = 0; i < N; i++){
int val = 0;
if (question(0, 1) >= i + 1 || question(0, 1) == -1){
val = 1;
}
int pos = 0;
for (int j = LOGN; j >= 0; j--){
int tmp = pos + (1<<j);
int t = question(tmp, val);
// cout<<i<<sp<<val<<sp<<tmp<<sp<<t<<endl;
if (t >= i + 1 || t == -1) pos = tmp;
}
pos++;
int lst = 0;
for (int i = 0; i < N; i++){
if (done[i] == -1 && pos > 0) lst = i, pos--;
}
done[lst] = i;
curr[lst] = 1 - val;
}
answer(curr, done);
}