結果

問題 No.390 最長の数列
ユーザー neko_the_shadow
提出日時 2019-05-17 18:43:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,919 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 87,520 KB
実行使用メモリ 78,800 KB
最終ジャッジ日時 2024-09-17 05:59:58
合計ジャッジ時間 13,415 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        
        int n = stdin.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = stdin.nextInt();
        }
        
        Arrays.sort(x);
        Map<Integer, Integer> indexes  = IntStream.range(0, n).boxed().collect(Collectors.toMap(i -> x[i], Function.identity()));
        
        int[] dp = new int[n];
        Arrays.fill(dp, 1);
        for (int i = 0; i < n; i++) {
            for (int j = x[i] * 2; j <= x[n - 1]; j += x[i]) {
                if (indexes.containsKey(j)) {
                    dp[indexes.get(j)] = Math.max(dp[indexes.get(j)], dp[i] + 1);
                }
            }
        }
        
        int ans = Arrays.stream(dp).max().getAsInt();
        System.out.println(ans);
    }
}
0