제출 #68788

#제출 시각아이디문제언어결과실행 시간메모리
68788someone_aa동굴 (IOI13_cave)C++17
12 / 100
309 ms544 KiB
#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 || 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, int r) { 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); } //bq = tryCombination(curr); //cout<<validq(5, 0, 3); answer(curr, sw); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...