結果

問題 No.979 Longest Divisor Sequence
ユーザー htensaihtensai
提出日時 2020-02-06 13:19:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,162 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 75,044 KB
実行使用メモリ 80,800 KB
最終ジャッジ日時 2023-10-25 22:30:58
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,376 KB
testcase_01 AC 51 ms
53,376 KB
testcase_02 AC 50 ms
53,372 KB
testcase_03 AC 50 ms
53,372 KB
testcase_04 AC 51 ms
53,380 KB
testcase_05 AC 50 ms
53,376 KB
testcase_06 AC 49 ms
53,380 KB
testcase_07 AC 50 ms
53,384 KB
testcase_08 AC 51 ms
53,372 KB
testcase_09 AC 51 ms
53,380 KB
testcase_10 AC 88 ms
55,016 KB
testcase_11 AC 87 ms
55,336 KB
testcase_12 AC 88 ms
55,032 KB
testcase_13 AC 275 ms
80,404 KB
testcase_14 AC 1,162 ms
80,800 KB
testcase_15 AC 485 ms
63,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] map = new int[300001];
        int ans = 1;
        String[] line = br.readLine().split(" ", n);
        for (int i = 0; i < n; i++) {
            int max = 0;
            int x = Integer.parseInt(line[i]);
            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