結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | tenten |
提出日時 | 2020-08-25 11:16:04 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 974 bytes |
コンパイル時間 | 1,833 ms |
コンパイル使用メモリ | 77,068 KB |
実行使用メモリ | 71,796 KB |
最終ジャッジ日時 | 2024-04-24 04:15:45 |
合計ジャッジ時間 | 8,504 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 107 ms
41,100 KB |
testcase_01 | AC | 110 ms
41,388 KB |
testcase_02 | AC | 106 ms
40,952 KB |
testcase_03 | AC | 105 ms
41,228 KB |
testcase_04 | AC | 109 ms
41,388 KB |
testcase_05 | AC | 108 ms
41,200 KB |
testcase_06 | AC | 97 ms
40,196 KB |
testcase_07 | AC | 109 ms
41,372 KB |
testcase_08 | AC | 105 ms
41,360 KB |
testcase_09 | AC | 103 ms
40,328 KB |
testcase_10 | AC | 199 ms
46,196 KB |
testcase_11 | AC | 210 ms
46,652 KB |
testcase_12 | AC | 214 ms
46,376 KB |
testcase_13 | AC | 723 ms
56,356 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 1,346 ms
63,452 KB |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); int ans = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int max = 0; if (x != 1 && map.containsKey(1)) { max = map.get(1); } for (int j = 2; j <= Math.sqrt(x); j++) { if (x % j == 0) { if (map.containsKey(j)) { max = Math.max(max, map.get(j)); } if (map.containsKey(x / j)) { max = Math.max(max, map.get(x / j)); } } } map.put(x, max + 1); ans = Math.max(ans, max + 1); } System.out.println(ans); } }