Submission #257225

#TimeUsernameProblemLanguageResultExecution timeMemory
2572252qbingxuanCave (IOI13_cave)C++14
100 / 100
972 ms888 KiB
#include "cave.h"
inline int __lg(int n) { return 31 - __builtin_clz(n); }
int on[5025];
int n;
int D[5025], S[5025];
int checkPrefix(int x, int d) {
    for(int i = 0; i < n; i++) {
        if(D[i] == -1)
            on[i] = (i < x) ^ d;
    }
    return tryCombination(on);
}
void exploreCave(int _n) {
  	n = _n;
    for(int i = 0; i < n; i++) D[i] = -1;
    for(int now = 0; now < n; now++) {
        if(checkPrefix(n, 0) == now) { // all on -> now should be off
            int x = 0;
            for(int s = 1<<__lg(n); s; s>>=1) if(x+s < n && checkPrefix(x+s, 1) == now) x += s;
            D[x] = now;
            S[x] = on[x] = 0;
        } else {
            int x = 0;
            for(int s = 1<<__lg(n); s; s>>=1) if(x+s < n && checkPrefix(x+s, 0) == now) x += s;
            D[x] = now;
            S[x] = on[x] = 1;
        }
    }
    answer(S, D);
}
#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...