Untitled
user_0483151
plain_text
5 months ago
905 B
4
Indexable
// y.ha #include <bits/stdc++.h> #define cook '\n' #define maxn #define Task "bai1" using namespace std; struct { bool isend = 0 ; int C[26],dem,f ; } Nood[(int) 1e6+1]; int cnt = 0,n,m ; void Add(string s) { int u = 0,pre = 0 ; for ( char c : s ) { int x = c-'A' ; if ( !Nood[u].C[x] ) Nood[u].C[x] = cnt++ ; u = Nood[u].C[x] ; Nood[u].dem++ ; Nood[u].f = Nood[pre].f+1 ; pre = u ; } Nood[u].isend = 1; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(nullptr) ; if(fopen(Task".INP","r")) { freopen(Task".INP","r",stdin); freopen(Task".OUT","w",stdout); } cin >> n ; Nood[0].f = 0; while ( n-- ) { string s; cin >> s; Add(s) ; } for ( int i = 1; i <= cnt; i++ ) cout << Nood[i].f << cook ; }
Editor is loading...
Leave a Comment