# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737942 | 2023-05-08T02:48:38 Z | guagua0407 | Type Printer (IOI08_printer) | C++17 | 46 ms | 52632 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=2.5e4*20+5; int trie[mxn][26]; char c[mxn]; int cur=1; vector<char> ans; string mx=""; void dfs(int v,int d=0,bool tf=true){ if(v!=0) ans.push_back(c[v]); int cnt=0; for(int i=0;i<26;i++){ if(trie[v][i]!=-1){ cnt++; if(tf and d<mx.length() and (mx[d]-'a')==i) continue; dfs(trie[v][i],d+1,false); } } if(tf and d<mx.length()){ dfs(trie[v][mx[d]-'a'],d+1,true); } if(cnt==0) ans.push_back('P'); if(v!=0) ans.push_back('-'); } void insert(string str){ int v=0,i=0; while(i<str.length()){ if(trie[v][str[i]-'a']==-1){ trie[v][str[i]-'a']=cur; v=cur; c[cur]=str[i]; cur++; } else{ v=trie[v][str[i]-'a']; } i++; } } int main() {_ for(int i=0;i<mxn;i++){ for(int j=0;j<26;j++){ trie[i][j]=-1; } } int n; cin>>n; for(int i=0;i<n;i++){ string str; cin>>str; insert(str); if(str.length()>mx.length()){ mx=str; } } dfs(0); while(ans.back()=='-') ans.pop_back(); cout<<(int)ans.size()<<'\n'; for(auto v:ans){ cout<<v<<'\n'; } return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 51160 KB | Output is correct |
2 | Correct | 19 ms | 51196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 51204 KB | Output is correct |
2 | Correct | 20 ms | 51156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 51176 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 51276 KB | Output is correct |
2 | Incorrect | 23 ms | 51148 KB | didn't print every word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 51156 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 51284 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 51472 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 31 ms | 51780 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 46 ms | 52632 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 42 ms | 52352 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |