結果

問題 No.979 Longest Divisor Sequence
ユーザー ks2mks2m
提出日時 2020-01-31 23:02:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,023 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 77,916 KB
実行使用メモリ 91,020 KB
最終ジャッジ日時 2023-10-17 11:55:55
合計ジャッジ時間 5,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
54,304 KB
testcase_01 AC 64 ms
54,164 KB
testcase_02 AC 65 ms
54,104 KB
testcase_03 AC 66 ms
54,284 KB
testcase_04 AC 65 ms
52,932 KB
testcase_05 AC 64 ms
54,036 KB
testcase_06 AC 66 ms
54,164 KB
testcase_07 AC 64 ms
54,164 KB
testcase_08 AC 66 ms
54,344 KB
testcase_09 AC 66 ms
54,044 KB
testcase_10 AC 138 ms
58,452 KB
testcase_11 AC 139 ms
58,672 KB
testcase_12 AC 140 ms
58,592 KB
testcase_13 AC 385 ms
84,000 KB
testcase_14 AC 1,023 ms
91,020 KB
testcase_15 AC 575 ms
67,228 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++) {
			List<Integer> list = divList(a[i]);
			int max = 0;
			for (int j : list) {
				if (j < a[i]) {
					max = Math.max(max, arr[j]);
				}
				if (j > a[i]) {
					throw new Exception();
				}
			}
			arr[a[i]] = Math.max(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