結果

問題 No.1032 数数え
ユーザー こまるこまる
提出日時 2020-11-20 23:45:20
言語 Haskell
(9.8.2)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 10,058 ms
コンパイル使用メモリ 205,260 KB
実行使用メモリ 15,540 KB
最終ジャッジ日時 2023-09-30 20:11:38
合計ジャッジ時間 12,008 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,596 KB
testcase_01 AC 2 ms
7,484 KB
testcase_02 AC 3 ms
7,500 KB
testcase_03 AC 3 ms
7,528 KB
testcase_04 AC 3 ms
7,520 KB
testcase_05 AC 2 ms
7,548 KB
testcase_06 AC 2 ms
7,608 KB
testcase_07 AC 103 ms
15,540 KB
testcase_08 AC 3 ms
7,616 KB
testcase_09 AC 12 ms
11,712 KB
testcase_10 AC 3 ms
7,688 KB
testcase_11 AC 3 ms
7,480 KB
testcase_12 AC 102 ms
14,572 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE TupleSections #-}

import           Control.Monad.State
import           Data.Char
import           Data.Coerce
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU

main :: IO ()
main = do
  [n, m] <- map (read :: String -> Int) . words <$> getLine
  ls <- seqInput n
  let xs = VU.tail . VU.indexed . VU.unsafeAccumulate (+) (VU.replicate (m + 1) 0) . VU.map (, 1 :: Int) $ ls
  VU.forM_ xs $ \(a, b) -> putStrLn $ show a ++ " " ++ show b

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 #-}
seqInput :: Int -> IO (VU.Vector Int)
seqInput n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine
{-# INLINE seqInput #-}
0