結果
問題 | No.2893 Minahoshi (Hard) |
ユーザー | 👑 seekworser |
提出日時 | 2024-09-07 00:19:28 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,047 bytes |
コンパイル時間 | 3,390 ms |
コンパイル使用メモリ | 265,476 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 20:52:41 |
合計ジャッジ時間 | 11,351 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const vector<int> ns = {1, 2, 5, 10, 19, 36, 69, 134, 263, 520, 1033, 2058, 4107, 8204, 16397, 32782, 65551, 131088, 262161}; const vector<vector<int>> primitive_polynomials = { {}, {1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}, {5, 6}, {6, 7}, {4, 5, 6, 8}, {5, 9}, {7, 10}, {9, 11}, {4, 10, 11, 12}, {8, 11, 12, 13}, {2, 12, 13, 14}, {14, 15}, {11, 13, 14, 16}, {14, 17}, {11, 18}, }; vector<pair<int, int>> lfsr(ll d) { vector<int> p = primitive_polynomials[d]; ll x = (1 << d) - 1; vector<int> r; while (r.size() == 0 || r[0] != x) { r.push_back(x); x <<= 1; for (auto k : p) if ((x >> k) & 1) x ^= 1; if ((x >> d) & 1) x ^= (1 << d); } r.insert(find(r.begin(), r.end(), (1 << (d-1))) + 1, 0); vector<pair<int, int>> result(1 << d); for (size_t i=0; i < (1 << d); ++i) { result[r[i]] = {0, r[(i+1) % (r.size())]}; } return result; } int main() { int n; cin >> n; if (n == 1) {cout << "a" << endl; return 0;} int d = (upper_bound(ns.begin(), ns.end(), n) - ns.begin()) - 1; vector<vector<pair<int, int>>> c(2); c[0] = lfsr(d); c[1] = vector<pair<int, int>>(1 << d, {-1, -1}); int l = ns[d]; int s = 0; unordered_set<int> r; for (int x=0; x < (1 << d); ++x) r.insert(x); while (l < n) { int x = *r.begin(); while (c[1][x].first == -1) { r.erase(x); l += 1; c[1][x] = {1, c[0][x].second ^ 1}; x = c[1][x].second; } s = c[0][x].second; swap(c[0][x], c[1][x]); } pair<int, int> pos = {0, s}; string ans; for (int i=d-1; i >= 0; i--) ans += ((pos.second >> i) & 1) ? 'a' : 'b'; cout << "ans: " << ans << endl; while (ans.size() < n) { auto [t, x] = pos; auto [tn, xn] = c[t][x]; ans += (xn & 1) ? 'a' : 'b'; pos = {tn, xn}; } cout << ans << endl; }