結果
問題 | No.2577 Simple Permutation Guess |
ユーザー | 👑 rin204 |
提出日時 | 2023-12-05 01:56:42 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 197 ms / 2,000 ms |
コード長 | 4,201 bytes |
コンパイル時間 | 3,466 ms |
コンパイル使用メモリ | 253,864 KB |
実行使用メモリ | 25,592 KB |
平均クエリ数 | 248.84 |
最終ジャッジ日時 | 2024-09-26 23:55:49 |
合計ジャッジ時間 | 18,771 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
24,812 KB |
testcase_01 | AC | 155 ms
25,196 KB |
testcase_02 | AC | 50 ms
25,196 KB |
testcase_03 | AC | 24 ms
25,196 KB |
testcase_04 | AC | 68 ms
25,196 KB |
testcase_05 | AC | 79 ms
24,812 KB |
testcase_06 | AC | 195 ms
25,196 KB |
testcase_07 | AC | 195 ms
24,428 KB |
testcase_08 | AC | 196 ms
24,556 KB |
testcase_09 | AC | 197 ms
24,428 KB |
testcase_10 | AC | 196 ms
24,812 KB |
testcase_11 | AC | 26 ms
25,196 KB |
testcase_12 | AC | 26 ms
24,800 KB |
testcase_13 | AC | 28 ms
25,196 KB |
testcase_14 | AC | 27 ms
24,812 KB |
testcase_15 | AC | 26 ms
24,428 KB |
testcase_16 | AC | 25 ms
25,196 KB |
testcase_17 | AC | 25 ms
25,196 KB |
testcase_18 | AC | 25 ms
25,580 KB |
testcase_19 | AC | 27 ms
25,452 KB |
testcase_20 | AC | 26 ms
24,940 KB |
testcase_21 | AC | 26 ms
25,196 KB |
testcase_22 | AC | 26 ms
25,220 KB |
testcase_23 | AC | 25 ms
25,220 KB |
testcase_24 | AC | 25 ms
24,836 KB |
testcase_25 | AC | 26 ms
24,836 KB |
testcase_26 | AC | 26 ms
24,836 KB |
testcase_27 | AC | 25 ms
24,580 KB |
testcase_28 | AC | 26 ms
24,580 KB |
testcase_29 | AC | 26 ms
24,836 KB |
testcase_30 | AC | 25 ms
25,208 KB |
testcase_31 | AC | 25 ms
25,196 KB |
testcase_32 | AC | 25 ms
24,812 KB |
testcase_33 | AC | 26 ms
25,196 KB |
testcase_34 | AC | 26 ms
25,196 KB |
testcase_35 | AC | 27 ms
25,196 KB |
testcase_36 | AC | 26 ms
24,812 KB |
testcase_37 | AC | 25 ms
24,836 KB |
testcase_38 | AC | 25 ms
24,836 KB |
testcase_39 | AC | 25 ms
24,824 KB |
testcase_40 | AC | 25 ms
25,220 KB |
testcase_41 | AC | 26 ms
24,580 KB |
testcase_42 | AC | 26 ms
24,836 KB |
testcase_43 | AC | 27 ms
24,836 KB |
testcase_44 | AC | 26 ms
25,220 KB |
testcase_45 | AC | 26 ms
25,220 KB |
testcase_46 | AC | 25 ms
25,220 KB |
testcase_47 | AC | 26 ms
25,220 KB |
testcase_48 | AC | 25 ms
24,836 KB |
testcase_49 | AC | 25 ms
25,220 KB |
testcase_50 | AC | 26 ms
24,836 KB |
testcase_51 | AC | 27 ms
24,836 KB |
testcase_52 | AC | 27 ms
24,836 KB |
testcase_53 | AC | 27 ms
24,836 KB |
testcase_54 | AC | 26 ms
25,220 KB |
testcase_55 | AC | 25 ms
24,836 KB |
testcase_56 | AC | 25 ms
24,580 KB |
testcase_57 | AC | 26 ms
25,460 KB |
testcase_58 | AC | 25 ms
24,580 KB |
testcase_59 | AC | 24 ms
25,592 KB |
testcase_60 | AC | 24 ms
24,836 KB |
testcase_61 | AC | 24 ms
25,220 KB |
testcase_62 | AC | 25 ms
24,836 KB |
testcase_63 | AC | 25 ms
24,836 KB |
testcase_64 | AC | 25 ms
25,220 KB |
testcase_65 | AC | 24 ms
25,220 KB |
testcase_66 | AC | 24 ms
24,824 KB |
testcase_67 | AC | 24 ms
24,836 KB |
testcase_68 | AC | 24 ms
24,836 KB |
testcase_69 | AC | 26 ms
24,836 KB |
testcase_70 | AC | 25 ms
24,836 KB |
testcase_71 | AC | 24 ms
24,836 KB |
testcase_72 | AC | 25 ms
24,836 KB |
testcase_73 | AC | 25 ms
24,812 KB |
testcase_74 | AC | 27 ms
25,196 KB |
testcase_75 | AC | 27 ms
25,196 KB |
testcase_76 | AC | 27 ms
25,196 KB |
testcase_77 | AC | 26 ms
24,800 KB |
testcase_78 | AC | 27 ms
24,428 KB |
testcase_79 | AC | 26 ms
24,544 KB |
testcase_80 | AC | 27 ms
24,812 KB |
testcase_81 | AC | 26 ms
25,196 KB |
testcase_82 | AC | 27 ms
25,196 KB |
testcase_83 | AC | 27 ms
24,812 KB |
testcase_84 | AC | 26 ms
24,812 KB |
testcase_85 | AC | 28 ms
24,812 KB |
testcase_86 | AC | 28 ms
24,800 KB |
testcase_87 | AC | 27 ms
24,428 KB |
testcase_88 | AC | 30 ms
25,196 KB |
testcase_89 | AC | 28 ms
25,196 KB |
testcase_90 | AC | 28 ms
25,196 KB |
testcase_91 | AC | 26 ms
25,196 KB |
testcase_92 | AC | 159 ms
24,812 KB |
testcase_93 | AC | 143 ms
25,196 KB |
testcase_94 | AC | 135 ms
24,556 KB |
testcase_95 | AC | 186 ms
24,544 KB |
testcase_96 | AC | 187 ms
24,812 KB |
testcase_97 | AC | 179 ms
24,416 KB |
testcase_98 | AC | 174 ms
25,196 KB |
testcase_99 | AC | 180 ms
25,196 KB |
testcase_100 | AC | 142 ms
25,196 KB |
testcase_101 | AC | 173 ms
24,812 KB |
evil_1_rnd_1.txt | AC | 369 ms
24,556 KB |
evil_1_rnd_2.txt | AC | 377 ms
25,196 KB |
evil_2_big_1.txt | AC | 472 ms
24,556 KB |
evil_2_big_2.txt | AC | 477 ms
24,812 KB |
evil_2_big_3.txt | AC | 469 ms
24,812 KB |
evil_3_sorted_1.txt | AC | 263 ms
24,568 KB |
evil_4_sorted_rev_1.txt | AC | 200 ms
25,220 KB |
evil_4_sorted_rev_2.txt | AC | 280 ms
25,220 KB |
evil_400_sorted.txt | AC | 445 ms
24,824 KB |
evil_400_sorted_rev.txt | AC | 449 ms
24,836 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> struct BIT { int n; std::vector<T> tree; BIT(int n) : n(n) { tree.assign(n + 1, T(0)); } BIT() {} T _sum(int i) { i++; T res = T(0); while (i > 0) { res += tree[i]; i -= i & -i; } return res; } T sum(int l, int r) { return _sum(r - 1) - _sum(l - 1); } T sum(int r) { return _sum(r - 1); } T get(int i) { return _sum(i) - _sum(i - 1); } void add(int i, T x) { i++; while (i <= n) { tree[i] += x; i += i & -i; } } int lower_bound(T x) { int pos = 0; int plus = 1; while (plus * 2 <= n) plus *= 2; while (plus > 0) { if ((pos + plus <= n) && (tree[pos + plus] < x)) { x -= tree[pos + plus]; pos += plus; } plus >>= 1; } return pos; } }; struct Factoradic : std::vector<int> { using std::vector<int>::vector; void shrink() { while (this->size() >= 2u && !this->back()) { this->pop_back(); } } Factoradic &operator+=(const Factoradic &rhs) { this->resize(std::max(this->size(), rhs.size()) + 1); for (size_t i = 0; i < rhs.size(); ++i) { (*this)[i] += rhs[i]; } for (size_t i = 0; i + 1 < this->size(); ++i) { if ((*this)[i] >= i + 1) { (*this)[i + 1] += (*this)[i] / (i + 1); (*this)[i] -= (i + 1); } } shrink(); return *this; } Factoradic &operator/=(int rhs) { for (int i = int(this->size()) - 1; i >= 0; --i) { if (i) { (*this)[i - 1] += (*this)[i] % rhs * i; } (*this)[i] /= rhs; } shrink(); return *this; } bool operator==(const Factoradic &rhs) const { for (size_t i = 0; i < std::min(this->size(), rhs.size()); ++i) { if ((*this)[i] != rhs[i]) return false; } if (this->size() > rhs.size()) { for (size_t i = rhs.size(); i < this->size(); ++i) { if ((*this)[i] != 0) return false; } } else { for (size_t i = this->size(); i < rhs.size(); ++i) { if (rhs[i] != 0) return false; } } return true; } Factoradic operator+(const Factoradic &rhs) const { Factoradic ret = *this; ret += rhs; return ret; } Factoradic operator/(int rhs) const { Factoradic ret = *this; ret /= rhs; return ret; } std::vector<int> to_permutation(int digit = -1) const { if (digit == -1) digit = int(this->size()); BIT<int> bit(digit); for (int i = 0; i < digit; ++i) { bit.add(i, 1); } std::vector<int> ret; ret.reserve(digit); for (int i = digit - 1; i >= 0; --i) { int x = (i < this->size() ? (*this)[i] : 0); int p = bit.lower_bound(x + 1); ret.push_back(p); bit.add(p, -1); } return ret; } }; void solve() { int n; cin >> n; Factoradic L(n + 1); Factoradic R(n + 1); R[n] = 1; while (1) { auto mid = (L + R) / 2; if (mid == L) break; auto P = mid.to_permutation(n); cout << "? "; for (size_t i = 0; i < P.size(); ++i) { cout << P[i] + 1; if (i != P.size() - 1) cout << " "; } cout << endl; int res; cin >> res; if (res == 0) { R = mid; } else { L = mid; } } auto P = L.to_permutation(n); cout << "! "; for (size_t i = 0; i < P.size(); ++i) { cout << P[i] + 1; if (i != P.size() - 1) cout << " "; } cout << endl; } int main() { // cin.tie(0)->sync_with_stdio(0); // cout << fixed << setprecision(12); int t; t = 1; // cin >> t; while (t--) solve(); return 0; }