Sphere Online Judge

SPOJ Problem Set (classical)

694. Distinct Substrings

Problem code: DISUBSTR

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:1s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6
Resource: ByteCode '06

hide comments
2013-05-08 07:37:13 XxX_Stu
Also can use Suffix Automaton to accepted.
String just have chars which 'A'-'Z'.
2013-03-23 09:27:04 Jarily
newbie go past
2013-03-03 11:58:04 shen
orz CaiG
2013-02-03 15:16:46 fjh
When I add 'memset',my programme accepted.And when I don't add it,my programme wrong answer.Why?
2013-01-16 07:41:56 Owen
Độc cô cầu bại :How you dynamic programming?
2012-11-23 19:20:06 Sanjary Rahman
Doubly Algo of suffix array took 0.01s for me :)
2012-10-03 11:40:32 Galileo Figaro magnifico
Can the string contain characters other than A-Za-z ?
2012-08-30 15:59:09 Arun Lakshman
http://www.spoj.pl/problems/SUBST1/
2012-08-15 23:57:46 Dunno
welll, O(N^2) works since constraint is pretty small.
2012-05-26 11:42:39 陈迪
suffix arr && height arr
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.