Submission #44038

#TimeUsernameProblemLanguageResultExecution timeMemory
44038ruhanhabib39Library (JOI18_library)C++17
100 / 100
329 ms1248 KiB
#include <cstdio> #include <vector> #include <algorithm> #include <map> #include "library.h" using namespace std; namespace { int N; const int MAXN = 1000; vector<int> G[MAXN + 10]; vector<int> init(int l, int r, int i = -1) { vector<int> v(N, 0); if(l <= r) fill(v.begin() + l, v.begin() + r + 1, 1); if(i != -1) v[i] ^= 1; return v; } map<tuple<int,int,int>,int> cnt; int ask(int l, int r, int i = -1) { int& res = cnt[{l,r,i}]; if(res == 0) res = Query(init(l, r, i)); return res; } void addEdge(int i, int j) { G[i].push_back(j); G[j].push_back(i); } template<class Fn> int work(int i, int l, int r, Fn cmp) { while(l < r) { int m = (l + r) / 2; if(cmp(ask(0, m), ask(0, m, i))) r = m; else l = m+1; } return l; } }; void Solve(int N_) { N = N_; for(int i = 1; i < N; i++) { if(ask(0, i-1) >= ask(0, i)) { int cc = ask(0, i-1) == ask(0, i) ? 1 : 2; int j = work(i, 0, i-1, greater_equal<int>()); addEdge(i, j); if(cc == 2) { j = work(i, j+1, i-1, greater<int>()); addEdge(i, j); } } } for(int i = 0; i < N; i++) { G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end()); } vector<int> res; res.reserve(N); int u = 0, p = -1; while(G[u].size() > 1) u++; while((int)res.size() < N) { res.push_back(u+1); for(int v : G[u]) { if(v != p) { p = u; u = v; break; } } } Answer(res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...