Submission #520158

#TimeUsernameProblemLanguageResultExecution timeMemory
520158AkiYuuType Printer (IOI08_printer)C++17
0 / 100
24 ms19256 KiB
/* Problems: Author: AkiYuu */ #include <bits/stdc++.h> #define task "GROUP" #define ll long long #define ld long double #define pb(u) emplace_back(u) #define ffw(i,a,b) for (ll i = a; i <= b; i++) #define fbw(i,b,a) for (ll i = b; i >= a; i--) #define adj(v,adj,u) for (auto v : adj[u]) #define rep(i,a) for (auto i : a) #define reset(a) memset(a, 0, sizeof(a)) #define sz(a) a.size() #define all(a) a.begin(),a.end() using namespace std; void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(task".inp", "r", stdin); // freopen(task".out", "w", stdout); } const int mxn = 1e6 + 5; typedef pair<ll, ll> ii; int n; int trie[25000 * 20 + 5][26], dem; bool isend[25000 * 20 * 26]; ii longest[25000 * 20 * 26]; void add(string s){ int node = 0; for (char c : s ){ int x = c - 'a'; if ( trie[node][x] == 0 ) trie[node][x] = ++dem; node = trie[node][x]; } isend[node ] = true; } int calc(int u){ longest[u] = ii(1,0); ffw(i,0,25){ if ( trie[u][i] == 0 ) continue; int v = trie[u][i]; longest[u] = max( longest[u] , ii(calc(v) + 1, v) ); } return longest[u].first; } vector < char > path; void dfs(int u){ if ( isend[u] ) { path.pb('P'); return; } char LG; ffw(i,0,25){ if ( trie[u][i] == 0) continue; int v = trie[u][i]; if ( v == longest[u].second) { LG = (char) ('a' + i); continue; } path.pb( (char) ('a' + i) ); dfs(v); path.pb( '-' ); } path.pb(LG); dfs(longest[u].second); path.pb('-'); } void solve(){ cin >> n; ffw(i,1,n){ string s; cin >> s; add(s); } calc(0); dfs(0); while (sz(path) && path.back() == '-' ) path.pop_back(); for (char c : path ) cout << c << '\n'; } int main(){ fastio(); int t = 1; // cin >> t; while (t--) solve(); }
#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...