結果

問題 No.979 Longest Divisor Sequence
コンテスト
ユーザー ks2m
提出日時 2020-01-31 23:02:43
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 1,235 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,072 ms
コンパイル使用メモリ 83,648 KB
実行使用メモリ 75,444 KB
最終ジャッジ日時 2026-04-06 05:52:15
合計ジャッジ時間 4,304 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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