Submission #44394

#TimeUsernameProblemLanguageResultExecution timeMemory
44394BruteforcemanLibrary (JOI18_library)C++14
0 / 100
51 ms608 KiB
#include <bits/stdc++.h> #include "library.h" using namespace std; bool vis[10000]; vector <int> P, Q; int size; void print(vector <int> &M) { for(auto i : M) { cout << i << " "; } cout << endl; } int query(vector <int> &v) { bool good = false; for(int i = 0; i < size; i++) { if(v[i] == 1) { good = true; break; } } return good ? Query(v) : 0; } bool goodSet(vector <int> &v) { vector <int> com (size); for(int i = 0; i < size; i++) { if(vis[i]) com[i] = 1; else com[i] = v[i] ^ 1; } int p = query(v); int q = query(com); return (p - 1) != q; } bool adjacent(int p, int q) { vector <int> v (size); v[p] = 1; v[q] = 1; return query(v) == 1; } bool goodSet(int p, int q, vector <int> &v) { vector <int> shit (size); for(int i = 0; i < size; i++) shit[i] = vis[i]; for(int i = p; i <= q; i++) shit[v[i]] = 1; return goodSet(shit); } int search(int b, int e, vector <int> &v) { if(b == e) { return b; } int m = (b + e) >> 1; if(goodSet(b, m, v)) return search(b, m, v); else return search(m + 1, e, v); } void Solve(int N) { size = N; vector<int> M(N); for(int i = 0; i < size; i++) { M[i] = i; } memset(vis, false, sizeof vis); vector <int> H (size); fill(H.begin(), H.end(), 1); for(int i = 0; i < size; i++) { H[i] = 0; if(query(H) == 1) { vis[i] = true; M.erase(find(M.begin(), M.end(), i)); if(P.empty()) P.push_back(i); else Q.push_back(i); } H[i] = 1; } while(P.size() + Q.size() < N) { int can = search(0, M.size() - 1, M); int val = M[can]; if (adjacent(P.back(), val)) P.push_back(val); else Q.push_back(val); M.erase(M.begin() + can); vis[val] = true; } reverse(Q.begin(), Q.end()); vector<int> res(N); for(int i = 0; i < P.size(); i++) { res[i] = P[i] + 1; } for(int i = 0; i < Q.size(); i++) { res[i + P.size()] = Q[i] + 1; } Answer(res); }

Compilation message (stderr)

library.cpp: In function 'void Solve(int)':
library.cpp:76:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(P.size() + Q.size() < N) {
        ~~~~~~~~~~~~~~~~~~~~^~~
library.cpp:86:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < P.size(); i++) {
                 ~~^~~~~~~~~~
library.cpp:89:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < Q.size(); i++) {
                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...