Submission #531831

#TimeUsernameProblemLanguageResultExecution timeMemory
531831AlanType Printer (IOI08_printer)C++17
100 / 100
95 ms52204 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; string lasts; 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; cin >> n; string a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; int sz = a[i].size(); if (sz > lastd) { lastd = sz; lasts = a[i]; } } for (int i = 0; i < n; i++) { int cur = 0; bool ishouldquitoi = lasts == a[i]; for (int j = 0; j < (int) a[i].size(); j++) { if (!trie[cur].child[a[i][j] - 'a']) trie[cur].child[a[i][j] - 'a'] = ++id; cur = trie[cur].child[a[i][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...