結果

問題 No.1306 Exactly 2 Digits
ユーザー ei1333333ei1333333
提出日時 2020-12-05 00:52:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,073 bytes
コンパイル時間 2,431 ms
コンパイル使用メモリ 220,484 KB
実行使用メモリ 25,580 KB
平均クエリ数 1226.98
最終ジャッジ日時 2024-07-17 09:42:55
合計ジャッジ時間 35,512 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,812 KB
testcase_01 RE -
testcase_02 AC 23 ms
24,964 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 23 ms
25,220 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 22 ms
24,964 KB
testcase_10 AC 23 ms
24,836 KB
testcase_11 AC 23 ms
25,220 KB
testcase_12 AC 22 ms
24,580 KB
testcase_13 AC 23 ms
24,812 KB
testcase_14 AC 23 ms
25,436 KB
testcase_15 AC 23 ms
25,452 KB
testcase_16 AC 23 ms
24,556 KB
testcase_17 AC 23 ms
25,196 KB
testcase_18 AC 23 ms
24,940 KB
testcase_19 AC 22 ms
24,812 KB
testcase_20 AC 23 ms
24,812 KB
testcase_21 AC 23 ms
25,196 KB
testcase_22 AC 23 ms
24,556 KB
testcase_23 AC 22 ms
24,556 KB
testcase_24 AC 23 ms
24,556 KB
testcase_25 AC 23 ms
24,940 KB
testcase_26 AC 23 ms
25,196 KB
testcase_27 AC 23 ms
24,812 KB
testcase_28 AC 23 ms
24,940 KB
testcase_29 AC 23 ms
25,196 KB
testcase_30 AC 24 ms
24,812 KB
testcase_31 AC 23 ms
24,812 KB
testcase_32 AC 23 ms
25,196 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 24 ms
24,940 KB
testcase_36 RE -
testcase_37 AC 23 ms
24,940 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 24 ms
25,196 KB
testcase_43 AC 25 ms
24,812 KB
testcase_44 AC 28 ms
24,940 KB
testcase_45 AC 26 ms
24,812 KB
testcase_46 AC 27 ms
24,568 KB
testcase_47 AC 27 ms
25,052 KB
testcase_48 AC 29 ms
24,812 KB
testcase_49 AC 29 ms
25,196 KB
testcase_50 RE -
testcase_51 AC 32 ms
25,196 KB
testcase_52 AC 35 ms
24,556 KB
testcase_53 AC 36 ms
25,196 KB
testcase_54 RE -
testcase_55 RE -
testcase_56 AC 45 ms
24,940 KB
testcase_57 AC 47 ms
25,196 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 AC 47 ms
24,556 KB
testcase_61 AC 58 ms
24,940 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 AC 53 ms
25,196 KB
testcase_65 AC 71 ms
24,812 KB
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 97 ms
24,556 KB
testcase_69 AC 90 ms
24,940 KB
testcase_70 AC 144 ms
24,556 KB
testcase_71 RE -
testcase_72 AC 136 ms
24,940 KB
testcase_73 AC 155 ms
25,196 KB
testcase_74 AC 111 ms
24,556 KB
testcase_75 RE -
testcase_76 AC 182 ms
24,812 KB
testcase_77 AC 216 ms
24,812 KB
testcase_78 RE -
testcase_79 RE -
testcase_80 AC 206 ms
24,940 KB
testcase_81 AC 273 ms
24,556 KB
testcase_82 RE -
testcase_83 AC 191 ms
24,812 KB
testcase_84 AC 194 ms
24,812 KB
testcase_85 RE -
testcase_86 AC 244 ms
24,844 KB
testcase_87 AC 283 ms
24,812 KB
testcase_88 RE -
testcase_89 AC 370 ms
24,812 KB
testcase_90 RE -
testcase_91 RE -
testcase_92 AC 344 ms
24,796 KB
testcase_93 AC 296 ms
24,940 KB
testcase_94 RE -
testcase_95 AC 336 ms
24,940 KB
testcase_96 RE -
testcase_97 AC 172 ms
24,940 KB
testcase_98 RE -
testcase_99 RE -
testcase_100 AC 340 ms
24,812 KB
testcase_101 AC 439 ms
24,556 KB
testcase_102 AC 297 ms
24,940 KB
testcase_103 RE -
testcase_104 AC 239 ms
24,556 KB
testcase_105 RE -
testcase_106 AC 403 ms
24,940 KB
testcase_107 RE -
testcase_108 RE -
testcase_109 RE -
testcase_110 AC 143 ms
24,556 KB
testcase_111 RE -
testcase_112 AC 134 ms
25,196 KB
testcase_113 RE -
testcase_114 AC 149 ms
24,940 KB
testcase_115 AC 247 ms
25,196 KB
testcase_116 RE -
testcase_117 AC 376 ms
24,812 KB
testcase_118 RE -
testcase_119 RE -
testcase_120 AC 152 ms
25,196 KB
testcase_121 AC 239 ms
24,812 KB
testcase_122 AC 189 ms
24,940 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 < M; 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;
        }
      }
      assert(~y);
      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