結果

問題 No.608 God's Maze
ユーザー kuwakuwa
提出日時 2017-12-10 20:47:36
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 10,820 ms
コンパイル使用メモリ 181,296 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2024-05-07 16:59:55
合計ジャッジ時間 8,913 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
5,248 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 WA -
testcase_30 AC 32 ms
19,328 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 29 ms
17,792 KB
testcase_34 WA -
testcase_35 AC 5 ms
8,064 KB
testcase_36 AC 7 ms
9,472 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 5 ms
7,680 KB
testcase_40 WA -
testcase_41 AC 9 ms
10,624 KB
testcase_42 WA -
testcase_43 AC 8 ms
9,472 KB
testcase_44 WA -
testcase_45 AC 26 ms
15,872 KB
testcase_46 AC 6 ms
8,448 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 WA -
testcase_49 AC 8 ms
9,472 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1 ms
5,376 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 1 ms
5,376 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BS

import Debug.Trace

------------------------------------------

data Tile = Front | Back deriving (Eq, Show)

fromChar :: Char -> Tile
fromChar '#' = Front
fromChar _ = Back

flipTile Front = Back
flipTile Back  = Front

main :: IO ()
main = do
  n <- readInt
  s <- map fromChar <$> BC.unpack <$> BC.getLine
  let leng = length s
      res = min (solve (n-1) s) (solve (leng-n) $ reverse s)
  print res

solve :: Int -> [Tile] -> Int
solve n ts' =
  let ts = foldr arrange [] $ dropWhile (== Front) (mapn n flipTile ts')
        where arrange Back [] =[]
              arrange x xs = x:xs
      n0 = n - min n (length ts' - length ts)
      score acc [] = acc
      score acc (Back:[]) = acc
      score acc (x:y:[]) = 
        case (x, y) of
          (Back, Back)   -> acc
          (Back, Front)  -> acc+1
          (Front, Front) -> acc+2
          (Front, Back)  -> acc+3
      score acc (x:y:ys) = 
        case x of
          Back  -> score (acc+1) (flipTile y:ys)
          Front -> score (acc+3) (y:ys)
  in  score n0 ts

mapn :: Int -> (a -> a) -> [a] -> [a]
mapn _ _ [] = []
mapn n f (x:xs)
  | n <= 0    = x:xs
  | otherwise = f x : mapn (n-1) f xs

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"
0