結果
問題 | No.1021 Children in Classrooms |
ユーザー | こまる |
提出日時 | 2020-11-08 04:08:59 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 4,062 bytes |
コンパイル時間 | 6,095 ms |
コンパイル使用メモリ | 257,664 KB |
実行使用メモリ | 20,592 KB |
最終ジャッジ日時 | 2024-07-22 15:00:41 |
合計ジャッジ時間 | 7,257 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 5 ms
7,424 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 5 ms
7,168 KB |
testcase_07 | AC | 5 ms
8,064 KB |
testcase_08 | AC | 5 ms
7,680 KB |
testcase_09 | AC | 122 ms
20,468 KB |
testcase_10 | AC | 122 ms
20,592 KB |
testcase_11 | AC | 122 ms
20,028 KB |
testcase_12 | AC | 123 ms
20,032 KB |
testcase_13 | AC | 122 ms
20,028 KB |
testcase_14 | AC | 122 ms
19,904 KB |
testcase_15 | AC | 87 ms
18,792 KB |
testcase_16 | AC | 88 ms
18,812 KB |
testcase_17 | AC | 91 ms
18,968 KB |
testcase_18 | AC | 113 ms
20,324 KB |
testcase_19 | AC | 12 ms
12,800 KB |
コンパイルメッセージ
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
ソースコード
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BinaryLiterals #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE UnicodeSyntax #-} {-# LANGUAGE ViewPatterns #-} module Main where import Control.Monad import Control.Monad.Cont import Control.Monad.Fix import Control.Monad.ST import Control.Monad.State import Data.Bits import Data.Bool import Data.Char import Data.Coerce import qualified Data.Foldable as F import qualified Data.List as L import Data.IORef import Data.STRef import Data.Word import GHC.Exts import System.IO import Unsafe.Coerce import qualified Data.ByteString as BS import qualified Data.ByteString.Builder as BSB import qualified Data.ByteString.Char8 as BSC8 import qualified Data.ByteString.Unsafe as BSU import qualified Data.Vector as V import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Generic as VG import qualified Data.Vector.Generic.Mutable as VGM import qualified Data.Vector.Mutable as VM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do [n, m] <- map (read @Int) . words <$> getLine ax <- seqInput' n sx <- seqInput m cnt <- VUM.replicate (n + 2 * m + 10) (0 :: Int) cur <- newIORef (m + 5) rep n $ \i -> VUM.unsafeWrite cnt (m + 5 + i) (ax VU.! i) rep m $ \i -> do cu <- readIORef cur if sx VU.! i == 'L' then do item <- VUM.unsafeRead cnt cu VUM.unsafeModify cnt (+ item) (cu + 1) VUM.unsafeWrite cnt cu 0 modifyIORef' cur succ else do item <- VUM.unsafeRead cnt (cu + n - 1) VUM.unsafeModify cnt (+ item) (cu + n - 2) VUM.unsafeWrite cnt (cu + n - 1) 0 modifyIORef' cur pred rep n $ \i -> do when (i /= 0) $ putStr " " cu <- readIORef cur ans <- VUM.unsafeRead cnt (cu + i) putStr $ show ans putStr "\n" type CParser a = StateT BSC8.ByteString Maybe a runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString) runCParser = runStateT {-# INLINE runCParser #-} int :: CParser Int int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace {-# INLINE int #-} char :: CParser Char char = coerce BSC8.uncons {-# INLINE char #-} seqInput :: Int -> IO (VU.Vector Char) seqInput n = VU.unfoldrN n (runCParser char) <$> BSC8.getLine {-# INLINE seqInput #-} seqInput' :: Int -> IO (VU.Vector Int) seqInput' n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine {-# INLINE seqInput' #-} stream :: Monad m => Int -> Int -> VFSM.Stream m Int stream !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 0 n) {-# INLINE rep #-}