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;
const int maxn = 5100;
int open[maxn], sw[maxn], n;
int f[maxn], bq;
int curr[maxn];
bool valid(int l, int r) {
bool valid = false;
for(int i=l;i<=r;i++) {
if(f[i] == -1) valid = true;
}
return valid;
}
bool validq(int ind, int l, int r) {
for(int i=l;i<=r;i++) {
if(f[i] == -1) {
curr[i] = 1;
}
}
int ans = tryCombination(curr);
for(int i=l;i<=r;i++) {
if(f[i] == -1) {
curr[i] = 0;
}
}
if((bq <= ind && bq!=-1)&& (ans == ind + 1 || ans == -1)) return true;// otvorile su se vrata ss index ind
else if((bq > ind || bq==-1) && ans <= ind) return true; // zatvorile su se tija vrata
else return false;
}
void setind(int ind, int x) {
curr[ind] = 1;
int ans = tryCombination(curr);
//cout<<"Connecting door: "<<x<<" with switch: "<<ind<<"\n";
if(ans > x || ans == -1) {
f[ind] = 1;
curr[ind] = 1;
}
else if(ans == x) {
f[ind] = 0;
curr[ind] = 0;
}
/*cout<<"Connection done:\n";
for(int i=0;i<n;i++) {
cout<<curr[i]<<" ";
} cout<<"\n";*/
}
void solve(int ind, int l=0, int r=n) {
int mid = (l+r)/2;
//cout<<ind<<": "<<l<<" "<<r<<"\n";
if(l==r) {
sw[l] = ind;
setind(l, ind);
}
else {
if(valid(l, mid)) {
if(validq(ind, l, mid)) {
solve(ind, l, mid);
}
else {
solve(ind, mid+1, r);
}
}
else {
solve(ind, mid+1, r);
}
}
}
void exploreCave(int N) {
n = N;
memset(f,-1,sizeof(f));
for(int i=0;i<N;i++) {
bq = tryCombination(curr);
/*cout<<"Before start:\n";
for(int i=0;i<N;i++) {
cout<<curr[i]<<" ";
}cout<<"\n";
for(int i=0;i<N;i++) {
cout<<f[i]<<" ";
} cout<<"\n";*/
solve(i, 0, N-1);
}
answer(curr, sw);
}
# | 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... |