結果

問題 No.608 God's Maze
ユーザー kuwakuwa
提出日時 2017-12-10 20:47:36
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 162,164 KB
実行使用メモリ 22,680 KB
最終ジャッジ日時 2023-08-20 09:57:47
合計ジャッジ時間 6,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
7,080 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
7,152 KB
testcase_06 AC 3 ms
7,200 KB
testcase_07 WA -
testcase_08 AC 2 ms
7,080 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
7,072 KB
testcase_13 AC 3 ms
7,100 KB
testcase_14 WA -
testcase_15 AC 2 ms
7,224 KB
testcase_16 AC 3 ms
7,204 KB
testcase_17 AC 3 ms
7,188 KB
testcase_18 AC 3 ms
7,084 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
7,188 KB
testcase_24 AC 3 ms
7,144 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3 ms
7,284 KB
testcase_28 AC 3 ms
7,088 KB
testcase_29 WA -
testcase_30 AC 43 ms
21,940 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 43 ms
20,360 KB
testcase_34 WA -
testcase_35 AC 12 ms
11,100 KB
testcase_36 AC 13 ms
12,672 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 7 ms
11,112 KB
testcase_40 WA -
testcase_41 AC 23 ms
13,684 KB
testcase_42 WA -
testcase_43 AC 13 ms
12,688 KB
testcase_44 WA -
testcase_45 AC 33 ms
18,456 KB
testcase_46 AC 9 ms
11,564 KB
testcase_47 AC 4 ms
7,332 KB
testcase_48 WA -
testcase_49 AC 12 ms
12,660 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 3 ms
7,172 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 3 ms
7,084 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 3 ms
7,208 KB
testcase_64 AC 3 ms
7,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/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