結果

問題 No.249 N言っちゃダメゲーム (2)
ユーザー ducktailducktail
提出日時 2018-02-05 14:04:45
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 669 bytes
コンパイル時間 3,638 ms
コンパイル使用メモリ 160,388 KB
実行使用メモリ 14,204 KB
最終ジャッジ日時 2023-09-21 21:36:18
合計ジャッジ時間 4,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  solve <$> replicateM 1000 (getl $ readil B.readInt) >>= print

solve :: [[Int]] -> Int
solve = foldl' f 0
  where
    f c e = if win e then c + 1 else c

win [n, k] = (n - 1) `mod` (k + 1) /= 0

getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')
0