DISUBSTR - Distinct Substrings

Given a string, we need to find the total number of its distinct substrings.

Input

T- number of test cases. T<=20;
Each test case consists of one string, whose length is <= 1000

Output

For each test case output one number saying the number of distinct substrings.

Example

Sample Input:
2
CCCCC
ABABA

Sample Output:
5
9

Explanation for the testcase with string ABABA:
len=1 : A,B
len=2 : AB,BA
len=3 : ABA,BAB
len=4 : ABAB,BABA
len=5 : ABABA
Thus, total number of distinct substrings is 9.


Added by:Prasanna
Date:2006-01-13
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource: ByteCode '06

hide comments
2015-07-29 22:47:22
Will AA and aa be considered different strings?
2015-07-25 13:33:25 Raghav Aggiwal Again
Suffix Array !
2015-07-17 09:49:34 xxbloodysantaxx
@n3gativ3 - My Z array solution takes 0.02 seconds to run!!
2015-06-30 20:26:53 Rydel Dcosta
my code got AC for this but WA for SUBST1 :/ can somebody help me ??whats wrong in my code
<snip>


Last edit: 2023-05-16 22:18:55
2015-06-18 09:49:37 n3gativ3
Z array-0.10 sec
KMP failure function-0.1 sec
Suffix Array-0,00 sec :)
2015-06-13 18:57:39 Rishab Banerjee
those are using O(n*log(n)*log(n))
try http://www.spoj.com/problems/SUBST1/
i got AC here but getting TLE in SUBST1
2015-06-13 09:34:46 Sherlock
can anybody help me out ?? getting runtime error??
2015-06-10 14:24:54 arp_ee
first prob on suffix array !!
2015-05-22 18:04:00 Shubham Bansal
phew..!! learnt alot from dis!!
2015-05-07 09:21:08 i_am_looser
Can this question be solved using Trie ?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.