#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,a[110],tany[110],i,j,b1[110],b2[110],te1,te2,jaw1[110],jaw2[110];
vector<ll> v1[110],v2[110];
ll tanya()
{
cout<<"query";
ll ii;
for(ii=1;ii<=n;ii++)cout<<" "<<tany[ii];
cout<<endl;
ll H=0;
cin>>H;
return H;
}
void cek(ll aa,ll bb)
{
ll ii;
vector<pair<ll,ll> > A;
for(ii=1;ii<=n;ii++)
if(ii!=aa&&ii!=bb)
A.pb(mp(a[ii],ii));
sort(A.begin(),A.end());
for(ii=0;ii<A.size();ii++)
tany[A[ii].se]=ii+1;
if(a[aa]<a[bb])
{
tany[aa]=n;
tany[bb]=n-1;
}
else
{
tany[aa]=n-1;
tany[bb]=n;
}
for(ii=1;ii<=n;ii++)
tany[ii]=a[ii];
swap(tany[aa],tany[bb]);
if(!tanya())
{
if(a[aa]<a[bb])v1[aa].pb(bb);
else v1[bb].pb(aa);
if(a[aa]<a[bb])v2[aa].pb(bb);
else v2[bb].pb(aa);
}
}
void dfs1(ll aa)
{
b1[aa]=1;
ll ii;
for(ii=0;ii<v1[aa].size();ii++)
if(!b1[v1[aa][ii]])
dfs1(v1[aa][ii]);
jaw1[aa]=te1;
te1--;
}
void dfs2(ll aa)
{
b2[aa]=1;
ll ii;
for(ii=0;ii<v2[aa].size();ii++)
if(!b2[v2[aa][ii]])
dfs2(v2[aa][ii]);
jaw2[aa]=te2;
te2--;
}
int main()
{
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
cek(i,j);
cout<<"end"<<endl;
for(i=1;i<=n;i++)sort(v1[i].begin(),v1[i].end());
for(i=1;i<=n;i++)sort(v2[i].begin(),v2[i].end());
for(i=1;i<=n;i++)reverse(v1[i].begin(),v1[i].end());
te1=n;
for(i=n;i>=1;i--)
if(!b1[i])
dfs1(i);
te2=n;
for(i=1;i<=n;i++)
if(!b2[i])
dfs2(i);
for(i=1;i<=n;i++)
if(i<n)cout<<jaw1[i]<<" ";
else cout<<jaw1[i]<<endl;
for(i=1;i<=n;i++)
if(i<n)cout<<jaw2[i]<<" ";
else cout<<jaw2[i]<<endl;
}
Compilation message
zagonetka.cpp: In function 'void cek(ll, ll)':
zagonetka.cpp:28:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ii=0;ii<A.size();ii++)
~~^~~~~~~~~
zagonetka.cpp: In function 'void dfs1(ll)':
zagonetka.cpp:55:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ii=0;ii<v1[aa].size();ii++)
~~^~~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs2(ll)':
zagonetka.cpp:65:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ii=0;ii<v2[aa].size();ii++)
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |