Submission #1099946

#TimeUsernameProblemLanguageResultExecution timeMemory
1099946North1304Cave (IOI13_cave)C++17
100 / 100
185 ms884 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 1;
int pos[N] , now[N] , ans[N] , know[N] , trial[N];
vector<int> s;
void exploreCave(int n) {
    for (int i=0;i<n;i++) {
        for (int j=0;j<n;j++) {
            if (know[j]) trial[j] = ans[j];
            else {
                s.push_back(j);
                trial[j] = 1;  
            }
        }
        int result = tryCombination(trial);
        if (result==-1 || result>i) now[i] = 1;
        else now[i] = 0;
        int l = 0 , r = s.size() - 1;
        while (l < r) {
            int mid = (l + r) / 2;
            for (int j=l;j<=mid;j++) {
                if (!know[s[j]]) trial[s[j]] = now[i];
            }
            for (int j=mid+1;j<=r;j++) {
                if (!know[s[j]]) trial[s[j]] = 1 - now[i];
            }
            result = tryCombination(trial);
            if (result==-1 || result>i) r = mid;
            else l = mid + 1;
        }
        pos[s[l]] = i;
        ans[s[l]] = now[i];
        know[s[l]] = 1;
        s.clear();
    }
    answer(ans, pos);
}
#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...