#include <bits/stdc++.h>
using namespace std;
int query(vector<int> v)
{
int x;
cout<<"query";
for (int i:v)
cout<<' '<<i;
cout<<endl;
cin>>x;
}
signed main()
{
int n;
cin>>n;
int x;
for (int i=0;i<n;i++)
cin>>x;
if (n<=6)
{
vector<int> v;
for (int i=1;i<=n;i++)
v.push_back(i);
vector<int> ans,ans1;
do
{
x=query(v);
if (x)
{
if (ans.empty())
ans=v;
ans1=v;
}
}while(next_permutation(v.begin(),v.end()));
cout<<"end\n";
for (int i=0;i<n-1;i++)
cout<<ans[i]<<' ';
cout<<ans.back()<<'\n';
for (int i=0;i<n-1;i++)
cout<<ans1[i]<<' ';
cout<<ans1.back()<<endl;
}
else
{
vector<int> v,ans,ans1;
for (int i=1;i<=n;i++)
v.push_back(i);
x=query(v);
ans=ans1=v;
reverse(ans1.begin(),ans1.end());
if (!x)
{
int pi,pj=0;
for (int i=0;i<n && !pj;i++)
for (int j=i+1;j<n && !pj;j++)
{
swap(v[i],v[j]);
if (query(v))
pi=i,pj=j;
swap(v[i],v[j]);
}
for (int i=pi+1;i<=pj;i++)
swap(ans[i],ans[i-1]),swap(ans1[i],ans1[i-1]);
}
cout<<"end\n";
for (int i=0;i<n-1;i++)
cout<<ans[i]<<' ';
cout<<ans.back()<<'\n';
for (int i=0;i<n-1;i++)
cout<<ans1[i]<<' ';
cout<<ans1.back()<<endl;
}
return 0;
}
Compilation message
zagonetka.cpp: In function 'int query(std::vector<int>)':
zagonetka.cpp:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
13 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1 ms |
340 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
0 ms |
344 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |