제출 #1302565

#제출 시각아이디문제언어결과실행 시간메모리
1302565binhbg0201Type Printer (IOI08_printer)C++20
0 / 100
44 ms36128 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" #define TASK "" #define II pair<int,int> #define fi first #define se second #define MASK(i) (1 << (i)) #define BIT(i,x) (((x) >> (i)) & 1) int MOD = 1e9 + 7; int const N = 1e6 + 7; struct node{ node * child[26]; int exits; int d; node(){ for(int i = 0;i < 26;i++) child[i] = NULL; exits = 0; d = 0; } }; node *root = new node(); struct Trie{ void insert(string s){ node *p = root; for(auto f : s){ int c = f - 'a'; if(p -> child[c] == NULL) p -> child[c] = new node(); p = p -> child[c]; } p -> exits = 1; } }T; vector<char> res; void dfs(node *p){ p -> d = 1; for(int i = 0;i < 26;i++){ node *v = p -> child[i]; if(v != NULL){ dfs(p->child[i]); p -> d = max(p -> d,v -> d + 1); } } } void dfs2(node *p){ if(p -> exits) res.push_back('P'); for(int i = 0;i < 26;i++){ node *v = p -> child[i]; if(v != NULL && p -> d > v -> d + 1){ res.push_back(char(i + 'a')); dfs2(v); } } for(int i = 1;i < 26;i++){ node *v = p -> child[i]; if(v != NULL && p -> d == v -> d + 1){ res.push_back(char(i + 'a')); dfs2(v); } } res.push_back('-'); } void solve(){ int n;cin>>n; for(int i = 1;i <= n;i++){ string s;cin>>s; T.insert(s); } dfs(root); dfs2(root); int p = res.size() - 1; while(res[p] != 'P'){ res.pop_back(); p--; } cout<<res.size()<<endl; for(int i = 0;i < res.size();i++){ cout<<res[i]<<endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); // freopen(TASK".INP","r",stdin); // freopen(TASK".OUT","w",stdout); solve(); return 0; } //be
#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...