# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205165 | 2020-02-28T08:40:54 Z | theStaticMind | Library (JOI18_library) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; #include<library.h> vector<int> Q(n, 0); int ind = 0; vector<int> adj[1001]; int bin(int l, int r){ int ret = -1; while(l <= r){ int mid = (l + r) / 2; vector<int> arr(n, 0); for(int i = 0; i <= mid; i++)arr[i] = 1; arr[r + 1] = 1; if(Query(arr) == Q[mid]){ ret = mid; r = mid - 1; } else{ l = mid + 1; } } return ret; } void Solve(int n){ vector<int> arr(n, 0); for(;ind < n; ind++){ arr[ind] = 1; int Q[ind] = Query(arr); if(ind != 0 && Q[ind] == Q[ind - 1]){ int x = bin(0, ind - 1); adj[x].pb(ind); adj[ind].pb(x); x = bin(x + 1, ind - 1); if(x != -1){ adj[x].pb(ind); adj[ind].pb(x); } } } int root = 0; while(sz(adj[root]) == 2)root++; vector<int> ans; int x = root; for(int i = 0; i < n; i++){ if(adj[x].size() == 1){ ans.pb(x); x = adj[x][0]; } else{ if(ans.back() == adj[x][0]){ ans.pb(x); x = adj[x][1]; } else{ ans.pb(x); x = adj[x][0]; } } } Answer(ans); }