# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155464 | 2019-09-28T13:35:29 Z | Mercenary | Library (JOI18_library) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> #include "library.h" using namespace std; void Solve(int n) { vector<int> res(n); vector<int> ask(n , 1); int pre = 0; vector<int> p(n); for(int i = 0 ; i < n ; ++i)p[i] = i; auto del = [&](int x){ p.erase(find(p.begin(),p.end(),x)); }; for(int i = 0 ; i < n ; ++i){ ask[i] = 0; if(Query(ask) == 1){ pre = i; break; } ask[i] = 1; } del(pre);res[0] = pre; if(n == 1)return res; for(int i = 1 ; i < n ; ++i){ int l = 0 , h = (int)p.size() - 1; while(l <= h){ for(int j = 0 ; j < n ; ++j)ask[j] = 0; int mid = l + h >> 1; for(int j = 0 ; j <= mid ; ++j)ask[p[j]] = 1; int last = Query(ask); ask[pre] = 1; if(last == Query(ask))h = mid - 1; else l = mid + 1; } pre = p[l]; del(pre); res[i] = pre; } for(int i = 0 ; i < n ; ++i)res[i]++; Answer(res); }