結果
問題 | No.390 最長の数列 |
ユーザー | takeya_okino |
提出日時 | 2017-06-14 10:38:38 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 790 bytes |
コンパイル時間 | 3,897 ms |
コンパイル使用メモリ | 78,936 KB |
実行使用メモリ | 57,480 KB |
最終ジャッジ日時 | 2023-10-24 23:51:14 |
合計ジャッジ時間 | 12,466 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
57,140 KB |
testcase_01 | AC | 131 ms
57,480 KB |
testcase_02 | AC | 132 ms
57,372 KB |
testcase_03 | AC | 130 ms
57,156 KB |
testcase_04 | AC | 130 ms
56,996 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); ArrayList<Integer> xList = new ArrayList<Integer>(); for(int i = 0; i < N; i++) { xList.add(sc.nextInt()); } Collections.sort(xList); int A = xList.get(xList.size() - 1); int[] dp = new int[A + 1]; for(int i = 1; i < A + 1; i++) { if(xList.contains(i)) { dp[i] = 1; } else { dp[i] = -1; } } int ans = 0; for(int i = 1; i < A + 1; i++) { ans = Math.max(ans, dp[i]); if(dp[i] > 0) { for(int j = 2 * i; j < A + 1; j += i) { if(dp[j] > 0) dp[j] = Math.max(dp[j], 1 + dp[i]); } } } System.out.println(ans); } }