結果

問題 No.390 最長の数列
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-17 18:43:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,956 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 85,012 KB
実行使用メモリ 82,104 KB
最終ジャッジ日時 2023-10-17 07:25:15
合計ジャッジ時間 14,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
57,512 KB
testcase_01 AC 143 ms
57,324 KB
testcase_02 AC 142 ms
57,516 KB
testcase_03 AC 143 ms
57,636 KB
testcase_04 AC 144 ms
57,728 KB
testcase_05 AC 692 ms
69,928 KB
testcase_06 AC 1,956 ms
82,000 KB
testcase_07 AC 141 ms
57,728 KB
testcase_08 AC 138 ms
57,648 KB
testcase_09 AC 162 ms
59,752 KB
testcase_10 AC 973 ms
76,800 KB
testcase_11 AC 1,028 ms
81,620 KB
testcase_12 AC 982 ms
76,780 KB
testcase_13 AC 955 ms
79,012 KB
testcase_14 AC 1,088 ms
82,104 KB
testcase_15 AC 143 ms
57,496 KB
testcase_16 AC 153 ms
57,604 KB
testcase_17 AC 269 ms
61,452 KB
testcase_18 AC 307 ms
62,900 KB
権限があれば一括ダウンロードができます

ソースコード

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