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 <chrono>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include "library.h"
using namespace std;
void Solve(int N)
{
if(N==1)
{
Answer({1});
return;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> M(N);
vector<int> end_point_guesses(N);
iota(end_point_guesses.begin(), end_point_guesses.end(),0);
shuffle(end_point_guesses.begin(),end_point_guesses.end(), rng);
vector<int> res(N);
for(const int& guess: end_point_guesses)
{
for(int i = 0; i < N; i++)
M[i] = i==guess ? 0 : 1;
if(Query(M)==1)
{
res[0] = guess;
break;
}
}
vector<int> done(N,false);
done[res[0]] = true;
for(int g = 0; g < N; g++)
M[g] = 0;
for(int i = 1; i < N; i++)
{
vector<int> candidates; candidates.reserve(N-i);
for(int g = 0; g < N; g++)
if(!done[g])
candidates.push_back(g);
shuffle(candidates.begin(),candidates.end(), rng);
M[res[i-1]] = 1;
for(const int& guess : candidates)
{
M[guess] = 1;
if(Query(M)==1)
{
res[i] = guess;
done[guess] = true;
break;
}
M[guess] = 0;
}
M[res[i-1]] = 0;
}
for(int& g : res)
++g;
Answer(res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |