結果

問題 No.2496 LCM between Permutations
ユーザー myaumyau
提出日時 2023-10-06 23:05:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 2,955 bytes
コンパイル時間 4,418 ms
コンパイル使用メモリ 261,508 KB
実行使用メモリ 24,408 KB
平均クエリ数 952.90
最終ジャッジ日時 2023-10-06 23:06:01
合計ジャッジ時間 7,930 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,412 KB
testcase_01 AC 25 ms
24,408 KB
testcase_02 AC 26 ms
23,868 KB
testcase_03 AC 26 ms
24,036 KB
testcase_04 AC 26 ms
24,036 KB
testcase_05 AC 27 ms
23,388 KB
testcase_06 AC 26 ms
24,360 KB
testcase_07 AC 25 ms
23,856 KB
testcase_08 AC 26 ms
24,396 KB
testcase_09 AC 27 ms
23,652 KB
testcase_10 AC 27 ms
23,436 KB
testcase_11 AC 27 ms
24,276 KB
testcase_12 AC 27 ms
23,628 KB
testcase_13 AC 27 ms
23,436 KB
testcase_14 AC 28 ms
24,384 KB
testcase_15 AC 33 ms
23,556 KB
testcase_16 AC 35 ms
23,652 KB
testcase_17 AC 36 ms
24,048 KB
testcase_18 AC 94 ms
24,036 KB
testcase_19 AC 74 ms
23,424 KB
testcase_20 AC 98 ms
24,060 KB
testcase_21 AC 86 ms
24,048 KB
testcase_22 AC 82 ms
23,844 KB
testcase_23 AC 108 ms
23,652 KB
testcase_24 AC 93 ms
24,348 KB
testcase_25 AC 118 ms
24,336 KB
testcase_26 AC 117 ms
23,544 KB
testcase_27 AC 118 ms
23,652 KB
testcase_28 AC 120 ms
23,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

//only for atcoder
#include<atcoder/all>
using namespace atcoder;

#define rep(i,l,r) for(ll i=(l); i<(r); i++)
#define rrep(i,l,r) for(ll i=(r)-1; i>=(l); i--)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REV(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MINV(c) *min_element(ALL(c))
#define MAXV(c) *max_element(ALL(c))

template <typename TYPE>
void print(TYPE vec){
  rep(i,0,vec.size()){
    cout << vec[i];
    if(i == vec.size()-1){
      cout << endl;
    }
    else{
      cout << " ";
    }
  }
}

using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VC = vector<char>;
using VVC = vector<VC>;
using VD = vector<ld>;
using VVD = vector<VD>;
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
const ll LINF = 2e18;
const int INF = 2e9;
using mint = modint998244353;

//素数判定
bool prime(int x){
  bool sosu = true;
  if(x <= 1){
    return false;
  }
  for(int j=2; j*j<=x; j++){
    if(x %j == 0){
      sosu = false;
    }
  }
  return sosu;
}

void query(int a, int b){
  cout << "? " << a << " " << b << endl;
}


int main(){
  int N;
  cin >> N;
  if(N == 1){
    cout << "! " << 1 << " " << 1 << endl;
    return 0;
  }
  
  int K = 0;
  rep(i,1,N+1){
    if(prime(i)){
      K = i;
    }
  }
  
  VI pos(0);
  rep(i,0,N){
    query(1,i+1);
    int x;
    cin >> x;
    if(x % K == 0){
      pos.push_back(i);
    }
  }
  
  VI A(N);
  VI B(N);
  
  if(pos.size() == N){
    A[0] = K;
    rep(i,0,N){
      query(1,i+1);
      int x;
      cin >> x;
      B[i] = x / K;
    }
    int p = -1;
    rep(i,0,N){
      if(B[i] == 1){
        p = i;
        break;
      }
    }
    
    rep(i,1,N){
      query(i+1,p+1);
      int x;
      cin >> x;
      if(x % K == 0){
        A[i] = x / K;
        B[p] = K;
      }
      else{
        A[i] = x;
        if(i == 1){
          rep(j,0,N){
            if(B[j] == 1 && p != j){
              B[j] = K;
            }
          }
        }
      }
    }
  }
  
  else{
    B[pos[0]] = K;
    
    rep(i,0,N){
      query(i+1,pos[0]+1);
      int x;
      cin >> x;
      A[i] = x / K;
    }
    int p = -1;
    rep(i,0,N){
      if(A[i] == 1){
        p = i;
        break;
      }
    }
    
    rep(i,0,N){
      if(i == pos[0]){
        continue;
      }
      query(p+1, i+1);
      int x;
      cin >> x;
      if(x % K == 0){
        B[i] = x / K;
        A[p] = K;
      }
      else{
        B[i] = x;
        if(i == 1){
          rep(j,0,N){
            if(A[j] == 1 && p != j){
              A[j] = K;
            }
          }
        }
      }
    }
  }
  
  
  cout << "! ";
  rep(i,0,N){
    cout << A[i] << " ";
  }
  print<VI>(B);
}
0