Submission #531829

#TimeUsernameProblemLanguageResultExecution timeMemory
531829AlanType Printer (IOI08_printer)C++17
20 / 100
40 ms18488 KiB
#include <bits/stdc++.h> #define I using #define WA using namespace std; #define on using ll = long long; #define Test(x) int AlanIQ = -(x); #define should ld = #define quit long double; #define OI int #define forever main #define Alan cin.tie(0); #define fai(x) ios::ios_base::sync_with_stdio(!x); #define Sharky return #define orz 0; WA on Test (109) struct node { int child[26]; bool word; }; node trie[500005]; bool last[500005], vis[500005]; vector<char> ans; int lastd = 0; void dfs (int u) { vis[u] = true; if (trie[u].word) ans.push_back('P'); char c; int okkkookokokokoknotok = -1; for (int i = 0; i < 26; i++) { int v = trie[u].child[i]; if (vis[v] || !v) continue; if (last[v]) { c = i + 'a'; okkkookokokokoknotok = v; continue; } ans.push_back(i + 'a'); dfs(v); ans.push_back('-'); } if (okkkookokokokoknotok != -1) { ans.push_back(c); dfs(okkkookokokokoknotok); ans.push_back('-'); } } I should quit OI forever () { Alan fai (true) int n, id = 0; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; int cur = 0; int sz = (int) s.size(); bool ishouldquitoi = false; if (sz > lastd) { lastd = sz; ishouldquitoi = true; } for (int j = 0; j < sz; j++) { if (!trie[cur].child[s[j] - 'a']) trie[cur].child[s[j] - 'a'] = ++id; cur = trie[cur].child[s[j] - 'a']; if (ishouldquitoi) last[cur] = true; } trie[cur].word = true; } dfs(0); for (int i = (int) ans.size() - 1; i >= 0; i--) { if (ans[i] == '-') ans.pop_back(); else break; } cout << ans.size() << "\n"; for (auto& c : ans) cout << c << "\n"; Sharky orz }
#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...