結果

問題 No.390 最長の数列
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-07-16 16:48:26
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 3,775 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 63,704 KB
最終ジャッジ日時 2024-04-23 13:46:37
合計ジャッジ時間 11,286 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
46,028 KB
testcase_01 AC 154 ms
45,644 KB
testcase_02 AC 160 ms
45,920 KB
testcase_03 AC 149 ms
44,984 KB
testcase_04 AC 157 ms
45,780 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 164 ms
45,960 KB
testcase_08 AC 157 ms
45,832 KB
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 155 ms
45,496 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

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=0; i<MAX; i++) {
			if (dp[i] == 0) continue;
			for (int j=i+i; j*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