結果

問題 No.1306 Exactly 2 Digits
ユーザー risujirohrisujiroh
提出日時 2020-12-03 00:55:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,882 bytes
コンパイル時間 2,741 ms
コンパイル使用メモリ 235,008 KB
実行使用メモリ 28,360 KB
平均クエリ数 1323.21
最終ジャッジ日時 2024-07-17 07:48:59
合計ジャッジ時間 39,583 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,812 KB
testcase_01 AC 23 ms
24,940 KB
testcase_02 AC 23 ms
24,964 KB
testcase_03 AC 23 ms
24,580 KB
testcase_04 AC 23 ms
24,836 KB
testcase_05 AC 23 ms
25,076 KB
testcase_06 AC 23 ms
25,220 KB
testcase_07 AC 23 ms
25,220 KB
testcase_08 AC 23 ms
24,964 KB
testcase_09 AC 22 ms
24,580 KB
testcase_10 AC 23 ms
24,580 KB
testcase_11 AC 23 ms
25,220 KB
testcase_12 AC 23 ms
24,836 KB
testcase_13 AC 23 ms
25,196 KB
testcase_14 AC 22 ms
25,196 KB
testcase_15 AC 22 ms
24,812 KB
testcase_16 AC 22 ms
25,052 KB
testcase_17 AC 23 ms
24,812 KB
testcase_18 AC 23 ms
25,052 KB
testcase_19 AC 23 ms
24,940 KB
testcase_20 AC 22 ms
25,452 KB
testcase_21 AC 23 ms
25,068 KB
testcase_22 AC 25 ms
24,556 KB
testcase_23 AC 24 ms
24,940 KB
testcase_24 RE -
testcase_25 AC 25 ms
25,184 KB
testcase_26 AC 23 ms
24,812 KB
testcase_27 AC 23 ms
25,196 KB
testcase_28 AC 23 ms
25,068 KB
testcase_29 AC 24 ms
24,812 KB
testcase_30 AC 24 ms
25,184 KB
testcase_31 AC 24 ms
25,452 KB
testcase_32 AC 25 ms
24,812 KB
testcase_33 AC 27 ms
24,940 KB
testcase_34 AC 25 ms
24,812 KB
testcase_35 AC 24 ms
24,812 KB
testcase_36 AC 24 ms
25,196 KB
testcase_37 AC 25 ms
25,196 KB
testcase_38 AC 24 ms
24,812 KB
testcase_39 RE -
testcase_40 AC 24 ms
25,196 KB
testcase_41 RE -
testcase_42 AC 23 ms
24,940 KB
testcase_43 AC 24 ms
24,812 KB
testcase_44 RE -
testcase_45 AC 26 ms
24,556 KB
testcase_46 AC 26 ms
24,812 KB
testcase_47 AC 27 ms
24,812 KB
testcase_48 AC 33 ms
24,800 KB
testcase_49 AC 29 ms
24,812 KB
testcase_50 AC 31 ms
24,556 KB
testcase_51 AC 33 ms
24,812 KB
testcase_52 AC 36 ms
25,184 KB
testcase_53 RE -
testcase_54 AC 37 ms
25,184 KB
testcase_55 AC 47 ms
24,940 KB
testcase_56 AC 46 ms
24,812 KB
testcase_57 AC 52 ms
24,812 KB
testcase_58 AC 59 ms
24,812 KB
testcase_59 AC 57 ms
24,940 KB
testcase_60 RE -
testcase_61 RE -
testcase_62 AC 85 ms
24,940 KB
testcase_63 RE -
testcase_64 AC 100 ms
25,452 KB
testcase_65 AC 101 ms
24,812 KB
testcase_66 AC 113 ms
25,196 KB
testcase_67 AC 121 ms
24,812 KB
testcase_68 AC 127 ms
24,812 KB
testcase_69 AC 142 ms
24,812 KB
testcase_70 AC 162 ms
24,556 KB
testcase_71 AC 167 ms
24,812 KB
testcase_72 AC 177 ms
24,812 KB
testcase_73 AC 187 ms
25,196 KB
testcase_74 AC 222 ms
25,240 KB
testcase_75 AC 229 ms
24,556 KB
testcase_76 AC 268 ms
24,940 KB
testcase_77 AC 289 ms
24,812 KB
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 AC 369 ms
25,928 KB
testcase_82 RE -
testcase_83 AC 484 ms
27,208 KB
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 473 ms
26,952 KB
testcase_87 AC 509 ms
27,464 KB
testcase_88 RE -
testcase_89 AC 499 ms
27,336 KB
testcase_90 AC 526 ms
27,592 KB
testcase_91 AC 456 ms
26,824 KB
testcase_92 AC 491 ms
27,464 KB
testcase_93 RE -
testcase_94 AC 431 ms
26,568 KB
testcase_95 AC 474 ms
27,464 KB
testcase_96 AC 426 ms
26,592 KB
testcase_97 AC 489 ms
27,336 KB
testcase_98 AC 420 ms
26,440 KB
testcase_99 AC 449 ms
26,696 KB
testcase_100 AC 453 ms
26,312 KB
testcase_101 RE -
testcase_102 AC 429 ms
26,440 KB
testcase_103 AC 439 ms
26,696 KB
testcase_104 AC 471 ms
27,080 KB
testcase_105 AC 531 ms
28,104 KB
testcase_106 AC 456 ms
26,696 KB
testcase_107 AC 548 ms
28,352 KB
testcase_108 AC 520 ms
28,096 KB
testcase_109 AC 563 ms
27,848 KB
testcase_110 AC 458 ms
27,208 KB
testcase_111 AC 520 ms
27,976 KB
testcase_112 AC 417 ms
26,440 KB
testcase_113 RE -
testcase_114 RE -
testcase_115 AC 506 ms
27,464 KB
testcase_116 RE -
testcase_117 AC 513 ms
27,720 KB
testcase_118 AC 554 ms
27,592 KB
testcase_119 AC 523 ms
27,848 KB
testcase_120 AC 450 ms
26,824 KB
testcase_121 AC 489 ms
27,208 KB
testcase_122 AC 483 ms
27,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

struct random : std::mt19937 {
  using std::mt19937::mt19937;
  using std::mt19937::operator();

  static int64_t gen_seed() {
    return std::chrono::steady_clock::now().time_since_epoch().count();
  }

  random() : std::mt19937(gen_seed()) {}

  template <class Int>
  auto operator()(Int a, Int b)
      -> std::enable_if_t<std::is_integral_v<Int>, Int> {
    return std::uniform_int_distribution<Int>(a, b)(*this);
  }
  template <class Real>
  auto operator()(Real a, Real b)
      -> std::enable_if_t<std::is_floating_point_v<Real>, Real> {
    return std::uniform_real_distribution<Real>(a, b)(*this);
  }
} rng;

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();

  int num_queries = 0;
  auto query = [&](int i, int j) -> array<int, 2> {
    assert(0 <= i), assert(i < n * (n - 1));
    assert(0 <= j), assert(j < n * (n - 1));
    ++num_queries;
    assert(num_queries <= n * (n - 1) / 2 * 3);
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    array<int, 2> res;
    if (OjLocal<0, 1>) {
      static vector<int> ans;
      if (empty(ans)) {
        ans.resize(n * (n - 1));
        iota(ALL(ans), n);
        shuffle(ALL(ans), rng);
        DUMP(ans);
      }
      res[0] = ans[i] / n - ans[j] / n;
      res[1] = ans[i] % n - ans[j] % n;
      sort(ALL(res));
    } else {
      res = {scan(), scan()};
    }
    assert(is_sorted(ALL(res)));
    return res;
  };

  map<map<int, int>, int> mp;
  for (int j : Rep(n, n * n)) {
    map<int, int> cnt;
    for (int i : Rep(n, n * n))
      if (i != j) {
        ++cnt[i / n - j / n];
        ++cnt[i % n - j % n];
      }
    mp[cnt] = j;
  }
  assert(int(size(mp)) == n * (n - 1));

  vector<array<int, 2>> res(n * (n - 1));
  map<int, int> cnt;
  for (int i : Rep(1, n * (n - 1))) {
    res[i] = query(i, 0);
    for (int z : Rep(2)) ++cnt[res[i][z]];
  }
  assert(mp.count(cnt));

  vector<int> ans(n * (n - 1));
  ans[0] = mp[cnt];

  vector<array<int, 2>> pre(n * n);
  for (int x : Rep(n, n * n)) {
    pre[x][0] = x / n - ans[0] / n;
    pre[x][1] = x % n - ans[0] % n;
    sort(ALL(pre[x]));
  }

  vector<vector<int>> pos(n * n);
  pos[ans[0]] = {0};
  for (int i : Rep(1, n * (n - 1))) {
    for (int x : Rep(n, n * n))
      if (x != ans[0] and res[i] == pre[x]) {
        pos[x].push_back(i);
      }
  }
  DUMP(pos);

  int off = -1;
  for (int x : Rep(n, n * n))
    if (size(pos[x]) == 1) {
      ans[pos[x][0]] = x;
      if (x != ans[0] and x / n - ans[0] / n != x % n - ans[0] % n) off = x;
    }
  DUMP(off);

  int pos_off = find(ALL(ans), off) - begin(ans);
  assert(pos_off < n * (n - 1));
  for (int x : Rep(n, n * n))
    if (size(pos[x]) == 2) {
      for (int i : pos[x]) {
        array<int, 2> expected;
        expected[0] = x / n - off / n;
        expected[1] = x % n - off % n;
        sort(ALL(expected));
        if (query(i, pos_off) == expected) {
          ans[i] = x;
          for (int y : Rep(n, n * n))
            if (y != x and pos[y] == pos[x]) {
              int other = pos[x][0] ^ pos[x][1] ^ i;
              ans[other] = y;
              pos[y].clear();
            }
          break;
        }
      }
    }

  cout << '!';
  for (auto&& e : ans) cout << ' ' << e;
  cout << endl;
}
0