結果
| 問題 |
No.1133 キムワイプイーター
|
| ユーザー |
|
| 提出日時 | 2020-09-11 09:49:45 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,236 bytes |
| コンパイル時間 | 5,691 ms |
| コンパイル使用メモリ | 171,776 KB |
| 実行使用メモリ | 215,680 KB |
| 最終ジャッジ日時 | 2024-12-25 10:24:32 |
| 合計ジャッジ時間 | 50,711 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 17 TLE * 14 |
コンパイルメッセージ
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
ソースコード
import qualified Data.List as L
main :: IO ()
main = do
[n, _m] <- map read . words <$> getLine
s <- getLine
putStrLn $ solve n s
solve :: Int -> [Char] -> String
solve n =
unlines
. map (unwords . map showBool)
. solve' n
where
showBool :: Bool -> String
showBool b = if b then "0" else "1"
solve' :: Int -> [Char] -> [[Bool]]
solve' n cs = solve'' n cs [(0, n)]
solve'' :: Int -> [Char] -> [(Int, Int)] -> [[Bool]]
solve'' n [] ps = fromCoords n $ L.nub ps
solve'' n (c:cs) ps@((x, y):_) = solve'' n cs ((x', y'):ps)
where x' =
case c of
'R' -> x + 1
'L' -> x - 1
_ -> x
y' =
case c of
'U' -> y - 1
'D' -> y + 1
_ -> y
solve'' _ _ [] = [[]] -- unreachable
fromCoords :: Int -> [(Int, Int)] -> [[Bool]]
fromCoords n ps =
fromCoords' ps
$ replicate (n + 1) (replicate (n + 1) False)
where
fromCoords' :: [(Int, Int)] -> [[Bool]] -> [[Bool]]
fromCoords' [] bs = bs
fromCoords' ((x, y):qs) bs =
fromCoords' qs
$ update y (update x True (bs!!y)) bs
where
update :: Int -> a -> [a] -> [a]
update i a as = take i as ++ [a] ++ drop (i + 1) as