結果

問題 No.123 カードシャッフル
ユーザー 情報学生情報学生
提出日時 2019-09-14 02:13:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 704 bytes
コンパイル時間 7,592 ms
コンパイル使用メモリ 163,932 KB
実行使用メモリ 14,252 KB
最終ジャッジ日時 2023-09-17 21:56:01
合計ジャッジ時間 8,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,196 KB
testcase_01 AC 2 ms
7,248 KB
testcase_02 AC 3 ms
7,252 KB
testcase_03 AC 3 ms
7,264 KB
testcase_04 AC 3 ms
7,288 KB
testcase_05 AC 3 ms
7,284 KB
testcase_06 AC 2 ms
7,292 KB
testcase_07 AC 3 ms
7,252 KB
testcase_08 AC 3 ms
7,224 KB
testcase_09 AC 2 ms
7,280 KB
testcase_10 AC 22 ms
14,252 KB
testcase_11 AC 23 ms
14,232 KB
testcase_12 AC 22 ms
14,208 KB
testcase_13 AC 22 ms
14,200 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 #

import Control.Applicative ((<$>))
import Data.Char (isSpace)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (foldl', unfoldr)

getL :: (ByteString -> [Int]) -> IO [Int]
getL f = f <$> B.getLine

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

main :: IO ()
main = do
    B.getLine
    as <- reverse <$> getL (readIL B.readInt)
    print $ foldl' f 1 as
    where
        f :: Int -> Int -> Int
        f acc n | acc == 1  = n
                | acc <= n  = acc - 1
                | otherwise = acc
0