結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
takeya_okino
|
| 提出日時 | 2017-06-14 10:38:38 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 790 bytes |
| コンパイル時間 | 3,005 ms |
| コンパイル使用メモリ | 87,020 KB |
| 実行使用メモリ | 82,712 KB |
| 最終ジャッジ日時 | 2024-09-24 18:53:16 |
| 合計ジャッジ時間 | 10,615 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 1 -- * 13 |
ソースコード
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);
}
}
takeya_okino