Hello all , i am trying to solve this problem
https://www.spoj.pl/problems/SETNJA/
but getting WA. Could some one please tell me what is wrong with
algorithm.
import qualified Data.ByteString.Char8 as BS
import Data.List as L
solve :: BS.ByteString -> Integer
solve xs = solverHelp xs 1 where
solverHelp ys p
| BS.null ys == True = p
| otherwise = case BS.head ys of
'L' -> solverHelp ( BS.tail ys ) 2*p
'R' -> solverHelp ( BS.tail ys ) ( 2*p + 1 )
'P' -> solverHelp ( BS.tail ys ) p
'*' -> solverHelp ( BS.tail ys ) p + solverHelp ( BS.tail ys
)
( 2*p ) + solverHelp ( BS.tail ys ) ( 2*p + 1 )
main = BS.interact $ BS.unlines . map ( BS.pack . show . solve ) .
BS.lines
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.