제출 #1118320

#제출 시각아이디문제언어결과실행 시간메모리
1118320thelegendary08도서관 (JOI18_library)C++17
100 / 100
457 ms604 KiB
#include "library.h" #include<bits/stdc++.h> #define vi vector<int> #define vb vector<bool> #define pb push_back #define f0r(i,n) for(int i = 0; i<n; i++) #define FOR(i, k, n) for(int i = k; i<n; i++) using namespace std; int n; int solve(int prev, vi &v, int l, int r){ if(l == r){ return l; } int mid = (l + r)/2; vi quer(n); for(int i = l; i<=mid; i++){ quer[v[i]] = 1; } quer[prev] = 1; int a1 = Query(quer); quer[prev] = 0; int a2 = Query(quer); if(a1 == a2){ return solve(prev, v, l, mid); } else{ return solve(prev, v, mid+1, r); } } void Solve(int n) { if(n == 1)Answer({1}); else{ ::n = n; int ret; int st; f0r(i, n){ vi quer(n); f0r(j,n){ if(j != i)quer[j] = 1; } //for(auto u : quer)cout<<u<<' '; //cout<<'\n'; ret = Query(quer); if(ret == 1){ st = i; break; } } //cout<<st<<'\n'; vi ans(n); ans[0] = st; vb vis(n,0); vis[st] = 1; int prev = st; FOR(i, 1, n){ vi cur; f0r(j,n){ if(!vis[j])cur.pb(j); } int m = cur.size(); int nxt = solve(prev, cur, 0, m-1); nxt = cur[nxt]; ans[i] = nxt; prev = nxt; vis[nxt] = 1; } f0r(i,n)ans[i]++; //for(auto u : ans)cout<<u<<' '; //cout<<'\n'; Answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...