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
2012-03-11 08:57:07 谢天成
Suffix array too
2011-08-18 05:00:12 mahmoud
substrings must be consecutive or not ?
2011-08-06 17:51:27 Ðộc cô cầu bại
trie or dynamic programming can accept. I used dynamic programming to accept this problem.

Last edit: 2011-08-06 17:55:52
2011-07-21 12:18:33 sandeep aggrawal
does the string only contain characters???
2010-07-20 01:20:55 Zheli Zhou
suffix array
2010-05-09 02:00:49 fake
Is it ues KMP?
2010-04-04 15:57:04 Iqram Mahmud
Precisely, it is within 32 and 126 in ascii values.
2009-06-12 08:02:53 Rajesh V
Any ASCII characters other than whitespaces.
2009-06-07 17:09:56 Dima Kravtsov
What characters does the string contain?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.