結果

問題 No.979 Longest Divisor Sequence
コンテスト
ユーザー htensai
提出日時 2020-02-06 12:52:14
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 1,179 ms / 2,000 ms
コード長 926 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,993 ms
コンパイル使用メモリ 82,020 KB
実行使用メモリ 70,052 KB
最終ジャッジ日時 2026-04-12 11:15:00
合計ジャッジ時間 7,928 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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