結果

問題 No.2496 LCM between Permutations
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-01 01:38:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 4,469 ms
コンパイル使用メモリ 259,416 KB
実行使用メモリ 24,396 KB
平均クエリ数 952.83
最終ジャッジ日時 2023-09-06 09:43:36
合計ジャッジ時間 8,392 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,372 KB
testcase_01 AC 24 ms
23,856 KB
testcase_02 AC 23 ms
23,388 KB
testcase_03 AC 24 ms
24,276 KB
testcase_04 AC 25 ms
24,360 KB
testcase_05 AC 25 ms
24,024 KB
testcase_06 AC 24 ms
23,640 KB
testcase_07 AC 24 ms
23,832 KB
testcase_08 AC 25 ms
23,424 KB
testcase_09 AC 24 ms
23,544 KB
testcase_10 AC 25 ms
24,360 KB
testcase_11 AC 26 ms
23,436 KB
testcase_12 AC 25 ms
24,348 KB
testcase_13 AC 25 ms
23,652 KB
testcase_14 AC 25 ms
23,400 KB
testcase_15 AC 31 ms
23,436 KB
testcase_16 AC 32 ms
24,036 KB
testcase_17 AC 33 ms
23,640 KB
testcase_18 AC 87 ms
24,396 KB
testcase_19 AC 69 ms
23,640 KB
testcase_20 AC 92 ms
24,240 KB
testcase_21 AC 81 ms
24,336 KB
testcase_22 AC 79 ms
23,532 KB
testcase_23 AC 104 ms
23,640 KB
testcase_24 AC 88 ms
24,300 KB
testcase_25 AC 114 ms
24,012 KB
testcase_26 AC 112 ms
23,676 KB
testcase_27 AC 112 ms
23,844 KB
testcase_28 AC 111 ms
23,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)

int guess(int i, int j) {
  cout << "? " << (i + 1) << " " << (j + 1) << endl;
  int l;
  cin >> l;
  return l;
}

int main() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << "! 1 1" << endl;
  } else {
    int p = n / 2 + 1;
    for (; true; p++) {
      bool ok = true;
      for (int d = 2; d * d <= p; d += (d & 1) + 1) ok &= p % d != 0;
      if (ok) break;
    }

    int x = -1, y = -1;
    rep(i, 0, n) {
      int l = guess(i, i);
      if (l % p == 0) {
        if (x == -1)
          x = i;
        else
          y = i;
      }
    }

    if (y == -1) {
      y = x;
    } else {
      if (guess(x, y) != p) swap(x, y);
    }

    vector<int> a(n), b(n);
    a[x] = p;
    b[y] = p;
    rep(i, 0, n) {
      if (i != x) a[i] = guess(i, y) / p;
      if (i != y) b[i] = guess(x, i) / p;
    }

    cout << "!";
    rep(i, 0, n) cout << " " << a[i];
    rep(i, 0, n) cout << " " << b[i];
    cout << endl;
  }
}
0