結果

問題 No.1306 Exactly 2 Digits
ユーザー 👑 emthrmemthrm
提出日時 2020-12-03 01:12:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 2,991 bytes
コンパイル時間 3,392 ms
コンパイル使用メモリ 236,276 KB
実行使用メモリ 67,212 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:36:14
合計ジャッジ時間 34,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,264 KB
testcase_01 AC 24 ms
23,304 KB
testcase_02 AC 23 ms
24,252 KB
testcase_03 AC 24 ms
23,940 KB
testcase_04 AC 24 ms
24,012 KB
testcase_05 AC 24 ms
23,556 KB
testcase_06 AC 24 ms
23,412 KB
testcase_07 AC 25 ms
23,460 KB
testcase_08 AC 25 ms
23,580 KB
testcase_09 AC 23 ms
23,328 KB
testcase_10 AC 25 ms
23,820 KB
testcase_11 AC 23 ms
23,340 KB
testcase_12 AC 24 ms
23,508 KB
testcase_13 AC 24 ms
23,472 KB
testcase_14 AC 24 ms
23,328 KB
testcase_15 AC 24 ms
23,748 KB
testcase_16 AC 24 ms
24,252 KB
testcase_17 AC 24 ms
23,328 KB
testcase_18 AC 24 ms
23,964 KB
testcase_19 AC 23 ms
23,964 KB
testcase_20 AC 24 ms
23,328 KB
testcase_21 AC 25 ms
23,952 KB
testcase_22 AC 24 ms
23,580 KB
testcase_23 AC 24 ms
23,388 KB
testcase_24 AC 25 ms
23,532 KB
testcase_25 AC 25 ms
23,304 KB
testcase_26 AC 25 ms
23,568 KB
testcase_27 AC 26 ms
24,432 KB
testcase_28 AC 26 ms
23,376 KB
testcase_29 AC 25 ms
23,652 KB
testcase_30 AC 25 ms
24,360 KB
testcase_31 AC 25 ms
23,976 KB
testcase_32 AC 26 ms
23,556 KB
testcase_33 AC 26 ms
24,288 KB
testcase_34 AC 26 ms
24,384 KB
testcase_35 AC 25 ms
24,288 KB
testcase_36 AC 26 ms
23,928 KB
testcase_37 AC 25 ms
23,292 KB
testcase_38 AC 26 ms
24,168 KB
testcase_39 AC 26 ms
23,832 KB
testcase_40 AC 26 ms
24,300 KB
testcase_41 AC 26 ms
23,508 KB
testcase_42 AC 26 ms
24,276 KB
testcase_43 AC 26 ms
23,376 KB
testcase_44 AC 27 ms
24,276 KB
testcase_45 AC 27 ms
24,024 KB
testcase_46 AC 27 ms
23,412 KB
testcase_47 AC 29 ms
23,520 KB
testcase_48 AC 31 ms
24,288 KB
testcase_49 AC 31 ms
24,276 KB
testcase_50 AC 32 ms
23,928 KB
testcase_51 AC 35 ms
24,168 KB
testcase_52 AC 37 ms
23,976 KB
testcase_53 AC 41 ms
23,328 KB
testcase_54 AC 41 ms
23,664 KB
testcase_55 AC 46 ms
23,640 KB
testcase_56 AC 47 ms
23,316 KB
testcase_57 AC 51 ms
24,276 KB
testcase_58 AC 56 ms
23,292 KB
testcase_59 AC 56 ms
23,616 KB
testcase_60 AC 68 ms
23,832 KB
testcase_61 AC 75 ms
23,760 KB
testcase_62 AC 78 ms
23,568 KB
testcase_63 AC 88 ms
23,580 KB
testcase_64 AC 92 ms
23,744 KB
testcase_65 AC 100 ms
24,548 KB
testcase_66 AC 112 ms
25,692 KB
testcase_67 AC 120 ms
26,508 KB
testcase_68 AC 129 ms
27,176 KB
testcase_69 AC 142 ms
28,096 KB
testcase_70 AC 154 ms
29,632 KB
testcase_71 AC 168 ms
30,952 KB
testcase_72 AC 180 ms
31,740 KB
testcase_73 AC 192 ms
33,568 KB
testcase_74 AC 217 ms
35,136 KB
testcase_75 AC 229 ms
36,944 KB
testcase_76 AC 257 ms
38,396 KB
testcase_77 AC 277 ms
40,952 KB
testcase_78 AC 304 ms
42,380 KB
testcase_79 AC 333 ms
44,992 KB
testcase_80 AC 359 ms
47,352 KB
testcase_81 AC 362 ms
50,724 KB
testcase_82 AC 416 ms
53,084 KB
testcase_83 AC 474 ms
59,768 KB
testcase_84 AC 486 ms
59,252 KB
testcase_85 AC 561 ms
66,736 KB
testcase_86 AC 465 ms
59,684 KB
testcase_87 AC 506 ms
63,104 KB
testcase_88 AC 566 ms
66,760 KB
testcase_89 AC 481 ms
59,572 KB
testcase_90 AC 532 ms
67,212 KB
testcase_91 AC 449 ms
56,068 KB
testcase_92 AC 501 ms
63,496 KB
testcase_93 AC 487 ms
59,164 KB
testcase_94 AC 437 ms
56,068 KB
testcase_95 AC 477 ms
59,820 KB
testcase_96 AC 433 ms
56,036 KB
testcase_97 AC 493 ms
62,940 KB
testcase_98 AC 429 ms
56,004 KB
testcase_99 AC 443 ms
56,476 KB
testcase_100 AC 445 ms
56,652 KB
testcase_101 AC 482 ms
59,356 KB
testcase_102 AC 433 ms
56,216 KB
testcase_103 AC 443 ms
56,280 KB
testcase_104 AC 473 ms
59,908 KB
testcase_105 AC 540 ms
66,428 KB
testcase_106 AC 463 ms
59,276 KB
testcase_107 AC 534 ms
66,832 KB
testcase_108 AC 529 ms
66,716 KB
testcase_109 AC 554 ms
66,856 KB
testcase_110 AC 466 ms
59,632 KB
testcase_111 AC 533 ms
67,088 KB
testcase_112 AC 426 ms
56,252 KB
testcase_113 AC 560 ms
66,688 KB
testcase_114 AC 525 ms
62,964 KB
testcase_115 AC 506 ms
63,052 KB
testcase_116 AC 565 ms
66,928 KB
testcase_117 AC 509 ms
62,868 KB
testcase_118 AC 553 ms
66,640 KB
testcase_119 AC 532 ms
66,588 KB
testcase_120 AC 462 ms
59,828 KB
testcase_121 AC 477 ms
59,536 KB
testcase_122 AC 475 ms
59,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

pair<int, int> query(int i, int j) {
  cout << "? " << i + 1 << ' ' << j + 1 << endl;
  int p, q; cin >> p >> q;
  return {p, q};
}

int main() {
  int n; cin >> n;
  map<vector<pair<int, int>>, pair<int, int>> mp;
  FOR(si, 1, n) REP(sj, n) {
    vector<pair<int, int>> v;
    FOR(i, 1, n) REP(j, n) {
      if (i != si || j != sj) v.emplace_back(minmax(si - i, sj - j));
    }
    sort(ALL(v));
    mp[v] = {si, sj};
  }
  int m = n * n - n;
  vector<pair<int, int>> res(m), sea;
  FOR(i, 1, m) {
    auto [p, q] = query(0, i);
    res[i] = {p, q};
    sea.emplace_back(p, q);
  }
  sort(ALL(sea));
  vector<pair<int, int>> ans(m, {-1, -1});
  ans[0] = mp[sea];
  map<pair<int, int>, vector<pair<int, int>>> mp2;
  map<pair<int, int>, int> rev;
  rev[ans[0]] = 0;
  FOR(i, 1, n) REP(j, n) {
    if (i != ans[0].first || j != ans[0].second) mp2[minmax(ans[0].first - i, ans[0].second - j)].emplace_back(i, j);
  }
  FOR(idx, 1, m) {
    if (mp2[res[idx]].size() == 1) {
      ans[idx] = mp2[res[idx]][0];
      rev[ans[idx]] = idx;
    }
  }
  FOR(idx, 1, m) {
    if (mp2[res[idx]].size() == 2) {
      auto [p1, q1] = mp2[res[idx]][0];
      auto [p2, q2] = mp2[res[idx]][1];
      for (auto [pr, pos] : rev) {
        auto [p, q] = pr;
        if (minmax(p - p1, q - q1) != minmax(p - p2, q - q2)) {
          auto [res_p, res_q] = query(pos, idx);
          if (res_p == minmax(p - p1, q - q1).first && res_q == minmax(p - p1, q - q1).second) {
            ans[idx] = {p1, q1};
            mp2[res[idx]].erase(mp2[res[idx]].begin());
          } else {
            assert(res_p == minmax(p - p2, q - q2).first && res_q == minmax(p - p2, q - q2).second);
            ans[idx] = {p2, q2};
            mp2[res[idx]].erase(mp2[res[idx]].begin() + 1);
          }
          // rev[ans[idx]] = idx;
          break;
        }
      }
    } else {
      ans[idx] = mp2[res[idx]][0];
      // rev[ans[idx]] = idx;
    }
  }
  cout << "! ";
  REP(i, m) {
    cout << ans[i].first * n + ans[i].second;
    if (i + 1 == m) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
  return 0;
}
0