oops there was a silly mistake, got AC learnt a lot from this question
hello,
could you just tell me weather my codeās output is correct or not, irrespective of time exceed errorā¦
why doesnt work?
module Main where
import Data.List
import System.Exit
al1 xs = nub . concat . map (drop 1 . inits) . tails $ xs
cmp xs xz = [ x | x <- ((al1 xs)++(al1 xz)), notElem x (intersect (al1 xs) (al1 xz) )]
main = do
line <- getLine
line2 <- getLine
putStr $ show $ length $ cmp line line2
exitWith ExitSuccess
works fine here runs but (time exceed)
import List
Import System
Might be that we need to find U(A) + U(B) - 2*U(A intersection B) because common substrings appear twice.
This is my code in python. it works fine on my system but dont know why it is not working in codechef
Probably you misunderstand the idea of contest programming - your code have to return correct answer for each available input, not only the one in problem statement and your program return 8 for each input, simply because you are NOT reading input from stdinā¦
If U(a) is taken to represent the set of all unique substrings of a, and |U(a)| its size, then the final expression should be: 2*|U(a) UNION U(b)| - |U(a)| - |U(b)|
getting run time error NZEC. first submission in codechef. so dont know much abt online compilers. plz help me out sir http://www.codechef.com/viewsolution/5666193
First try to comment System.exit(0);
- killing JVM is not a good idea in generalā¦
Iād say, that problem is with memory, you want to allocate array of strings of length n^2 (and n is 100000).
array of strings with no of strings is n2, where n2 being 10 for a four letter word
10=4+3+2+1
so n2=no of letters +(no of letters-1)+ā¦+ 1
and sir system.exit(0) presence or absence has no effect in this case in the runtime errorā¦
any other suggestions sir ?
thanks
Wowā¦ that was a quite a sleek approachā¦ Nice one