結果

問題 No.390 最長の数列
ユーザー pekempeypekempey
提出日時 2016-07-29 14:53:06
言語 Haskell
(9.8.2)
結果
AC  
実行時間 526 ms / 5,000 ms
コード長 552 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 177,920 KB
実行使用メモリ 72,224 KB
最終ジャッジ日時 2024-04-10 10:04:21
合計ジャッジ時間 6,773 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
47,844 KB
testcase_01 AC 95 ms
47,844 KB
testcase_02 AC 98 ms
47,964 KB
testcase_03 AC 96 ms
47,712 KB
testcase_04 AC 101 ms
47,708 KB
testcase_05 AC 486 ms
63,252 KB
testcase_06 AC 405 ms
72,224 KB
testcase_07 AC 96 ms
47,708 KB
testcase_08 AC 88 ms
47,964 KB
testcase_09 AC 90 ms
47,712 KB
testcase_10 AC 506 ms
64,404 KB
testcase_11 AC 526 ms
64,272 KB
testcase_12 AC 495 ms
64,400 KB
testcase_13 AC 261 ms
46,104 KB
testcase_14 AC 506 ms
50,836 KB
testcase_15 AC 94 ms
47,964 KB
testcase_16 AC 87 ms
47,732 KB
testcase_17 AC 114 ms
54,068 KB
testcase_18 AC 124 ms
53,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import Control.Applicative
import Control.Monad
import Data.Array.IO
import Data.List

n = 10 ^ 6

main = do
    _ <- readLn :: IO Int
    a <- sort . map read . words <$> getLine :: IO [Int]
    
    dp <- newArray (0, n) (-1) :: IO (IOUArray Int Int)

    forM_ a $ \i -> do
        writeArray dp i 1

    forM_ a $ \i -> do
        forM_ [i * 2, i * 3 .. n] $ \j -> do
            y <- readArray dp j
            when (y > 0) $ writeArray dp j =<< max <$> ((+ 1) <$> readArray dp i) <*> readArray dp j
   
    print =<< maximum <$> getElems dp
    
0