結果

問題 No.1133 キムワイプイーター
ユーザー gemmarogemmaro
提出日時 2020-09-11 09:49:45
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 162,352 KB
実行使用メモリ 7,256 KB
最終ジャッジ日時 2023-08-26 13:30:47
合計ジャッジ時間 5,239 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

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
0