結果

問題 No.390 最長の数列
ユーザー pekempeypekempey
提出日時 2016-07-29 14:44:16
言語 Haskell
(9.8.2)
結果
AC  
実行時間 557 ms / 5,000 ms
コード長 550 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 177,280 KB
実行使用メモリ 93,024 KB
最終ジャッジ日時 2024-04-10 10:04:01
合計ジャッジ時間 8,211 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
92,900 KB
testcase_01 AC 152 ms
93,024 KB
testcase_02 AC 153 ms
93,020 KB
testcase_03 AC 156 ms
92,764 KB
testcase_04 AC 158 ms
93,016 KB
testcase_05 AC 509 ms
69,264 KB
testcase_06 AC 425 ms
79,392 KB
testcase_07 AC 150 ms
93,020 KB
testcase_08 AC 148 ms
93,016 KB
testcase_09 AC 159 ms
92,764 KB
testcase_10 AC 539 ms
66,196 KB
testcase_11 AC 527 ms
66,320 KB
testcase_12 AC 533 ms
66,324 KB
testcase_13 AC 312 ms
83,224 KB
testcase_14 AC 557 ms
84,632 KB
testcase_15 AC 147 ms
92,900 KB
testcase_16 AC 146 ms
92,788 KB
testcase_17 AC 131 ms
63,284 KB
testcase_18 AC 135 ms
62,144 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) (-10^6) :: IO (IOUArray Int Int)

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

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