結果

問題 No.1306 Exactly 2 Digits
ユーザー ei1333333ei1333333
提出日時 2020-12-05 00:54:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,075 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 217,936 KB
実行使用メモリ 24,516 KB
平均クエリ数 1226.98
最終ジャッジ日時 2023-09-24 09:10:42
合計ジャッジ時間 33,380 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,388 KB
testcase_01 RE -
testcase_02 AC 25 ms
23,400 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 26 ms
23,388 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 26 ms
23,520 KB
testcase_10 AC 25 ms
23,412 KB
testcase_11 AC 25 ms
24,372 KB
testcase_12 AC 25 ms
23,532 KB
testcase_13 AC 25 ms
23,376 KB
testcase_14 AC 25 ms
24,360 KB
testcase_15 AC 26 ms
23,400 KB
testcase_16 AC 25 ms
24,012 KB
testcase_17 AC 24 ms
23,640 KB
testcase_18 AC 25 ms
23,628 KB
testcase_19 AC 25 ms
23,832 KB
testcase_20 AC 25 ms
23,412 KB
testcase_21 AC 25 ms
24,396 KB
testcase_22 AC 24 ms
24,000 KB
testcase_23 AC 26 ms
23,664 KB
testcase_24 AC 26 ms
23,388 KB
testcase_25 AC 26 ms
23,400 KB
testcase_26 AC 26 ms
24,216 KB
testcase_27 AC 27 ms
23,820 KB
testcase_28 AC 26 ms
23,808 KB
testcase_29 AC 26 ms
24,036 KB
testcase_30 AC 26 ms
23,388 KB
testcase_31 AC 25 ms
24,012 KB
testcase_32 AC 25 ms
24,036 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 26 ms
23,832 KB
testcase_36 RE -
testcase_37 AC 26 ms
23,640 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 26 ms
24,324 KB
testcase_43 AC 26 ms
23,424 KB
testcase_44 AC 28 ms
23,628 KB
testcase_45 AC 27 ms
24,300 KB
testcase_46 AC 29 ms
24,324 KB
testcase_47 AC 30 ms
23,364 KB
testcase_48 AC 31 ms
23,364 KB
testcase_49 AC 31 ms
23,832 KB
testcase_50 RE -
testcase_51 AC 36 ms
23,652 KB
testcase_52 AC 37 ms
23,832 KB
testcase_53 AC 38 ms
24,036 KB
testcase_54 RE -
testcase_55 RE -
testcase_56 AC 49 ms
23,508 KB
testcase_57 AC 51 ms
23,640 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 AC 51 ms
23,424 KB
testcase_61 AC 60 ms
23,532 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 AC 54 ms
23,532 KB
testcase_65 AC 73 ms
24,048 KB
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 100 ms
23,412 KB
testcase_69 AC 91 ms
24,264 KB
testcase_70 AC 145 ms
23,832 KB
testcase_71 RE -
testcase_72 AC 136 ms
24,036 KB
testcase_73 AC 156 ms
23,640 KB
testcase_74 AC 113 ms
24,036 KB
testcase_75 RE -
testcase_76 AC 195 ms
23,376 KB
testcase_77 AC 219 ms
23,652 KB
testcase_78 RE -
testcase_79 RE -
testcase_80 AC 205 ms
24,024 KB
testcase_81 AC 276 ms
23,784 KB
testcase_82 RE -
testcase_83 AC 197 ms
23,652 KB
testcase_84 AC 195 ms
23,628 KB
testcase_85 RE -
testcase_86 AC 242 ms
23,376 KB
testcase_87 AC 283 ms
24,324 KB
testcase_88 RE -
testcase_89 AC 373 ms
24,360 KB
testcase_90 RE -
testcase_91 RE -
testcase_92 AC 343 ms
24,324 KB
testcase_93 AC 296 ms
23,988 KB
testcase_94 RE -
testcase_95 AC 341 ms
23,808 KB
testcase_96 RE -
testcase_97 AC 177 ms
24,060 KB
testcase_98 RE -
testcase_99 RE -
testcase_100 AC 343 ms
24,060 KB
testcase_101 AC 437 ms
23,820 KB
testcase_102 AC 300 ms
23,664 KB
testcase_103 RE -
testcase_104 AC 245 ms
23,532 KB
testcase_105 RE -
testcase_106 AC 402 ms
24,024 KB
testcase_107 RE -
testcase_108 RE -
testcase_109 RE -
testcase_110 AC 144 ms
23,364 KB
testcase_111 RE -
testcase_112 AC 137 ms
24,024 KB
testcase_113 RE -
testcase_114 AC 148 ms
23,664 KB
testcase_115 AC 249 ms
23,640 KB
testcase_116 RE -
testcase_117 AC 372 ms
23,388 KB
testcase_118 RE -
testcase_119 RE -
testcase_120 AC 155 ms
23,376 KB
testcase_121 AC 239 ms
23,520 KB
testcase_122 AC 193 ms
23,376 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