結果

問題 No.390 最長の数列
ユーザー ぴろずぴろず
提出日時 2015-04-12 13:15:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 757 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 78,044 KB
実行使用メモリ 71,536 KB
最終ジャッジ日時 2024-04-10 08:37:35
合計ジャッジ時間 8,888 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
60,404 KB
testcase_01 AC 130 ms
60,124 KB
testcase_02 AC 133 ms
60,356 KB
testcase_03 AC 120 ms
59,280 KB
testcase_04 AC 137 ms
60,164 KB
testcase_05 AC 510 ms
67,884 KB
testcase_06 AC 757 ms
71,536 KB
testcase_07 AC 135 ms
60,284 KB
testcase_08 AC 120 ms
59,096 KB
testcase_09 AC 137 ms
60,272 KB
testcase_10 AC 567 ms
68,000 KB
testcase_11 AC 550 ms
68,100 KB
testcase_12 AC 523 ms
68,156 KB
testcase_13 AC 502 ms
66,932 KB
testcase_14 AC 652 ms
71,020 KB
testcase_15 AC 124 ms
60,216 KB
testcase_16 AC 131 ms
60,404 KB
testcase_17 AC 219 ms
63,932 KB
testcase_18 AC 232 ms
64,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package longestsequence;

import java.util.Scanner;

public class Main {
	public static int X_MAX = 2000000;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		for(int i=0;i<n;i++) {
			x[i] = Integer.parseInt(sc.next());
		}
		System.out.println(solve(n,x));
	}

	public static int solve(int n,int[] x) {
		int[] dp = new int[X_MAX+1];
		for(int i:x) {
			dp[i] = 1;
		}
		int ans = 0;
		for(int i=1;i<=X_MAX;i++) {
			if (dp[i] <= 0) {
				continue;
			}
			for(int j=i*2;j<=X_MAX;j+=i) {
				if (dp[j] >= 1) {
					dp[j] = Math.max(dp[j], dp[i] + 1);
				}
			}
			ans = Math.max(ans, dp[i]);
		}
		return ans;
	}

}
0