# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985290 | 2024-05-17T14:35:04 Z | roctes7 | Type Printer (IOI08_printer) | C++17 | 1000 ms | 66292 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const double eps = 1e-6; const int MAX = 5e5+3; int adj[MAX][30]; int num[MAX]; int mx_level[MAX]; bool has[MAX]; int nex = 1; void init(){ memset(adj,-1,sizeof adj); } void add(string s){ int i = 0, v = 0; while(i < s.size()){ if(adj[v][s[i]-'a'] == -1) v = adj[v][s[i++]-'a'] = nex++; else v = adj[v][s[i++]-'a']; } has[v] = true; num[v]++; } void dfs(int u,int d){ if(has[u])mx_level[u] = d; for(char c='a';c<='z';c++)if(adj[u][c-'a']!=-1){ dfs(adj[u][c-'a'],d+1); mx_level[u] = max(mx_level[u],mx_level[adj[u][c-'a']]); } } vector<char> ans; void dfs_ans(int u){ if(has[u])ans.push_back('P'); int mx = -1; int ind = -1; char indChar = '0'; for(char c='a';c<='z';c++)if(adj[u][c-'a']!=-1)if(mx_level[adj[u][c-'a']]>0){ if(mx_level[adj[u][c-'a']]>mx){ if(ind!=-1){ ans.push_back(indChar); dfs_ans(ind); } mx = mx_level[adj[u][c-'a']]; ind = adj[u][c-'a']; indChar = c; }else { ans.push_back(c); dfs_ans(adj[u][c-'a']); } } if(ind!=-1){ ans.push_back(indChar); dfs_ans(ind); } ans.push_back('-'); } int main(){ fastio; //freopen("output.txt","w",stdout); init(); int n; cin>>n; for(int i=0;i<n;i++){ string s; cin>>s; add(s); } dfs(0,0); dfs_ans(0); while(ans.back()=='-')ans.pop_back(); cout<<ans.size()<<endl; for(auto a:ans)cout<<a<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 63320 KB | Output is correct |
2 | Correct | 9 ms | 63324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 63324 KB | Output is correct |
2 | Correct | 8 ms | 63324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 63324 KB | Output is correct |
2 | Correct | 8 ms | 63324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 63324 KB | Output is correct |
2 | Correct | 9 ms | 63324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 63264 KB | Output is correct |
2 | Correct | 17 ms | 63320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 63320 KB | Output is correct |
2 | Correct | 28 ms | 63320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 67 ms | 63556 KB | Output is correct |
2 | Correct | 136 ms | 63832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 185 ms | 64148 KB | Output is correct |
2 | Correct | 51 ms | 63324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 410 ms | 64804 KB | Output is correct |
2 | Correct | 867 ms | 65812 KB | Output is correct |
3 | Correct | 457 ms | 64720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 325 ms | 64424 KB | Output is correct |
2 | Execution timed out | 1018 ms | 66292 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |