結果

問題 No.769 UNOシミュレータ
ユーザー ducktailducktail
提出日時 2018-12-18 14:05:58
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 2,634 bytes
コンパイル時間 14,627 ms
コンパイル使用メモリ 233,088 KB
実行使用メモリ 116,480 KB
最終ジャッジ日時 2024-05-02 00:13:05
合計ジャッジ時間 23,937 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
116,480 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 7 ms
9,472 KB
testcase_05 AC 7 ms
9,600 KB
testcase_06 AC 7 ms
9,472 KB
testcase_07 AC 7 ms
9,472 KB
testcase_08 AC 7 ms
9,472 KB
testcase_09 AC 52 ms
15,104 KB
testcase_10 AC 54 ms
15,360 KB
testcase_11 AC 52 ms
15,360 KB
testcase_12 AC 1,679 ms
59,136 KB
testcase_13 AC 1,675 ms
59,136 KB
testcase_14 AC 1,718 ms
59,136 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n, m] <- f
  solve n <$> replicateM m getLine >>= putStrLn . unwords . map show
  where
    f = map read <$> words <$> getLine

solve :: Int -> [String] -> [Int]
solve n xs = evalState (f xs) (V.replicate n 0, 0, 1, 0, 0)
  where
    f :: [String] -> State (Vector Int, Int, Int, Int, Int) [Int]
    f [] = do
      (v, t, dr, _, _) <- get
      let pt = (t - dr) `mod` n
      return [pt + 1, v ! pt]
    f ("number":rs) = do
      (v, t, dr, d2, d4) <- get
      let nt = (t + dr) `mod` n
      if d2 > 0
        then do
          put (v // [(t, (v ! t) - 2 * d2)], nt, dr, 0, d4)
          f ("number":rs)
        else if d4 > 0
             then do
               put (v // [(t, (v ! t) - 4 * d4)], nt, dr, d2, 0)
               f ("number":rs)
             else do
               put (v // [(t, (v ! t) + 1)], nt, dr, d2, d4)
               f rs
    f ("drawtwo":rs) = do
      (v, t, dr, d2, d4) <- get
      let nt = (t + dr) `mod` n
      if d4 > 0
        then do
          put (v // [(t, (v ! t) - 4 * d4)], nt, dr, d2, 0)
          f ("drawtwo":rs)
        else do
          put (v // [(t, (v ! t) + 1)], nt, dr, d2 + 1, d4)
          f rs
    f ("drawfour":rs) = do
      (v, t, dr, d2, d4) <- get
      let nt = (t + dr) `mod` n
      if d2 > 0
        then do
          put (v // [(t, (v ! t) - 2 * d2)], nt, dr, 0, d4)
          f ("drawfour":rs)
        else do
          put (v // [(t, (v ! t) + 1)], nt, dr, d2, d4 + 1)
          f rs
    f ("skip":rs) = do
      (v, t, dr, d2, d4) <- get
      let nt = (t + dr) `mod` n
      if d2 > 0
        then do
          put (v // [(t, (v ! t) - 2 * d2)], nt, dr, 0, d4)
          f ("skip":rs)
        else if d4 > 0
             then do
               put (v // [(t, (v ! t) - 4 * d4)], nt, dr, d2, 0)
               f ("skip":rs)
             else do
               let nnt = (nt + dr) `mod` n
               put (v // [(t, (v ! t) + 1)], nnt, dr, d2, d4)
               f rs
    f ("reverse":rs) = do
      (v, t, dr, d2, d4) <- get
      let nt = (t + dr) `mod` n
      if d2 > 0
        then do
          put (v // [(t, (v ! t) - 2 * d2)], nt, dr, 0, d4)
          f ("reverse":rs)
        else if d4 > 0
             then do
               put (v // [(t, (v ! t) - 4 * d4)], nt, dr, d2, 0)
               f ("reverse":rs)
             else do
               let nt' = (t - dr) `mod` n
               put (v // [(t, (v ! t) + 1)], nt', negate dr, d2, d4)
               f rs
0