結果

問題 No.5 数字のブロック
コンテスト
ユーザー vjudge1
提出日時 2026-08-19 12:34:17
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
+ 913µs
コード長 738 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,937 ms
コンパイル使用メモリ 207,304 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2026-08-19 12:34:29
合計ジャッジ時間 5,050 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.List (sort)

-- This recursive function naturally short-circuits (early exit).
-- The moment `k >= x` is false, it stops and returns 0 without looking at the rest of `xs`.
solve :: Int -> [Int] -> Int
solve k (x:xs) | k >= x = 1 + solve (k - x) xs
solve _ _               = 0

main :: IO ()
main = do
    -- 1. Read all input instantly as raw bytes (B.getContents)
    input <- B.getContents
    
    -- 2. B.words splits by any whitespace (newlines or spaces)
    -- 3. B.readInt parses integers directly from the byte array
    let (k:_:xs) = map (fst . fromJust . B.readInt) (B.words input)
    
    -- 4. Sort and solve
    print (solve k (sort xs))
0