# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29880 | aybala | Cave (IOI13_cave) | C++11 | 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>
#define fori(a,b,c) for(int a=b; a<c; a++)
#define ford(a,b,c) for(int a=b; a>=c; a--)
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int n;
int sw[5000];
int used[5000];
pii a[5000],b[5000];
int s[5000],d[5000];
void exploreCave(int N) {
n=N;
int lg=0;
while(1<<lg < n){
lg++;
}
cout << lg;
int nn=(1<<lg);
fori(i,0,n){
int las=0;
int x=0;
fori(j,0,lg+1){
fori(k,las,las+(nn/(1<<(j)))+x){
if(k>=n)
break;
if(!used[k]){
sw[k]=(b[i].se+1)%2;
}
else{
sw[k]=a[k].se;
}
}
int trc=tryCombination(sw);
if(n==1){
if(trc!=i){
b[i].se=1;
}
a[i].fi=i;
a[i].se=b[i].se;
}
if(j==lg){
if(trc!=i){
used[las+1]=1;
b[i].fi=las+1;
a[las+1].fi=i;
a[las+1].se=b[i].se;
}
else{
used[las]=1;
b[i].fi=las;
a[las].fi=i;
a[las].se=b[i].se;
}
break;
}
if(trc!=i && j==0){
b[i].se = 1;
continue;
}
if(trc==i && j==0){
fori(k,las,las+(nn/(1<<(j)))+x){
if(k>=n)
break;
if(!used[k]){
sw[k]=0;
}
else{
sw[k]=a[k].se;
}
}
continue;
}
if(trc!=i && j!=0){
las=las+(nn/(1<<(j)))+x;
continue;
}
if(trc==i && j!=0){
fori(k,las,las+(nn/(1<<(j)))+x){
if(k>=n)
break;
if(!used[k]){
sw[k]=(b[i].se)%2;
}
else{
sw[k]=a[k].se;
}
}
continue;
}
}
}
fori(i,0,n){
s[i]=a[i].se;
d[i]=a[i].fi;
}
answer(s,d);
}