제출 #145745

#제출 시각아이디문제언어결과실행 시간메모리
145745MathStudent2002동굴 (IOI13_cave)C++14
100 / 100
1391 ms640 KiB
#include "cave.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXM = 5005;
 
int M;
int pos[MAXM];
int loc[MAXM];
int cur;
int ex[MAXM];
 
void found(int known, int L, int R) {
    for(int x = 0; x < M; x++) {ex[x] = 1-known;}
    for(int x = L; x <= R; x++) {ex[x] = known;}
    for(int x = 0; x < cur; x++) {ex[loc[x]] = pos[x];}
}
 
void exploreCave(int N) {
    M = N;
 
    int check[M];
 
    for(int i = 0; i < M; i++) {pos[i] = -1; loc[i] = -1;}
 
    int curpos;
    int res;
 
    for(cur = 0; cur < M; cur++) {
        found(0, 0, M-1);
        for(int j = 0; j < M; j++) {
            check[j] = ex[j];
        }
        res = tryCombination(check);
        curpos = 0;
        if(res == cur) {curpos = 1;}
        pos[cur] = curpos;
 
        int lo = 0, hi = M-1;
        int mi;
        while(hi != lo) {
            mi = (lo+hi)/2;
            found(curpos,lo,mi);
            for(int j = 0; j < M; j++) {check[j] = ex[j];}
            res = tryCombination(check);
            if(res == cur) {lo = mi+1;}
            else hi = mi;
        }
 
        loc[cur] = lo;
    }
 
    int ansloc[M];
    int anspos[M];
 
    for(int i = 0; i < M; i++) {
        ansloc[loc[i]] = i;
        anspos[loc[i]] = pos[i];
    }
 
    answer(anspos, ansloc);
}
#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...