結果
問題 | No.979 Longest Divisor Sequence |
ユーザー |
![]() |
提出日時 | 2020-01-31 23:03:23 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,236 bytes |
コンパイル時間 | 2,164 ms |
コンパイル使用メモリ | 78,508 KB |
実行使用メモリ | 87,440 KB |
最終ジャッジ日時 | 2024-09-17 10:08:22 |
合計ジャッジ時間 | 5,792 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 RE * 3 |
ソースコード
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;}}