結果

問題 No.390 最長の数列
ユーザー tentententen
提出日時 2020-09-29 13:44:17
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,093 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 75,900 KB
実行使用メモリ 55,896 KB
最終ジャッジ日時 2023-09-16 21:04:10
合計ジャッジ時間 11,968 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,896 KB
testcase_01 AC 118 ms
55,636 KB
testcase_02 AC 116 ms
55,788 KB
testcase_03 AC 120 ms
55,740 KB
testcase_04 AC 117 ms
55,644 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            lists.add(new ArrayList<>());
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            boolean flag = true;
            for (int j = max - 1; j >= 0 && flag; j--) {
                for (int x : lists.get(j)) {
                    if (arr[i] % x == 0) {
                        lists.get(j + 1).add(arr[i]);
                        max = Math.max(max, j + 2);
                        flag = false;
                        break;
                    }
                }
            }
            if (flag) {
                lists.get(0).add(arr[i]);
                max = Math.max(1, max);
            }
        }
        System.out.println(max);
    }
}
0