# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1238829 | em4ma2 | Cave (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
#include "grader.h"
/*#include <assert.h>
#include <stdio.h>
#include <stdlib.h>*/
using namespace std;
#define ll long long
//#define int long long
#define pb push_back
#define applejuice ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int mod=1e9+7;
const ll inf=LLONG_MAX;
const ll mxsz=500+4;
int off=1;
/*#define MAX_N 5000
#define MAX_CALLS 70000
static int N;
static int realS[MAX_N];
static int realD[MAX_N];
static int inv[MAX_N];
static int num_calls;
void answer(int S[], int D[]) {
int i;
for (i = 0; i < N; ++i)
if (S[i] != realS[i] || D[i] != realD[i]) {
printf("INCORRECT\nWrong answer:");
if (S[i] != realS[i])
printf("S[%d] != realS[%d]", i, i);
else
printf("D[%d] != realD[%d]", i, i);
exit(0);
}
printf("CORRECT\n");
exit(0);
}
int tryCombination(int S[]) {
int i;
if (num_calls >= MAX_CALLS) {
printf("INCORRECT\nToo many calls to tryCombination().\n");
exit(0);
}
++num_calls;
for (i = 0; i < N; ++i)
if (S[inv[i]] != realS[inv[i]])
return i;
return -1;
}
int init() {
int i;
assert(scanf("%d", &N) == 1);
for (i = 0; i < N; ++i) {
assert(scanf("%d", &realS[i]) == 1);
}
for (i = 0; i < N; ++i) {
assert(scanf("%d", &realD[i]) == 1);
inv[realD[i]] = i;
}
num_calls = 0;
return N;
}*/
void exploreCave(int n){
vector<int>a(n,-1),b(n,-1);
for (int i=0;i<n;i++){
int tmp[n];
for (int j=0;j<n;j++){
if (a[j]==-1)tmp[j]=0;
else tmp[j]=a[j];
}
int ans=tryCombination(tmp);
if (ans==-1){
ans=n+1;
}
int l=0,r=n,out=0;
while (l<r-1){
int mid=(l+r)/2;
for (int j=l;j<mid;j++){
if (a[j]==-1)tmp[j]=1;
}
int cur=tryCombination(tmp);
if (cur==-1)cur=n+1;
if (cur>i){
if (ans>i){
l=mid;
out=mid;
}
else r=mid;
}else{
if (ans>i)r=mid;
else {
out=mid;
l=mid;
}
}
for (int j=l;j<mid;j++){
if (a[j]==-1)tmp[j]=0;
}
}
if (ans>i)a[out]=0;
else a[out]=1;
b[out]=i;
}
answer(a.data(),b.data());
}
/*
signed main() {
int N;
N = init();
exploreCave(N);
printf("INCORRECT\nYour solution did not call answer().\n");
return 0;
}
*/