結果

問題 No.1306 Exactly 2 Digits
ユーザー ei1333333ei1333333
提出日時 2020-12-05 00:56:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 557 ms / 2,000 ms
コード長 4,064 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 218,568 KB
実行使用メモリ 24,372 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 09:13:39
合計ジャッジ時間 24,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,904 KB
testcase_01 AC 25 ms
23,712 KB
testcase_02 AC 25 ms
23,832 KB
testcase_03 AC 24 ms
23,640 KB
testcase_04 AC 24 ms
24,228 KB
testcase_05 AC 25 ms
23,424 KB
testcase_06 AC 24 ms
24,132 KB
testcase_07 AC 24 ms
24,060 KB
testcase_08 AC 23 ms
24,288 KB
testcase_09 AC 24 ms
23,904 KB
testcase_10 AC 26 ms
24,048 KB
testcase_11 AC 25 ms
23,916 KB
testcase_12 AC 25 ms
23,424 KB
testcase_13 AC 24 ms
23,832 KB
testcase_14 AC 24 ms
23,652 KB
testcase_15 AC 24 ms
23,496 KB
testcase_16 AC 24 ms
24,240 KB
testcase_17 AC 24 ms
23,712 KB
testcase_18 AC 25 ms
24,228 KB
testcase_19 AC 24 ms
23,916 KB
testcase_20 AC 25 ms
24,204 KB
testcase_21 AC 25 ms
24,228 KB
testcase_22 AC 24 ms
24,360 KB
testcase_23 AC 24 ms
23,424 KB
testcase_24 AC 24 ms
23,388 KB
testcase_25 AC 24 ms
23,376 KB
testcase_26 AC 25 ms
23,916 KB
testcase_27 AC 22 ms
23,892 KB
testcase_28 AC 24 ms
23,280 KB
testcase_29 AC 24 ms
24,228 KB
testcase_30 AC 24 ms
24,372 KB
testcase_31 AC 24 ms
23,412 KB
testcase_32 AC 25 ms
24,024 KB
testcase_33 AC 24 ms
23,244 KB
testcase_34 AC 24 ms
24,336 KB
testcase_35 AC 24 ms
23,844 KB
testcase_36 AC 25 ms
23,244 KB
testcase_37 AC 24 ms
23,844 KB
testcase_38 AC 25 ms
23,904 KB
testcase_39 AC 26 ms
23,652 KB
testcase_40 AC 25 ms
23,400 KB
testcase_41 AC 25 ms
23,628 KB
testcase_42 AC 26 ms
24,264 KB
testcase_43 AC 25 ms
23,532 KB
testcase_44 AC 27 ms
23,868 KB
testcase_45 AC 26 ms
23,388 KB
testcase_46 AC 26 ms
23,628 KB
testcase_47 AC 28 ms
23,664 KB
testcase_48 AC 29 ms
24,276 KB
testcase_49 AC 31 ms
23,544 KB
testcase_50 AC 30 ms
23,388 KB
testcase_51 AC 33 ms
23,244 KB
testcase_52 AC 36 ms
24,072 KB
testcase_53 AC 37 ms
24,060 KB
testcase_54 AC 39 ms
23,508 KB
testcase_55 AC 42 ms
24,228 KB
testcase_56 AC 48 ms
24,276 KB
testcase_57 AC 47 ms
23,904 KB
testcase_58 AC 46 ms
23,916 KB
testcase_59 AC 56 ms
23,640 KB
testcase_60 AC 50 ms
24,288 KB
testcase_61 AC 59 ms
24,204 KB
testcase_62 AC 64 ms
23,700 KB
testcase_63 AC 75 ms
23,544 KB
testcase_64 AC 55 ms
23,640 KB
testcase_65 AC 73 ms
23,400 KB
testcase_66 AC 68 ms
23,904 KB
testcase_67 AC 69 ms
23,508 KB
testcase_68 AC 99 ms
23,256 KB
testcase_69 AC 92 ms
24,276 KB
testcase_70 AC 146 ms
23,832 KB
testcase_71 AC 85 ms
23,412 KB
testcase_72 AC 135 ms
23,292 KB
testcase_73 AC 157 ms
23,424 KB
testcase_74 AC 112 ms
23,856 KB
testcase_75 AC 168 ms
23,532 KB
testcase_76 AC 181 ms
23,412 KB
testcase_77 AC 215 ms
23,256 KB
testcase_78 AC 148 ms
23,292 KB
testcase_79 AC 267 ms
23,412 KB
testcase_80 AC 205 ms
23,664 KB
testcase_81 AC 270 ms
23,544 KB
testcase_82 AC 242 ms
23,520 KB
testcase_83 AC 188 ms
23,436 KB
testcase_84 AC 189 ms
23,424 KB
testcase_85 AC 311 ms
23,292 KB
testcase_86 AC 234 ms
23,832 KB
testcase_87 AC 280 ms
23,376 KB
testcase_88 AC 229 ms
23,292 KB
testcase_89 AC 359 ms
23,388 KB
testcase_90 AC 483 ms
23,652 KB
testcase_91 AC 407 ms
23,424 KB
testcase_92 AC 336 ms
24,060 KB
testcase_93 AC 293 ms
23,268 KB
testcase_94 AC 138 ms
23,400 KB
testcase_95 AC 333 ms
23,400 KB
testcase_96 AC 348 ms
23,256 KB
testcase_97 AC 173 ms
23,544 KB
testcase_98 AC 128 ms
24,192 KB
testcase_99 AC 288 ms
23,628 KB
testcase_100 AC 333 ms
23,520 KB
testcase_101 AC 434 ms
23,832 KB
testcase_102 AC 293 ms
23,664 KB
testcase_103 AC 293 ms
24,204 KB
testcase_104 AC 236 ms
24,360 KB
testcase_105 AC 360 ms
23,508 KB
testcase_106 AC 391 ms
23,424 KB
testcase_107 AC 302 ms
23,544 KB
testcase_108 AC 441 ms
24,264 KB
testcase_109 AC 164 ms
23,532 KB
testcase_110 AC 140 ms
23,712 KB
testcase_111 AC 138 ms
23,376 KB
testcase_112 AC 134 ms
23,400 KB
testcase_113 AC 289 ms
24,240 KB
testcase_114 AC 149 ms
23,412 KB
testcase_115 AC 244 ms
23,544 KB
testcase_116 AC 557 ms
23,544 KB
testcase_117 AC 371 ms
23,400 KB
testcase_118 AC 541 ms
23,304 KB
testcase_119 AC 383 ms
23,652 KB
testcase_120 AC 155 ms
24,204 KB
testcase_121 AC 239 ms
24,144 KB
testcase_122 AC 188 ms
23,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

pair< int, int > ask(int x, int y) {
  cout << "? " << x << " " << y << endl;
  int p, q;
  cin >> p >> q;
  return {p, q};
}

int main() {
  int N;
  cin >> N;
  int M = N * N - N;
  vector< int > ans(M, -1);

  auto f = [&](int a, int b) {
    int x = a / N - b / N;
    int y = a % N - b % N;
    if(x > y) swap(x, y);
    return make_pair(x, y);
  };

  vector< pair< int, int > > ret;
  for(int i = 1; i < M; i++) {
    ret.emplace_back(ask(1, i + 1));
  }

  {
    auto xs{ret};
    sort(begin(xs), end(xs));
    for(int i = 0; i < M; i++) {
      vector< pair< int, int > > X;
      for(int j = 0; j < M; j++) {
        if(i == j) continue;
        X.emplace_back(f(i + N, j + N));
      }
      sort(begin(X), end(X));
      if(X == xs) {
        ans[0] = i + N;
        break;
      }
    }
  }

  map< int, vector< int > > mp;
  for(int i = 0; i < ret.size(); i++) {
    for(int j = 0; j < M; j++) {
      if(ret[i] == f(ans[0], j + N)) {
        mp[j + N].emplace_back(i + 1);
        break;
      }
    }
  }

  while(mp.size()) {
    auto it = begin(mp);
    while(it != end(mp)) {
      if(it->second.size() == 1) {
        ans[it->second.front()] = it->first;
        it = mp.erase(it);
        continue;
      }
      int x = it->first;
      int y = -1;
      for(int i = x + 1; i < N * N; i++) {
        if(f(ans[0], x) == f(ans[0], i)) {
          y = i;
          break;
        }
      }
      bool check = false;
      for(int i = 0; i < M; i++) {
        if(ans[i] == -1) continue;
        if(f(ans[i], x) != f(ans[i], y)) {
          auto beet = ask(i + 1, it->second.front() + 1);
          if(beet == f(ans[i], x)) {
            ans[it->second.front()] = x;
            ans[it->second.back()] = y;
          } else {
            ans[it->second.front()] = y;
            ans[it->second.back()] = x;
          }
          check = true;
          break;
        }
      }
      if(check) {
        it = mp.erase(it);
      } else {
        ++it;
      }
    }
  }
  cout << "! " << ans << endl;
}


0