# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61721 | kjp4155 | Library (JOI18_library) | C++17 | 686 ms | 700 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
#define sz(x) (int) x.size()
bool vis[1050];
int L;
vector<int> rans, lans;
void Solve(int N)
{
if( N == 1 ){
lans.push_back(1);
Answer(lans);
return;
}
// find leftmost
for(int i=1;i<=N;i++){
vector<int> qv;
for(int j=1;j<=N;j++){
qv.push_back(1);
}
qv[i-1] = 0;
int res1 = Query(qv);
if( sz(lans) == 0 && res1 == 1 ){
lans.push_back(i); vis[i] = 1;
}
else if( sz(rans) == 0 && res1 == 1 ){
rans.push_back(i); vis[i] = 1;
}
}
vector<int> qv(N);
// find left
while( sz(lans) + sz(rans) < N ){
int L = lans[sz(lans)-1];
int R = rans[sz(rans)-1];
int lt = 0, rt = 0;
for(int k=0;k<10;k++){
for(auto& e : qv) e = 0;
for(int i=1;i<=N;i++)if(!vis[i]){
if( i & (1<<k) ) qv[i-1] = 1;
}
bool all_zero = true, all_one = true;
for(auto e : qv) if( e != 0 ) all_zero = false;
for(auto e : qv) if( e != 1 ) all_one = false;
if( all_zero ) continue;
int res1 = Query(qv);
qv[L-1] = 1;
int res2 = Query(qv);
qv[L-1] = 0;
qv[R-1] = 1;
int res3 = Query(qv);
if( res1 == res2 ) lt |= (1<<k);
if( res1 == res3 ) rt |= (1<<k);
}
lans.push_back(lt); vis[lt] = 1;
if( lt != rt ){
rans.push_back(rt); vis[rt] = 1;
}
}
for(int i=sz(rans)-1;i>=0;i--) lans.push_back(rans[i]);
//for(auto e : ans ) printf("%d ",e);
Answer(lans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |