結果

問題 No.979 Longest Divisor Sequence
ユーザー htensaihtensai
提出日時 2020-02-06 12:52:14
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 926 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 76,520 KB
実行使用メモリ 86,556 KB
最終ジャッジ日時 2023-10-25 22:28:48
合計ジャッジ時間 9,660 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
57,636 KB
testcase_01 AC 122 ms
57,144 KB
testcase_02 AC 123 ms
57,640 KB
testcase_03 AC 115 ms
57,384 KB
testcase_04 AC 118 ms
57,620 KB
testcase_05 AC 119 ms
57,304 KB
testcase_06 AC 113 ms
57,756 KB
testcase_07 AC 116 ms
56,204 KB
testcase_08 AC 120 ms
57,644 KB
testcase_09 AC 121 ms
57,380 KB
testcase_10 AC 248 ms
61,724 KB
testcase_11 AC 235 ms
60,004 KB
testcase_12 AC 238 ms
61,492 KB
testcase_13 AC 691 ms
72,600 KB
testcase_14 TLE -
testcase_15 AC 1,390 ms
77,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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