結果

問題 No.1306 Exactly 2 Digits
ユーザー risujirohrisujiroh
提出日時 2020-12-03 00:41:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,422 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 232,084 KB
実行使用メモリ 27,844 KB
平均クエリ数 1757.67
最終ジャッジ日時 2023-09-24 07:27:49
合計ジャッジ時間 42,067 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,048 KB
testcase_01 WA -
testcase_02 AC 25 ms
23,520 KB
testcase_03 WA -
testcase_04 AC 26 ms
24,288 KB
testcase_05 AC 26 ms
23,928 KB
testcase_06 AC 26 ms
23,940 KB
testcase_07 AC 26 ms
23,412 KB
testcase_08 AC 25 ms
24,288 KB
testcase_09 AC 25 ms
23,292 KB
testcase_10 AC 26 ms
23,928 KB
testcase_11 WA -
testcase_12 AC 24 ms
24,168 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 25 ms
23,292 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
24,300 KB
testcase_20 AC 25 ms
23,532 KB
testcase_21 AC 25 ms
23,400 KB
testcase_22 AC 25 ms
23,760 KB
testcase_23 AC 25 ms
23,928 KB
testcase_24 WA -
testcase_25 AC 25 ms
23,532 KB
testcase_26 AC 27 ms
23,580 KB
testcase_27 WA -
testcase_28 AC 25 ms
23,808 KB
testcase_29 AC 25 ms
23,616 KB
testcase_30 AC 25 ms
23,616 KB
testcase_31 AC 25 ms
23,532 KB
testcase_32 WA -
testcase_33 AC 26 ms
23,304 KB
testcase_34 WA -
testcase_35 AC 26 ms
23,460 KB
testcase_36 AC 26 ms
23,988 KB
testcase_37 AC 26 ms
24,204 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 27 ms
24,372 KB
testcase_44 WA -
testcase_45 AC 29 ms
23,364 KB
testcase_46 AC 30 ms
23,928 KB
testcase_47 AC 32 ms
23,820 KB
testcase_48 WA -
testcase_49 AC 32 ms
24,288 KB
testcase_50 AC 35 ms
23,616 KB
testcase_51 AC 36 ms
23,580 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 39 ms
23,604 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 56 ms
23,436 KB
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 92 ms
23,280 KB
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 168 ms
23,448 KB
testcase_73 AC 180 ms
23,364 KB
testcase_74 WA -
testcase_75 AC 215 ms
23,364 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 AC 335 ms
25,072 KB
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 AC 462 ms
26,904 KB
testcase_91 WA -
testcase_92 AC 442 ms
27,100 KB
testcase_93 WA -
testcase_94 AC 400 ms
26,204 KB
testcase_95 WA -
testcase_96 AC 391 ms
25,616 KB
testcase_97 AC 434 ms
26,528 KB
testcase_98 AC 380 ms
25,948 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 395 ms
25,800 KB
testcase_103 WA -
testcase_104 WA -
testcase_105 AC 481 ms
27,052 KB
testcase_106 AC 401 ms
26,436 KB
testcase_107 AC 484 ms
27,276 KB
testcase_108 AC 460 ms
27,416 KB
testcase_109 WA -
testcase_110 AC 419 ms
26,872 KB
testcase_111 AC 470 ms
26,948 KB
testcase_112 AC 380 ms
25,828 KB
testcase_113 WA -
testcase_114 WA -
testcase_115 AC 466 ms
26,804 KB
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 AC 473 ms
26,984 KB
testcase_120 AC 403 ms
26,244 KB
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます

ソースコード

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();

  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));
    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);
      }
  }

  for (int x : Rep(n, n * n))
    if (size(pos[x]) == 1) {
      ans[pos[x][0]] = x;
    }
  int pos_n = find(ALL(ans), n) - begin(ans);
  assert(pos_n < 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 - 1;
        expected[1] = x % n;
        sort(ALL(expected));
        if (query(i, pos_n) == expected) {
          ans[i] = x;
          break;
        }
      }
    }

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