結果
問題 | No.390 最長の数列 |
ユーザー |
![]() |
提出日時 | 2016-07-16 16:51:53 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 717 ms / 5,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 4,053 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 56,844 KB |
最終ジャッジ日時 | 2024-10-02 10:58:39 |
合計ジャッジ時間 | 11,481 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class No0390 { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static boolean debug = false; static void solve() { int n = in.nextInt(); int[] a = new int[n]; for (int i=0; i<n; i++) { a[i] = in.nextInt(); } int MAX = 1000001; int[] dp = new int[MAX]; for (int x : a) { dp[x] = 1; } int ans = 1; for (int i=1; i<MAX; i++) { if (dp[i] == 0) continue; for (int j=i+i; j<MAX; j+=i) { if (dp[j] != 0) { dp[j] = Math.max(dp[i] + 1, dp[j]); } } ans = Math.max(ans, dp[i]); } out.println(ans); } public static void main(String[] args) { debug = args.length > 0; long start = System.nanoTime(); solve(); out.flush(); long end = System.nanoTime(); dump((end - start) / 1000000 + " ms"); in.close(); out.close(); } static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); } }