Submission #44396

#TimeUsernameProblemLanguageResultExecution timeMemory
44396BruteforcemanLibrary (JOI18_library)C++14
100 / 100
642 ms844 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) { if(N == 1) { vector <int> ans; ans.push_back(1); Answer(ans); return ; } 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:82:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(P.size() + Q.size() < N) {
        ~~~~~~~~~~~~~~~~~~~~^~~
library.cpp:92:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < P.size(); i++) {
                 ~~^~~~~~~~~~
library.cpp:95: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...