QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462781 | #1464. Interactive Algorithm | ItsGuitar | RE | 0ms | 0kb | C++14 | 1.4kb | 2024-07-04 04:01:10 | 2024-07-04 04:01:11 |
answer
#include<bits/stdc++.h>
#define TC while(t--)
#define DEBUG(x) cout<<"Debug "<<#x<<':'<<x<<endl;
#define EL "\n"
#define ll long long
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define st first
#define nd second
#define pb push_back
using namespace std;
void fast(){
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void solve(){
int n;
cin>>n;
vector<int> graph[n+1];
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
cout<<"? "<<i<<" "<<j<<" ";
for(int k=1;k<=n-2;k++){
cout<<j+k<<" ";
}
cout<<EL<<flush;
int x;
cin>>x;
if(x==1){
graph[i].pb(j);
graph[j].pb(i);
}
}
}
int start;
for(int i=1;i<=n;i++){
if(sz(graph[i])==1){
start=i;
break;
}
}
vector<int> ans;
queue<int> q;
vector<bool> visited(n+1,false);
visited[start]=true;
q.push(start);
while(!q.empty()){
int u=q.front();
ans.pb(u);
q.pop();
for(auto v:graph[u]){
if(!visited[v]){
visited[v]=true;
q.push(v);
}
}
}
cout<<"? ";
for(auto it:ans) cout<<it<<" ";
cout<<EL<<flush;
int x;
cin>>x;
if(x==n-1){
cout<<"! ";
for(auto it:ans) cout<<it<<" ";
cout<<flush;
}
else{
reverse(ans.begin(),ans.end());
cout<<"! ";
for(auto it:ans) cout<<it<<" ";
cout<<flush;
}
}
int main(){
fast();
solve();
/*int t;
cin>>t;
TC{
solve();
}*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 1
output:
? 1 2 3 4 5 ? 1 3 4 5 6