# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
804466 | 2023-08-03T08:53:24 Z | vjudge1 | 도서관 (JOI18_library) | C++17 | 0 ms | 0 KB |
#ifdef Home #define _GLIBCXX_DEBUG #endif // Home #include <bits/stdc++.h> #include <library.h> using namespace std; typedef long long ll; typedef long double ld; void Solve(int N) { srand(time(0)); vector < int > M(N); deque < int > dq; vector < int > books(N); iota(books.begin(), books.end(), 0); random_shuffle(books.begin(), books.end()); dq.push_back(books.back()); books.pop_back(); bool ok = true; for(; ok;) { ok = false; M[dq.back()] = 1; for(int i = 0; i < (int)books.size(); ++ i) { M[books[i]] = 1; int ans = Query(M); M[books[i]] = 0; if(ans == 1) { dq.push_back(books[i]); books.erase(books.begin() + i); ok = true; break; } } M[dq.back()] = 0; } for(ok = true; ok;) { ok = false; M[dq.front()] = 1; for(int i = 0; i < (int)books.size(); ++ i) { M[books[i]] = 1; int ans = Query(M); M[books[i]] = 0; if(ans == 1) { dq.push_front(books[i]); books.erase(books.begin() + i); ok = true; break; } } M[dq.front()] = 0; } vector < int > res; for(auto &i : dq) { res.push_back(i + 1); } Answer(res); } main() { Solve(5); }