- #include <bits/stdc++.h>
- using namespace std;
- #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define ll long long
- #define fr(i,n) for(ll i=0;i<n;i++)
- struct node
- {
- ll cnt;
- struct node* child[26];
- node()
- {
- cnt=0;
- fr(i,26)child[i]=NULL;
- }
- };
- struct trie
- {
- node* root;
- trie()
- {
- root =new node();
- }
- };
- trie *rt;
- ll ans;
- string s;
- void insert(ll i)
- {
- node* cur=rt->root;
- while(i<s.size())
- {
- if(cur->child[s[i]-'a']==NULL){cur->child[s[i]-'a']=new node();ans++;}
- cur=cur->child[s[i]-'a'];
- i++;
- }
- }
- void solve()
- {
- ans=1;
- cin>>s;
- rt=new trie();
- fr(i,s.size())
- {
- insert(i);
- }
- //including empty substring
- cout<<ans<<en;
- }
- int main()
- {
- fast
- // ll t;cin>>t;while(t--)
- solve();
- return 0;
- }
[text] Number of distinct substrings
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: