Submission #47857

#TimeUsernameProblemLanguageResultExecution timeMemory
47857mirbek01Library (JOI18_library)C++17
100 / 100
515 ms656 KiB
#include <cstdio> #include <vector> #include "library.h" using namespace std; void Solve(int N){ vector <int> res(N), M(N), used(N), a(N), b(N); int cur = 0, p1 = 0; a[0] = 0; b[0] = 0; used[0] = 1; while(1){ vector <int> v; for(int i = 0; i < N; i ++) if(!used[i]) v.emplace_back(i); if(!v.size()) break; for(int i = 0; i < v.size(); i ++) M[v[i]] = 1; int A = Query(M); M[cur] = 1; int B = Query(M); M[cur] = 0; for(int i = 0; i < v.size(); i ++) M[v[i]] = 0; if(A < B) break; int lo = 0, hi = v.size() - 1, rs; while(lo <= hi){ int md = (lo + hi) >> 1; for(int i = 0; i <= md; i ++) M[v[i]] = 1; int A = Query(M); M[cur] = 1; int B = Query(M); M[cur] = 0; for(int i = 0; i <= md; i ++) M[v[i]] = 0; if(A >= B){ rs = v[md]; hi = md - 1; } else lo = md + 1; } cur = rs; used[cur] = 1; a[++ p1] = cur; } cur = 0; int p2 = 0; while(1){ vector <int> v; for(int i = 0; i < N; i ++) if(!used[i]) v.emplace_back(i); if(!v.size()) break; for(int i = 0; i < v.size(); i ++) M[v[i]] = 1; int A = Query(M); M[cur] = 1; int B = Query(M); M[cur] = 0; for(int i = 0; i < v.size(); i ++) M[v[i]] = 0; if(A < B) break; int lo = 0, hi = v.size() - 1, rs; while(lo <= hi){ int md = (lo + hi) >> 1; for(int i = 0; i <= md; i ++) M[v[i]] = 1; int A = Query(M); M[cur] = 1; int B = Query(M); M[cur] = 0; for(int i = 0; i <= md; i ++) M[v[i]] = 0; if(A >= B){ rs = v[md]; hi = md - 1; } else lo = md + 1; } cur = rs; used[cur] = 1; b[++ p2] = cur; } int ps = 0; for(int i = p2; i > 0; i --){ res[ps ++] = b[i] + 1; } for(int i = 0; i <= p1; i ++){ res[ps ++] = a[i] + 1; } Answer(res); }

Compilation message (stderr)

library.cpp: In function 'void Solve(int)':
library.cpp:19:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < v.size(); i ++)
                            ~~^~~~~~~~~~
library.cpp:25:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < v.size(); i ++)
                            ~~^~~~~~~~~~
library.cpp:60:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < v.size(); i ++)
                            ~~^~~~~~~~~~
library.cpp:66:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int i = 0; i < v.size(); i ++)
                            ~~^~~~~~~~~~
library.cpp:89:21: warning: 'rs' may be used uninitialized in this function [-Wmaybe-uninitialized]
             used[cur] = 1;
                     ^
library.cpp:48:21: warning: 'rs' may be used uninitialized in this function [-Wmaybe-uninitialized]
             used[cur] = 1;
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...