結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | ks2m |
提出日時 | 2020-01-31 23:03:23 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,236 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 78,100 KB |
実行使用メモリ | 91,028 KB |
最終ジャッジ日時 | 2023-10-17 11:57:04 |
合計ジャッジ時間 | 5,867 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
54,336 KB |
testcase_01 | AC | 63 ms
54,064 KB |
testcase_02 | AC | 65 ms
54,308 KB |
testcase_03 | AC | 64 ms
54,308 KB |
testcase_04 | RE | - |
testcase_05 | AC | 62 ms
54,320 KB |
testcase_06 | AC | 65 ms
54,296 KB |
testcase_07 | AC | 63 ms
52,260 KB |
testcase_08 | RE | - |
testcase_09 | AC | 64 ms
54,328 KB |
testcase_10 | AC | 132 ms
58,356 KB |
testcase_11 | AC | 133 ms
58,256 KB |
testcase_12 | AC | 137 ms
58,696 KB |
testcase_13 | RE | - |
testcase_14 | AC | 1,039 ms
91,028 KB |
testcase_15 | AC | 530 ms
67,152 KB |
ソースコード
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; } }