結果

問題 No.2124 Guess the Permutation
ユーザー umezo
提出日時 2024-01-11 01:21:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 194,872 KB
最終ジャッジ日時 2025-02-18 17:06:32
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  int sum=n*(n+1)/2;
  vector<int> ANS(n+1);
  vector<int> A(n+1,1);
  A[0]=0;
  int tmp=sum;
  for(int i=n-1;i>=2;i--){
    cout<<"? "<<1<<" "<<i<<endl;
    int a;
    cin>>a;
    ANS[i+1]=tmp-a;
    A[tmp-a]=0;
    tmp-=ANS[i+1];
  }
  cout<<"? "<<2<<" "<<n<<endl;
  int a;
  cin>>a;
  ANS[1]=sum-a;
  A[sum-a]=0;
  rep(i,n+1){
    if(A[i]) ANS[2]=i; 
  }
  cout<<'!';
  for(int i=1;i<=n;i++) cout<<" "<<ANS[i];
  cout<<endl;
    
  return 0;
}
0