# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117284 | 2024-11-23T08:16:27 Z | Newtonabc | Type Printer (IOI08_printer) | C++14 | 266 ms | 262144 KB |
#include<bits/stdc++.h> using namespace std; const int N=5e5+10; int trie[N][30]; bool word[N]; int cnt,sz[N],path[N]; stack<int> st; vector<int> adj[N]; char type[N]; vector<char> pt; void insert(string s){ int u=0; for(int i=0;i<s.size();i++){ if(trie[u][s[i]-'a']==0){ trie[u][s[i]-'a']=++cnt; type[cnt]=s[i]; adj[cnt].push_back(u); adj[u].push_back(cnt); } u=trie[u][s[i]-'a']; } word[u]=true; } void findsz(int u,int p){ sz[u]=0; for(int i=0;i<adj[u].size();i++){ int v=adj[u][i]; if(v==p) continue; findsz(v,u); if(sz[v]+1>sz[u]){ sz[u]=sz[v]+1; path[u]=v; } } } void dfs(int u,int p){ while(!st.empty() && st.top()!=p) pt.push_back('-'),st.pop(); if(u) st.push(u); if(u) pt.push_back(type[u]); if(word[u] && u) pt.push_back('P'); for(int i=0;i<adj[u].size();i++){ int v=adj[u][i]; if(v==p || v==path[u]) continue; dfs(v,u); } dfs(path[u],u); } int main(){ int n; cin>>n; for(int i=0;i<n;i++){ string inp; cin>>inp; insert(inp); } dfs(0,0); cout<<pt.size() <<"\n"; for(int i=0;i<pt.size();i++){ cout<<pt[i] <<"\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 224 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 238 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 240 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 234 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 233 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 246 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 245 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 248 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 260 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 266 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |