Submission #5754268


Source Code Expand

Copy
{-# LANGUAGE RankNTypes, ViewPatterns, OverloadedStrings #-}
    
import Control.Monad.State
import Control.Monad.ST
import Data.Array.ST
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = inputs >>= putStrLn . uncurry solve
    where
        inputs = (,) <$> readLine <*> B.getLine 

solve :: [Int] -> B.ByteString -> String
solve [n, a, b, c, d] ss 
    | check0 (a - 1) ss = "No"
    | c < d = "Yes"
    | check1 (b - 2) ss = "Yes"
    | otherwise = "No"
    where
        check0 i s@(B.uncons -> Just (_, t))
            | i > max c d - 1 = False
            | "##" `B.isPrefixOf` s = True
            | otherwise = check0 (i + 1) t
        check0 _ _ = False

        check1 i s@(B.uncons -> Just (_, t))
            | i > d - 2 = False
            | "..." `B.isPrefixOf` s = True
            | otherwise = check1 (i + 1) t
        check1 _ _ = False


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

type Table s a b = STArray s a (Maybe b)
type Memo s a b = a -> StateT (Table s a b) (ST s) b

evalMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s b
evalMemo f k = evalStateT (memoizeFix f k)

runMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s (b, Table s a b)
runMemo f k = runStateT (memoizeFix f k)

memoizeFix :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> forall s. Memo s a b
memoizeFix f k = get >>= (\arr -> lift (readArray arr k) >>= maybe (f (memoizeFix f) k >>= ((<$) <*> (lift . writeArray arr k . Just))) return)

Submission Info

Submission Time
Task A - Kenken Race
User lodnix
Language Haskell (GHC 7.10.3)
Score 0
Code Size 1773 Byte
Status
Exec Time 5 ms
Memory 892 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_00, example_01, example_02
All 0 / 400 example_00, example_01, example_02, handmade_00, handmade_01, handmade_02, handmade_03, handmade_04, handmade_05, handmade_06, handmade_07, handmade_08, handmade_09, handmade_10, handmade_11
Case Name Status Exec Time Memory
example_00 1 ms 380 KB
example_01 1 ms 380 KB
example_02 1 ms 380 KB
handmade_00 4 ms 764 KB
handmade_01 2 ms 892 KB
handmade_02 2 ms 764 KB
handmade_03 4 ms 764 KB
handmade_04 5 ms 764 KB
handmade_05 5 ms 764 KB
handmade_06 5 ms 764 KB
handmade_07 5 ms 764 KB
handmade_08 5 ms 764 KB
handmade_09 5 ms 764 KB
handmade_10 5 ms 764 KB
handmade_11 3 ms 764 KB