Submission #189079

#TimeUsernameProblemLanguageResultExecution timeMemory
189079AkashiLibrary (JOI18_library)C++14
100 / 100
747 ms504 KiB
#include "library.h" #include <bits/stdc++.h> using namespace std; vector <int> p, f; vector <int> Left, Right; inline int exists(int st, int dr){ for(int i = st; i <= dr ; ++i) f[p[i]] = 1; int val = Query(f); for(auto it : Left) f[it] = 1; for(auto it : Right) f[it] = 1; int val2 = Query(f); for(auto it : Left) f[it] = 0; for(auto it : Right) f[it] = 0; for(int i = st; i <= dr ; ++i) f[p[i]] = 0; int dif = val2 - val; if(dif <= 1) return 1; return 0; } inline int find_value(int st, int dr){ if(st == dr) return p[st]; int mij = (st + dr) / 2; if(exists(st, mij)) return find_value(st, mij); else return find_value(mij + 1, dr); } inline bool belongs(vector <int> v, int val, int n){ vector <int> f(n); for(int i = 0; i < n ; ++i) f[i] = 0; for(auto it : v) f[it] = 1; f[val] = 1; int x = Query(f); if(x == 1) return 1; return 0; } void Solve(int n){ if(n == 1){ vector <int> ans; ans.push_back(1); Answer(ans); return ; } for(int i = 0; i < n ; i++) p.push_back(i), f.push_back(1); for(int i = 0; i < n ; ++i){ f[i] = 0; if(Query(f) == 1){ if(Left.empty()) Left.push_back(i); else Right.push_back(i); p.erase(find(p.begin(), p.end(), i)); } f[i] = 1; } for(int i = 0; i < n ; ++i) f[i] = 0; while(!p.empty()){ int val = find_value(0, p.size() - 1); if(belongs(Left, val, n)) Left.push_back(val); else Right.push_back(val); p.erase(find(p.begin(), p.end(), val)); } vector <int> ans; for(auto it : Left) ans.push_back(it + 1); reverse(Right.begin(), Right.end()); for(auto it : Right) ans.push_back(it + 1); Answer(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...