AtCoder Beginner Contest 055

Submission #1871433

Source codeソースコード

import Data.List
import qualified Data.ByteString.Char8 as BC (words, getLine, unpack)

data Animal = S | W deriving (Show, Eq)

main = do
  n <- (read :: String -> Int) <$> getLine
  input <- BC.unpack <$> BC.getLine
  let pattern = [[a,b] | a <- [S, W], b <- [S, W]]
      result = map (solve input) pattern
      resultTF = map judge result
      ansIdx = elemIndices True resultTF
  if length ansIdx > 0 then putStrLn . toString $ result !! (head ansIdx)
                       else print $ -1

rev :: Animal -> Animal
rev S = W
rev W = S

solve :: String -> [Animal] -> [Animal]
solve (s:tt) (a:b:bs)
  | s == 'o' && b == S = solve' tt (a:b:bs) ++ [a]
  | s == 'o' && b == W = solve' tt (a:b:bs) ++ [rev a]
  | s == 'x' && b == S = solve' tt (a:b:bs) ++ [rev a]
  | otherwise          = solve' tt (a:b:bs) ++ [a]

solve' :: String -> [Animal] -> [Animal]
solve' []     s        = s
solve' (s:tt) (a:b:bs)
  | s == 'o' && a == S = solve' tt (b:a:b:bs)
  | s == 'o' && a == W = solve' tt ((rev b):a:b:bs)
  | s == 'x' && a == S = solve' tt ((rev b):a:b:bs)
  | otherwise          = solve' tt (b:a:b:bs)

judge :: [Animal] -> Bool
judge []       = False
judge (_:[])   = False
judge (a:b:bs) = a == (last . init $ bs) && b == last bs

toString :: [Animal] -> String
toString = concat . map show . reverse . init . tail

Submission

Task問題 D - Menagerie
User nameユーザ名 amanuko
Created time投稿日時
Language言語 Haskell (GHC 7.10.3)
Status状態 AC
Score得点 500
Source lengthソースコード長 1362 Byte
File nameファイル名
Exec time実行時間 66 ms
Memory usageメモリ使用量 23932 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt,00_example_03.txt
All 500 / 500 00_example_01.txt,00_example_02.txt,00_example_03.txt,01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 1 ms 380 KB
00_example_02.txt AC 1 ms 380 KB
00_example_03.txt AC 1 ms 380 KB
01.txt AC 45 ms 18812 KB
02.txt AC 30 ms 11644 KB
03.txt AC 3 ms 1404 KB
04.txt AC 1 ms 508 KB
05.txt AC 61 ms 22908 KB
06.txt AC 59 ms 20860 KB
07.txt AC 10 ms 3708 KB
08.txt AC 13 ms 5500 KB
09.txt AC 4 ms 1660 KB
10.txt AC 12 ms 4988 KB
11.txt AC 66 ms 23932 KB
12.txt AC 66 ms 23932 KB
13.txt AC 66 ms 23932 KB