# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
96177 | liwi | 동굴 (IOI13_cave) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);
#define MAXN 5001
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int len,init,curr,guess[MAXN],res[MAXN],back[MAXN];
//int real_back[MAXN]={3,0,1,2},order[MAXN]={1,0,1,0};
bool done[MAXN];
//
//void answer(int S[MAXN], int D[MAXN]){
// for(int i=0; i<len; i++){
// if(S[i] != order[i]){
// printf("SWITCH %d WRONG ORDER\n",i);
// exit(0);
// }
// }
// for(int i=0; i<len; i++){
// if(D[i] != real_back[i]){
// printf("SWITCH %d MAPPED TO WRONG DOOR",i);
// exit(0);
// }
// }
// printf("AC\n");
//}
//
//int tryCombination(int S[MAXN]){
// int res = INT_MAX;
// for(int i=0; i<len; i++)
// if(S[i] != order[i])
// res = min(res,real_back[i]);
// if(res == INT_MAX) return -1;
// return res;
//}
void solve(int l, int r){
for(int i=0; i<len; i++){
if(done[i]) guess[i] = res[i];
else guess[i] = 0;
}
for(int i=l; i<=(l+r)/2; i++){
if(done[i]) guess[i] = res[i];
else guess[i] = 1;
}
int mid = (l+r)/2, current = (tryCombination(guess)==curr?1:0);
if(l == r){
if(init) res[l] = 1;
else res[l] = 0;
done[l] = true;
back[l] = curr;
return;
}
if(current == init) solve(mid+1,r);
else solve(l,mid);
}
void exploreCave(int N){
len = N;
for(curr=0; curr<N; curr++){
for(int k=0; k<N; k++){
if(done[k]) guess[k] = res[k];
else guess[k] = 0;
}
init = (tryCombination(guess)==curr?1:0);
solve(0,N-1);
}
answer(res,back);
}