QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745711 | #9432. Permutation | hotdogseller | TL | 1ms | 3800kb | C++14 | 1.9kb | 2024-11-14 11:11:11 | 2024-11-14 11:11:12 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 1005
#define INF 1e18
//#define int long long
using namespace std;
inline int read(){
int lre=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-'){
f=-1;
}
c=getchar();
}
while(c>='0'&&c<='9'){
lre=(lre<<3)+(lre<<1)+(c-'0');
c=getchar();
}
return lre*f;
}
int n;
int arr[maxn];
int query(int l,int r,int x,int y){
printf("0 ");
int mid=l+r>>1;
for(int i=1;i<=mid;++i){
printf("%lld ",x);
}
for(int j=mid+1;j<=n;j++){
printf("%lld ",y);
}
putchar('\n');
fflush(stdout);
return read();
}
void print(){
printf("1 ");
for(int i=1;i<=n;++i){
printf("%lld ",arr[i]);
}
putchar('\n');
fflush(stdout);
}
void dfs(int l,int r,vector<int> v){
if(l==r){
arr[l]=v[0];
return;//递归边界
}
int mid=l+r>>1;
vector<int> a,b;//左,右节点
random_shuffle(v.begin(),v.end());
int i=0,lst=0;
while(i+1<v.size()){
int lre=query(l,r,v[i],v[i+1]);
if(lre==0){
//v[i+1]在左,v[i]在右
a.push_back(v[i+1]);
// cout<<v[i+1]<<" to left!"<<endl;
b.push_back(v[i]);
// cout<<v[i]<<" to right!"<<endl;
for(int j=lst;j<i;j++){
b.push_back(v[j]);
}
lst=++i;
}else if(lre==2){
a.push_back(v[i]);
b.push_back(v[i+1]);
for(int j=lst;j<i;j++){
a.push_back(v[j]);
}
lst=++i;
}else{
//lre=1说明v[i]和v[i+1]在同侧
i++;
}
}
if(a.size()<mid-l+1){
//向左填
for(int i=lst;i<v.size();++i){
a.push_back(v[i]);
}
}else{
//向右填
for(int i=lst;i<v.size();++i){
b.push_back(v[i]);
}
}
dfs(l,mid,a);
dfs(mid+1,r,b);
}//左,右,可能存在节点
signed main(){
srand(time(0));
n=read();
vector<int> v0;
for(int i=1;i<=n;i++){
v0.push_back(i);
}
dfs(1,n,v0);
print();
return 0;
}
/*
4
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3800kb
input:
5 1 1 2 1 2 0 0 0 2
output:
0 3 3 3 4 4 0 4 4 4 2 2 0 2 2 2 5 5 0 5 5 5 1 1 0 3 3 2 2 2 0 2 2 4 4 4 0 4 3 3 3 3 0 5 5 5 5 1 0 1 1 1 1 5 1 3 4 2 1 5
result:
ok Accepted
Test #2:
score: -100
Time Limit Exceeded
input:
1000 1 1 1 1 0 2 0 2 1 0 1 1 1 2 1 0 2 1 0 2 1 0 1 1 2 1 0 1 2 0 1 1 1 1 1 1 2 0 2 1 0 1 2 0 2 0 2 1 1 0 1 2 1 1 0 2 0 2 0 1 1 2 1 0 1 2 0 2 0 2 1 1 0 2 1 1 0 1 2 1 1 0 2 0 2 1 0 1 2 0 1 1 2 0 2 1 1 0 1 2 0 1 1 2 0 2 0 2 1 0 1 1 1 1 2 0 1 1 1 1 2 0 2 1 1 1 1 1 1 1 0 1 2 1 0 1 1 2 0 2 0 1 2 1 1 0 2 1...
output:
0 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 334 33...