# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705482 | YassineBenYounes | 동굴 (IOI13_cave) | C++14 | 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.
/*
ID: Yassine BenYounes
TASK: guard
LANG: C++
*/
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vdd vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int mx = 2e5+9;
const int LOG = 25;
const ll inf = 1e15;
int pos[mx], door[mx], tr[mx];
int tryCombination(int pos[]);
void answer(int pos[], int door[]);
void exploreCave(int n){
memset(pos, -1, sizeof pos);
for(int i = 0; i < n;i++){
// iterate on doors
bool right = 0;
for(int j = 0;j < n;j++){
// iterate on switches
if(pos[j] == -1)tr[j] = right;
else tr[j] = pos[j];
}
int x = tryCombination(tr);
if(x == i)right = 1;
int l = 0, r = n-1;
while(l < r){
int md = (l+r)/2;
for(int j = 0; j < n;j++){
// iterate on switches
if(j >= l && j <= md){
if(pos[j] == -1)tr[j] = right;
else tr[j] = pos[j];
}
else{
if(pos[j] == -1)tr[j] = !right;
else tr[j] = pos[j];
}
}
int x = tryCombination(tr);
if(x == i){
l = md+1;
}
else{
r = md;
}
}
// switch for i-th door : l
door[l] = i;
pos[l] = right;
}
answer(pos, door);
}