結果

問題 No.2496 LCM between Permutations
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-09-01 01:29:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,208 bytes
コンパイル時間 4,278 ms
コンパイル使用メモリ 259,628 KB
実行使用メモリ 24,384 KB
平均クエリ数 953.28
最終ジャッジ日時 2023-09-06 09:43:48
合計ジャッジ時間 12,087 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
23,412 KB
testcase_02 AC 25 ms
23,544 KB
testcase_03 AC 25 ms
23,652 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 AC 25 ms
24,024 KB
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

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) {
        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