結果

問題 No.390 最長の数列
ユーザー ぴろずぴろず
提出日時 2015-04-12 02:24:38
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,624 ms / 5,000 ms
コード長 701 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 73,768 KB
実行使用メモリ 107,284 KB
最終ジャッジ日時 2023-07-25 16:34:56
合計ジャッジ時間 13,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 195 ms
98,032 KB
testcase_01 AC 181 ms
97,680 KB
testcase_02 AC 190 ms
97,824 KB
testcase_03 AC 181 ms
97,952 KB
testcase_04 AC 193 ms
97,376 KB
testcase_05 AC 613 ms
101,820 KB
testcase_06 AC 1,218 ms
107,172 KB
testcase_07 AC 170 ms
97,964 KB
testcase_08 AC 154 ms
97,388 KB
testcase_09 AC 172 ms
98,060 KB
testcase_10 AC 784 ms
107,152 KB
testcase_11 AC 797 ms
107,284 KB
testcase_12 AC 783 ms
107,180 KB
testcase_13 AC 780 ms
107,068 KB
testcase_14 AC 1,624 ms
106,848 KB
testcase_15 AC 157 ms
97,936 KB
testcase_16 AC 159 ms
97,772 KB
testcase_17 AC 307 ms
100,248 KB
testcase_18 AC 295 ms
99,896 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