이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int n;
vector<int> ans;
bitset<1005> rem;
vector<int> q;
void dnc(int idx,int sz){
if(sz<=1){
for(int i=0;i<n;i++)if(rem[i]){ans[idx]=i;break;}
return;
}
int m=(sz-1)/2;
for(int i=0;i<n;i++)q[i]=0;
int x=0;
for(int i=0;i<n&&x<=m;i++)if(rem[i]){q[i]=1;x++;}
int cur=Query(q);
for(int i=0;i<idx;i++)q[ans[i]]=1;
if(cur==Query(q)){
x=0;
for(int i=0;i<n;i++){
if(rem[i]){
if(x>m){
rem[i]=0;
}
x++;
}
}
dnc(idx,m+1);
}else{
x=0;
for(int i=0;i<n;i++){
if(rem[i]){
if(x<=m){
rem[i]=0;
}
x++;
}
}
dnc(idx,sz-m-1);
}
}
void Solve(int N){
n=N;
ans.resize(n);
q.resize(n);
vector<int> m(N);
for(int i=0;i<n;i++)m[i]=1;
for(int i=0;i<n;i++){
m[i]=0;
if(Query(m)==1){
ans[0]=i;
//printf("%d ",ans[0]);
for(int j=1;j<n;j++){
for(int k=0;k<n;k++){
rem[k]=(m[k]==1?1:0);
}
dnc(j,n-j);
assert(ans[j]>=0&&ans[j]<n);
m[ans[j]]=0;
//printf("%d ",ans[j]);
}
for(int j=0;j<n;j++)ans[j]++;
Answer(ans);
return;
}
m[i]=1;
}
}
/*
5
4
2
5
3
1
9
7
2
1
6
4
8
3
9
5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |