Submission #745592

#TimeUsernameProblemLanguageResultExecution timeMemory
745592Perl32Type Printer (IOI08_printer)C++14
20 / 100
104 ms33884 KiB
/** * author: Perl32 * created: 19.05.2023 17:00:04 **/ #ifdef LOCAL # define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define ff first #define ss second #define szof(x) (int) x.size() #define all(x) x.begin(), x.end() #ifndef LOCAL # define cerr __get_ce #endif using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef complex<double> cmpl; typedef unsigned long long ull; using namespace __gnu_pbds; template<typename K, typename V> using normal_unordered_map = gp_hash_table<K, V>; template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<T>>; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; const int INF = (int) 1e9 + 1e3; const ll INFL = (ll) 1e18 + 1e6; #ifdef LOCAL mt19937 tw(9450189); #else mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif uniform_int_distribution<ll> ll_distr; ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; } struct Trie { struct Node { unordered_map<char, int> next; bool terminal = false; }; vector<Node> tree; Trie() { tree.emplace_back(); } bool contain(int v, char ch) { return tree[v].next.find(ch) != tree[v].next.end(); } int add(int v, char ch, bool terminal) { if (!contain(v, ch)) { tree[v].next[ch] = szof(tree); tree.emplace_back(); } int to = tree[v].next[ch]; tree[to].terminal |= terminal; return to; } int go(int v, char ch) { if (!contain(v, ch)) { return -1; } return tree[v].next[ch]; } void get() { vector<char> ans; function<void(int)> dfs = [&](int u) { if (tree[u].terminal) { ans.push_back('P'); } for (auto [ch, to] : tree[u].next) { ans.push_back(ch); dfs(to); ans.push_back('-'); } }; dfs(0); while (ans.back() == '-') { ans.pop_back(); } cout << szof(ans) << '\n'; for (auto x : ans) { cout << x << '\n'; } } }; signed main() { #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); auto start_time = clock(); cerr << setprecision(3) << fixed; #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; Trie tree; for (int i = 0; i < n; ++i) { string s; cin >> s; int v = 0; for (int j = 0; j < szof(s); ++j) { v = tree.add(v, s[j], j == szof(s) - 1); } } tree.get(); #ifdef LOCAL auto end_time = clock(); cerr << "Execution time: " << (end_time - start_time) * (ll) 1e3 / CLOCKS_PER_SEC << " ms\n"; #endif }

Compilation message (stderr)

printer.cpp: In lambda function:
printer.cpp:83:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |             for (auto [ch, to] : tree[u].next) {
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...