結果

問題 No.390 最長の数列
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-07-16 16:51:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 667 ms / 5,000 ms
コード長 1,039 bytes
コンパイル時間 3,453 ms
コンパイル使用メモリ 84,108 KB
実行使用メモリ 67,984 KB
最終ジャッジ日時 2024-04-10 09:11:22
合計ジャッジ時間 10,448 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,692 KB
testcase_01 AC 149 ms
58,524 KB
testcase_02 AC 137 ms
57,708 KB
testcase_03 AC 143 ms
58,524 KB
testcase_04 AC 146 ms
58,576 KB
testcase_05 AC 564 ms
63,916 KB
testcase_06 AC 667 ms
67,984 KB
testcase_07 AC 142 ms
58,248 KB
testcase_08 AC 129 ms
57,660 KB
testcase_09 AC 135 ms
57,784 KB
testcase_10 AC 594 ms
63,828 KB
testcase_11 AC 598 ms
63,840 KB
testcase_12 AC 642 ms
63,888 KB
testcase_13 AC 495 ms
63,464 KB
testcase_14 AC 640 ms
65,512 KB
testcase_15 AC 132 ms
57,344 KB
testcase_16 AC 157 ms
58,472 KB
testcase_17 AC 242 ms
62,088 KB
testcase_18 AC 256 ms
63,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)); }
}
0