Submission #321631

#TimeUsernameProblemLanguageResultExecution timeMemory
321631iliccmarkoType Printer (IOI08_printer)C++14
100 / 100
123 ms49004 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define INF 1000000000 #define LINF 1000000000000000LL #define pb push_back #define all(x) x.begin(), x.end() #define len(s) (int)s.size() #define test_case { int t; cin>>t; while(t--)solve(); } #define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];} #define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;} #define single_case solve(); #define line cout<<"------------"<<endl; #define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); } using namespace std; const int N = 5e5 + 5; int trie[N][26]; int kraj[N]; int ind; int n; int cnt = 0; vector<string> v; int m; string ss; int c; vector<int> kk; void _insert(string s) { int node = 0; for(int i = 0;i<len(s);i++) { int c = s[i] - 'a'; if(!trie[node][c]) trie[node][c] = ++ind; node = trie[node][c]; } kraj[node] = 1; } int u; void search(string s) { int node = 0; for(int i = 0;i<len(s);i++) { int c = s[i] - 'a'; kk.pb(trie[node][c]); node = trie[node][c]; } } void print(int node, int p) { if(kraj[node]) { cnt++; cout<<"P"<<endl; } for(int i = 0;i<26;i++) { if(i==p) continue; if(trie[node][i]) { cout<<char(i+'a')<<endl; print(trie[node][i], -1); cout<<"-"<<endl; } } } int main() { ios cin>>n; for(int i = 0;i<n;i++) { string s; cin>>s; _insert(s); if(len(s)>len(ss)) ss = s; } int le = len(ss); ss.pb('#'); cout<<2*ind - le + n<<endl; search(ss); print(0, ss[0]-'a'); for(int i = 0;i<le;i++) { cout<<ss[i]<<endl; if(i==le-1) { cout<<"P"<<endl; break; } print(kk[i], ss[i+1]-'a'); } 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...