結果

問題 No.979 Longest Divisor Sequence
ユーザー kitakitalilykitakitalily
提出日時 2020-01-31 23:31:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,018 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 3,693 ms
コンパイル使用メモリ 78,312 KB
実行使用メモリ 91,048 KB
最終ジャッジ日時 2023-10-17 12:53:22
合計ジャッジ時間 7,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
53,948 KB
testcase_01 AC 66 ms
54,080 KB
testcase_02 AC 66 ms
54,080 KB
testcase_03 AC 66 ms
54,080 KB
testcase_04 AC 66 ms
54,104 KB
testcase_05 AC 66 ms
54,084 KB
testcase_06 AC 69 ms
52,760 KB
testcase_07 AC 66 ms
53,960 KB
testcase_08 AC 66 ms
53,968 KB
testcase_09 AC 66 ms
53,956 KB
testcase_10 AC 138 ms
58,192 KB
testcase_11 AC 141 ms
58,004 KB
testcase_12 AC 141 ms
58,372 KB
testcase_13 AC 379 ms
83,944 KB
testcase_14 AC 1,018 ms
91,048 KB
testcase_15 AC 549 ms
67,080 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]);
				}
			}
			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