Submission #1099875

#TimeUsernameProblemLanguageResultExecution timeMemory
1099875horezusholType Printer (IOI08_printer)C++17
100 / 100
222 ms96640 KiB
#include<bits/stdc++.h> #define F first #define S second #define SZ(x) int((x).size()) const char nl = '\n'; using ll = long long; using namespace std; const int N = 25000 * 21; int nam = 0; int n; int trie[N][27]; int dep[N][27]; bool stop[N]; void add(string s) { int x = 0; for (auto c : s) { if (!trie[x][c-'a']) { trie[x][c-'a'] = ++nam; } dep[x][c-'a'] = max(dep[x][c-'a'], SZ(s)); x = trie[x][c-'a']; } stop[x] = true; } vector<char> res; int fine = 0; void dfs(int x) { if (stop[x]) { res.push_back('P'); fine ++; } vector<int> topo(26, 0); iota(topo.begin(), topo.end(), 0); sort(topo.begin(), topo.end(), [&](int a, int b) { return dep[x][a] < dep[x][b]; }); for (auto c : topo) { if (!trie[x][c]) { continue; } res.push_back(c + 'a'); dfs(trie[x][c]); } if (fine != n) { res.push_back('-'); } } void verkefni() { cin >> n; for (int i = 0; i < n; i ++) { string s; cin >> s; add(s); } dfs(0); cout << SZ(res) << nl; for (auto el : res) { cout << el << nl; } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tst = 1; // cin >> tst; while (tst --) { verkefni(); } }
#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...