結果

問題 No.714 回転寿司屋のシミュレート
ユーザー ducktailducktail
提出日時 2018-07-20 17:57:26
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,415 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 202,404 KB
最終ジャッジ日時 2024-04-27 02:35:19
合計ジャッジ時間 2,084 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:12:3: error: [GHC-88464]
    Variable not in scope:
      replicateM :: Int -> IO [ByteString] -> IO [[ByteString]]
    Suggested fixes:
      • Perhaps use one of these:
          ‘V.replicateM’ (imported from Data.Vector),
          ‘replicate’ (imported from Prelude),
          ‘V.replicate’ (imported from Data.Vector)
      • Add ‘replicateM’ to the import list in the import of
        ‘Data.Vector’ (at Main.hs:5:1-38).
   |
12 |   replicateM n (B.words <$> B.getLine) >>= solve
   |   ^^^^^^^^^^

ソースコード

diff #

import Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (delete)
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
import Control.Monad.State

main :: IO ()
main = do
  n <- readi B.readInt <$> B.getLine
  replicateM n (B.words <$> B.getLine) >>= solve

solve :: [[ByteString]] -> IO ()
solve bs = evalStateT (sushi bs) (V.replicate 21 [])

sushi :: [[ByteString]] -> StateT (Vector [ByteString]) IO ()
sushi [] = return ()
sushi ((d:rs):bs) | readi B.readInt d == 0 = do
                      let (n:_:as) = rs
                      v <- get
                      put $ v // [(readi B.readInt n, as)]
                      sushi bs
                  | readi B.readInt d == 2 = do
                      v <- get
                      put $ v // [(readi B.readInt (head rs), [])]
                      sushi bs
                  | otherwise = do
                      v <- get
                      case V.findIndex (\ls -> (head rs) `elem` ls) v of
                       Just x -> do
                         lift $ putStrLn (show x)
                         put $ v // [(x, delete (head rs) (v ! x))]
                       Nothing -> lift $ putStrLn "-1"
                      sushi bs

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n
0