I figured it out - for at least one case, the first word in the first language is of length 0 - an emtpy line. scanf reads all whitespace when it encounters a space, tab, or newline in the format string, so we were skipping that new line.
Someone who got AC, how fast does your program run on the input produced by this program?
My program (currently the fastest on the ranklist) takes 6.5 sec on my Pentium-II 400.
My program is currently the second on the ranklist And it runs < 0.1 sec. on this test.
My program's complexity is about O(n*m*10). It's intresting to know is it possible to solve it faster?
Pupirev Sergei wrote:My program is currently the second on the ranklist And it runs < 0.1 sec. on this test.
My program's complexity is about O(n*m*10). It's intresting to know is it possible to solve it faster?
Oh, yes, it is!
My new program uses sorting and binary search. Its complexity quite depends on the input. It is O(N) for inputs, like the one generated by jdmetz's program.
Hint: think, of what form can all duplicate concatenations be. (think about prefixes, suffixes, etc.)
CodeMaker wrote:have u solved it using prefix-suffix?
Yes, that's the approach I used in the program, which currently (again) holds the first place in the ranklist.
It has O(N) complexity only in some very special cases -- when the first language is given sorted and no string is a prefix of another one.
In the worst case, my program is O(N^2 M log M), but this complexity can occur only when the length of the longest word is near N.
During the contest I solved the problem by hashing.
Pupirev Sergei wrote:
My program is currently the second on the ranklist And it runs < 0.1 sec. on this test.
My program's complexity is about O(n*m*10). It's intresting to know is it possible to solve it faster?
Does you use trie tree to solve the problem?
It looks the complexity is O(n*m*length)
I use trie tree to solve the problem, but get TLE
I don't know what's wrong with my thought.
Thx in advance.
9
3 3
a
b
a
b
2 2
a
aa
a
aa
3 3
a
ab
abc
bcd
cd
d
5 7
a
ab
abc
abcd
abcde
bcde
cde
de
e
defg
dxyz
5 5
a
aa
aab
abc
ad
a
ab
b
bc
cd
0 0
1 1
a
b
0 1
a
1 0
b
hi everybody ,
i am getting wa in this problem ... i guess i am having trouble parsing the input .....this is how i parse my input .....could anyone tell me if there is anything wrong .if there is no problem in parsing input i may forced to paste my code here ..................
i forgot to mention one thing in my previous post ........my code passes all the test cases available in this topic given by people who have got ac in this problem.............
happy coding
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
thanx for the reply Emilio ...i am releived to know i am not making any mistake while taking input . can some one give me some more i/o ....or i can paste my code here ...............pliz help...
thanx in advance
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN