結果

問題 No.365 ジェンガソート
ユーザー ducktailducktail
提出日時 2018-05-06 13:04:34
言語 Haskell
(9.8.2)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 3,779 ms
コンパイル使用メモリ 163,576 KB
実行使用メモリ 28,524 KB
最終ジャッジ日時 2023-09-10 10:43:59
合計ジャッジ時間 7,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,908 KB
testcase_01 AC 2 ms
7,892 KB
testcase_02 AC 2 ms
7,988 KB
testcase_03 AC 2 ms
7,536 KB
testcase_04 AC 3 ms
7,876 KB
testcase_05 AC 2 ms
7,884 KB
testcase_06 AC 2 ms
7,872 KB
testcase_07 AC 2 ms
7,840 KB
testcase_08 AC 3 ms
7,996 KB
testcase_09 AC 2 ms
8,084 KB
testcase_10 AC 3 ms
7,872 KB
testcase_11 AC 3 ms
7,968 KB
testcase_12 AC 2 ms
8,032 KB
testcase_13 AC 3 ms
8,116 KB
testcase_14 AC 3 ms
8,004 KB
testcase_15 AC 3 ms
8,020 KB
testcase_16 AC 72 ms
20,452 KB
testcase_17 AC 72 ms
22,868 KB
testcase_18 AC 12 ms
13,056 KB
testcase_19 AC 62 ms
26,184 KB
testcase_20 AC 23 ms
15,088 KB
testcase_21 AC 22 ms
14,576 KB
testcase_22 AC 73 ms
20,532 KB
testcase_23 AC 42 ms
16,660 KB
testcase_24 AC 72 ms
20,512 KB
testcase_25 AC 22 ms
14,624 KB
testcase_26 AC 53 ms
19,788 KB
testcase_27 AC 112 ms
28,388 KB
testcase_28 AC 62 ms
19,808 KB
testcase_29 AC 92 ms
22,080 KB
testcase_30 AC 63 ms
19,936 KB
testcase_31 AC 33 ms
15,460 KB
testcase_32 AC 32 ms
15,960 KB
testcase_33 AC 113 ms
28,516 KB
testcase_34 AC 23 ms
14,036 KB
testcase_35 AC 73 ms
20,508 KB
testcase_36 AC 52 ms
26,716 KB
testcase_37 AC 53 ms
26,236 KB
testcase_38 AC 122 ms
28,524 KB
testcase_39 AC 52 ms
26,216 KB
testcase_40 AC 52 ms
26,192 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.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)
import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IM

main :: IO ()
main = solve <$> readLn <*> (readil B.readInt <$> B.getLine) >>= print

solve :: Int -> [Int] -> Int
solve n xs = f (db ! n) (n - 1)
  where db = IM.fromList $ zip xs [1..]
        f _ 0 = 0
        f i m = if mi < i then f mi (m - 1) else m
          where mi = db ! m
                
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