結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2020-10-17 09:35:52 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,374 bytes |
| コンパイル時間 | 3,393 ms |
| コンパイル使用メモリ | 204,592 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-21 01:51:26 |
| 合計ジャッジ時間 | 4,407 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
コンパイルメッセージ
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 NumericUnderscores #-}
{-# LANGUAGE TupleSections #-}
import Control.Arrow
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed as VU
-------------------------------------------------------------------------------
-- input
-------------------------------------------------------------------------------
type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)
parseInt :: Parser Int
parseInt = fmap (second BSC8.tail) . BSC8.readInt
parseM :: Int -> IO (VU.Vector Int)
parseM m = VU.unfoldrN m parseInt <$> BSC8.getLine
-------------------------------------------------------------------------------
-- Bucket Sort
-------------------------------------------------------------------------------
bucketSortVU :: Int -> VU.Vector Int -> VU.Vector Int
bucketSortVU bucketSize
= VU.concatMap (uncurry $ flip VU.replicate)
. VU.indexed
. VU.unsafeAccumulate (+) (VU.replicate bucketSize 0)
. VU.map (, 1)
{-# INLINE bucketSortVU #-}
-------------------------------------------------------------------------------
-- main
-------------------------------------------------------------------------------
main :: IO ()
main = do
l <- readLn :: IO Int
m <- readLn :: IO Int
ws <- parseM m
print . VU.length . VU.takeWhile (<= l) . VU.scanl1' (+) . bucketSortVU 10_000 $ ws