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;
bool isOpen(int i, int ret){
return ret == -1 || ret > i;
}
void exploreCave(int N){
int switches[N], permu[N], ansD[N], ansP[N];
for(int i = 0; i < N; ++i){
switches[i] = i;
permu[i] = 0;
ansP[i] = 0;
ansD[i] = 0;
}
for(int i = 0; i < N; ++i){
for(int j = 0; j < N - i; ++j){
permu[switches[j]] = 0;
}
int correct;
/*cout << "PRINT SWITCHES\n";
for(int j = 0; j < N; ++j){
cout << switches[j] << ' ';
}
cout << '\n';
printPermu(permu, N);
printf("check:%d\n", tryCombination(permu));*/
if(isOpen(i, tryCombination(permu))){
correct = 0;
} else {
correct = 1;
}
//printf("correct:%d\n", correct);
int l = 0;
int r = N - i - 1;
int ans = 0;
while(l < r){
//printf("l:%d r:%d\n", l, r);
int m = (l + r) / 2;
//permu[switches[m]] = correct ^ 1;
for(int j = l; j <= m; ++j){
permu[switches[j]] = correct;
}
for(int j = m + 1; j <= r; ++j){
permu[switches[j]] = correct ^ 1;
}
if(isOpen(i, tryCombination(permu))){
r = m;
} else {
/*for(int j = l; j <= m; ++j){
permu[switches[j]] = correct ^ 1;
}*/
l = m + 1;
}
}
ans = l;
//printf("ans:%d door[%d]:%d\n", ans, i, switches[ans]);
ansP[switches[ans]] = correct;
permu[switches[ans]] = correct;
ansD[switches[ans]] = i;
swap(switches[ans], switches[N - i - 1]);
/*cout << "ansP: ";
for(int j = 0; j < N; ++j){
cout << ansP[j] << ' ';
}
cout << "\nansD: ";
for(int j = 0; j < N; ++j){
cout << ansD[j] << ' ';
}
cout << '\n';*/
}
answer(ansP, ansD);
}
# | 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... |