Submission #321630

#TimeUsernameProblemLanguageResultExecution timeMemory
321630iliccmarkoType Printer (IOI08_printer)C++14
10 / 100
49 ms18156 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, int raz, int ind) { if(kraj[node]) { cnt++; cout<<"P"<<endl; } for(int i = 0;i<26;i++) { if(trie[node][i]&&(i!=p||raz)) { cout<<char(i+'a')<<endl; int r = raz; if(!r) if(i!=p) r = 1; if(ind<len(ss)-1) p = ss[ind+1] - 'a'; else p = 30; print(trie[node][i], p, r, ind+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', 0, 0); for(int i = 0;i<le;i++) { cout<<ss[i]<<endl; print(kk[i], ss[i+1]-'a', 0, i); } 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...