結果

問題 No.390 最長の数列
ユーザー ぴろずぴろず
提出日時 2015-04-12 02:24:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,847 ms / 5,000 ms
コード長 701 bytes
コンパイル時間 3,724 ms
コンパイル使用メモリ 77,284 KB
実行使用メモリ 106,580 KB
最終ジャッジ日時 2024-04-10 08:33:19
合計ジャッジ時間 14,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 211 ms
95,956 KB
testcase_01 AC 200 ms
96,020 KB
testcase_02 AC 205 ms
96,168 KB
testcase_03 AC 198 ms
96,036 KB
testcase_04 AC 207 ms
96,132 KB
testcase_05 AC 630 ms
99,024 KB
testcase_06 AC 1,467 ms
106,368 KB
testcase_07 AC 187 ms
96,424 KB
testcase_08 AC 175 ms
95,972 KB
testcase_09 AC 203 ms
95,996 KB
testcase_10 AC 872 ms
106,200 KB
testcase_11 AC 960 ms
106,512 KB
testcase_12 AC 923 ms
104,996 KB
testcase_13 AC 861 ms
106,144 KB
testcase_14 AC 1,847 ms
106,580 KB
testcase_15 AC 172 ms
96,064 KB
testcase_16 AC 188 ms
96,088 KB
testcase_17 AC 341 ms
97,964 KB
testcase_18 AC 340 ms
98,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package longestsequence;

import java.util.Scanner;

public class Main {
	public static int X_MAX = 10000000;
	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