Submission #963194

#TimeUsernameProblemLanguageResultExecution timeMemory
963194fzyzzz_zType Printer (IOI08_printer)C++17
50 / 100
399 ms62024 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; map<string, int> id; int s = 1; vector<int> adj[20 * 25000]; int bad[20 * 25000]; char ch[20 * 25000]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<string> a(n); string mx = ""; for (auto & x: a) { cin >> x; if (x.size() > mx.size()) mx = x; } for (int i = 0; i < 20 * 25000; ++i) bad[i] = 0; for (auto x: a) { int at = 0; string cur = ""; for (auto c: x) { cur += c; if (id.find(cur) == id.end()) { adj[at].push_back(s); id[cur] = s++; } at = id[cur]; ch[at] = c; if (x == mx) bad[at] = 1; } bad[at] |= 2; } string ans = ""; function<void(int)> dfs = [&] (int x) -> void { if (x > 0) ans += ch[x]; if (bad[x] & 2) ans += 'P'; for (auto u: adj[x]) { if (!(bad[u] & 1)) { dfs(u); } } for (auto u: adj[x]) { if ((bad[u] & 1)) { dfs(u); } } ans += '-'; }; dfs(0); while (ans.back() == '-') ans.pop_back(); cout << ans.size() << '\n'; for (auto x: ans) { cout << x << '\n'; } return 0; }
#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...