Submission #233501

#TimeUsernameProblemLanguageResultExecution timeMemory
233501DS007Library (JOI18_library)C++14
0 / 100
459 ms792 KiB
#include <bits/stdc++.h> using namespace std; #include "library.h" const int N = 1000; vector<int> adj[N]; vector<int> m, pos, res; vector<pair<int, bool>> v; bool isEnd[N]; int n_; void dfs(int v, int p = -1) { res.push_back(v + 1); for (int i : adj[v]) { if (i != p) dfs(i, v); } } int get() { int ans = 0; for (int i = 0; i < n_; i++) { if (adj[i].size() == 1 && !isEnd[i]) ans = i; } return ans; } int find(int num, int l, int r) { if (l == r) { m[num] = 1; m[pos[l]] = 1; if (Query(m) == 1) return pos[l]; else return -1; } int mid = (l + r) / 2; for (int i = l; i <= mid; i++) m[pos[i]] = 1; m[num] = 1; int a1 = Query(m); m[num] = 0; int a2 = Query(m); for (int i = l; i <= mid; i++) m[pos[i]] = 0; if (a2 < a1) return find(num, mid + 1, r); else return find(num, l, mid); } void Solve(int n) { n_ = n; m.resize(n, 0); for (int i = 0; i < n; i++) v.emplace_back(i, true); for (int i = 0; i < n - 1;) { int num = get(); assert(num < n); pos.clear(); for (auto j : v) { if (j.second && j.first != num) pos.push_back(j.first); } fill(m.begin(), m.end(), 0); int ans = find(num, 0, (int)pos.size() - 1); assert(num < n); if (ans != -1) adj[num].push_back(ans), adj[ans].push_back(num), i++; else isEnd[num] = true; v[num].second = false; v[ans].second = false; } int end1 = -1; for (int i = 0; i < n; i++) { if (isEnd[i] || adj[i].size() == 1) end1 = i; } dfs(end1); for (int i : res) assert(i <= n); Answer(res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...