結果
問題 | No.2893 Minahoshi (Hard) |
ユーザー | noimi |
提出日時 | 2024-09-13 22:50:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,604 bytes |
コンパイル時間 | 2,919 ms |
コンパイル使用メモリ | 230,168 KB |
実行使用メモリ | 31,248 KB |
最終ジャッジ日時 | 2024-09-13 22:50:37 |
合計ジャッジ時間 | 13,002 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 32 ms
16,996 KB |
testcase_04 | AC | 29 ms
16,348 KB |
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; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define ov4(a, b, c, d, name, ...) name #define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaa, n) #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for(ll i = (a) - 1; i >= (b); i--) #define fore(e, v) for(auto &&e : v) #define all(a) begin(a), end(a) #define si(a) (int)(size(a)) #define lb(v, x) (lower_bound(all(v), x) - begin(v)) #define eb emplace_back template <typename T, typename S> bool chmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> bool chmax(T &a, const S &b) { return a < b ? a = b, 1 : 0; } const int INF = 1e9 + 100; const ll INFL = 3e18 + 100; #define i128 __int128_t struct _ { _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); } } __; vi lcp(string s) { vector<string> res; rep(i, si(s)) res.eb(s.substr(i)); sort(all(res)); vi ans; rep(i, si(res) - 1) { bool found = false; rep(j, 1, min(si(res[i]), si(res[i + 1])) + 1) { if(res[i].substr(0, j) != res[i + 1].substr(0, j)) { ans.eb(j - 1); found = true; break; } } if(!found) ans.eb(min(si(res[i]), si(res[i + 1]))); } return ans; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { os << "["; fore(e, v) os << e << ", "; return os << "]"; } template <typename T, typename S> ostream &operator<<(ostream &os, pair<T, S> p) { return os << "(" << p.first << ", " << p.second << ")"; } struct edge { int x, y, idx; }; vector<edge> eulerian_path(vector<edge> es, int s, bool directed = false) { if(es.empty()) return {}; int n = 0; fore(e, es) chmax(n, max(e.x, e.y) + 1); vector<vector<pair<edge, int>>> g(n); for(auto &e : es) { int p = si(g[e.y]); g[e.x].emplace_back(e, p); if(!directed) { int q = si(g[e.x]) - 1; swap(e.x, e.y); g[e.x].emplace_back(e, q); } } vector<edge> ord; stack<pair<int, edge>> st; st.emplace(s, edge{-1, -1, -1}); while(st.size()) { int x = st.top().first; if(empty(g[x])) { ord.eb(st.top().second); st.pop(); } else { auto e = g[x].back(); g[x].pop_back(); if(e.second == -1) continue; if(!directed) g[e.first.y][e.second].second = -1; st.emplace(e.first.y, e.first); } } ord.pop_back(); reverse(begin(ord), end(ord)); if(si(ord) != si(es)) return {}; return ord; } int main() { int t; cin >> t; rep(t) { int n; cin >> n; if(n == 2) { cout << "ab" << endl; continue; } int m = 1; while((1 << m) + (m - 1) < n) m++; vector<edge> E; rep(b, 1 << (m - 1)) { rep(j, 2) { int nb = ((b << 1) | j) & ~(1 << m - 1); E.push_back(edge{(int)b, nb, (int)j}); } } assert(si(E) == (1 << m)); auto res = eulerian_path(E, 0, true); string s(m, 'a'); int i = 0; while(si(s) < n) { s += 'a' + (res[i].idx); i++; } reverse(all(s)); cout << s << endl; // cout << lcp(s) << endl; } }