# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033855 | shjeong | Cave (IOI13_cave) | C++17 | 87 ms | 600 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>
#include "cave.h"
using namespace std;
typedef long long ll;
void exploreCave(int N) {
int *s = (int*)malloc(N*sizeof(int));
int *ans = (int*)malloc(N*sizeof(int)); //s[i] = j : i번 문은 j번 스위치 / ans[i] = j : i번 스위치는 j
vector<bool> vis(N);
for(int i = 0 ; i < N ; i++){
int *tmp = (int*)malloc(N*sizeof(int));
memset(tmp,0,sizeof(tmp));
vector<ll> idx;
for(int j = 0 ; j < N ; j++){
if(!vis[j])idx.push_back(j);
}
for(int j = 0 ; j < i ; j++)tmp[s[j]] = ans[s[j]];
ll x = tryCombination(tmp);
bool f = (x==i);
ll l = 0, r = (int)idx.size()-1;
while(l < r){
ll mid = l+r>>1;
for(int i = l ; i <= mid ; i++)tmp[idx[i]] = 0;
for(int i = mid+1 ; i <= r ; i++)tmp[idx[i]] = 1;
ll x = tryCombination(tmp);
if((x==i) == f){
if(f==0)r = mid;
else l = mid+1;
}
else{
if(f==0)l = mid+1;
else r = mid;
}
}
ans[idx[r]] = f;
s[i] = idx[r];
vis[idx[r]] = 1;
free(tmp);
}
answer(ans,s);
free(ans); free(s);
}
Compilation message (stderr)
# | 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... |