結果
| 問題 | 
                            No.608 God's Maze
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kuwa
                         | 
                    
| 提出日時 | 2017-12-10 20:47:36 | 
| 言語 | Haskell  (9.10.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,792 bytes | 
| コンパイル時間 | 10,002 ms | 
| コンパイル使用メモリ | 181,284 KB | 
| 実行使用メモリ | 20,224 KB | 
| 最終ジャッジ日時 | 2024-11-30 11:23:28 | 
| 合計ジャッジ時間 | 9,414 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 29 WA * 36 | 
コンパイルメッセージ
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
ソースコード
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"
            
            
            
        
            
kuwa