結果

問題 No.979 Longest Divisor Sequence
ユーザー ks2mks2m
提出日時 2020-01-31 22:35:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,170 bytes
コンパイル時間 2,501 ms
コンパイル使用メモリ 78,080 KB
実行使用メモリ 91,188 KB
最終ジャッジ日時 2023-10-17 10:53:00
合計ジャッジ時間 6,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
54,192 KB
testcase_01 AC 66 ms
54,092 KB
testcase_02 AC 66 ms
54,192 KB
testcase_03 AC 66 ms
54,328 KB
testcase_04 AC 66 ms
54,328 KB
testcase_05 AC 66 ms
54,188 KB
testcase_06 AC 66 ms
54,288 KB
testcase_07 WA -
testcase_08 AC 66 ms
54,096 KB
testcase_09 AC 66 ms
54,164 KB
testcase_10 AC 140 ms
58,644 KB
testcase_11 AC 141 ms
58,560 KB
testcase_12 AC 141 ms
58,740 KB
testcase_13 AC 299 ms
81,792 KB
testcase_14 WA -
testcase_15 AC 592 ms
68,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

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());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] arr = new int[300001];
		for (int i = 0; i < n; i++) {
			if (arr[a[i]] == 0) {
				List<Integer> list = divList(a[i]);
				int max = 0;
				for (int j : list) {
					max = Math.max(max, arr[j]);
				}
				arr[a[i]] = max + 1;
			}
		}
		int ans = 0;
		for (int i = 0; i < arr.length; i++) {
			ans = Math.max(ans, arr[i]);
		}
		System.out.println(ans);
	}

	static List<Integer> divList(int n) {
		List<Integer> list = new ArrayList<>();
		int end = (int) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				list.add(i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		return list;
	}
}
0