結果

問題 No.979 Longest Divisor Sequence
ユーザー htensaihtensai
提出日時 2020-02-06 12:59:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,687 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 3,627 ms
コンパイル使用メモリ 83,084 KB
実行使用メモリ 72,884 KB
最終ジャッジ日時 2023-10-25 22:29:35
合計ジャッジ時間 7,961 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
59,476 KB
testcase_01 AC 122 ms
59,536 KB
testcase_02 AC 120 ms
59,292 KB
testcase_03 AC 116 ms
58,900 KB
testcase_04 AC 120 ms
59,288 KB
testcase_05 AC 121 ms
57,676 KB
testcase_06 AC 113 ms
58,356 KB
testcase_07 AC 116 ms
59,752 KB
testcase_08 AC 120 ms
59,620 KB
testcase_09 AC 121 ms
59,348 KB
testcase_10 AC 218 ms
60,696 KB
testcase_11 AC 218 ms
60,512 KB
testcase_12 AC 211 ms
60,468 KB
testcase_13 AC 660 ms
72,884 KB
testcase_14 AC 1,687 ms
72,392 KB
testcase_15 AC 932 ms
72,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] map = new int[300001];
        int ans = 1;
        for (int i = 0; i < n; i++) {
            int max = 0;
            int x = sc.nextInt();
            if (x != 1) {
                max = map[1];
            }
            for (int j = 2; j <= Math.sqrt(x); j++) {
                if (x % j == 0) {
                    max = Math.max(max, map[j]);
                    max = Math.max(max, map[x / j]);
                }
            }
            map[x] = max + 1;
            ans = Math.max(ans, max + 1);
        }
        System.out.println(ans);
    }
}
0