Submission #247714

#TimeUsernameProblemLanguageResultExecution timeMemory
247714NightlightCave (IOI13_cave)C++14
100 / 100
790 ms804 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; int N; bool found[5005]; int S[5005], D[5005]; void solve(int pos) { int C[N]; int init; vector<int> pen; for(int i = 0; i < N; i++) { if(found[i] == 0) { pen.push_back(i); } C[i] = 0; } for(int i = 0; i < pos; i++) C[D[i]] = S[i]; int now = tryCombination(C); if(now != pos) init = 0, S[pos] = 0; else init = 1, S[pos] = 1; int l = 0, r = pen.size() - 1, res; while(l <= r) { int mid = (l + r) >> 1; for(int i = 0; i <= mid; i++) { C[pen[i]] = init; } for(int i = mid + 1; i < pen.size(); i++) { C[pen[i]] = !init; } if(tryCombination(C) != pos) { r = mid - 1; res = mid; }else l = mid + 1; } found[pen[res]] = 1; D[pos] = pen[res]; } void exploreCave(int n) { N = n; for(int i = 0; i < N; i++) { solve(i); // cout << D[i] << "\n"; } int s[n], d[n]; for(int i = 0; i < n; i++) { d[D[i]] = i; s[D[i]] = S[i]; } answer(s, d); }

Compilation message (stderr)

cave.cpp: In function 'void solve(int)':
cave.cpp:29:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = mid + 1; i < pen.size(); i++) {
                              ~~^~~~~~~~~~~~
cave.cpp:37:18: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
     found[pen[res]] = 1;
                  ^
#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...