結果

問題 No.390 最長の数列
ユーザー ぴろずぴろず
提出日時 2015-04-12 13:34:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 4,479 ms / 5,000 ms
コード長 293 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 29,696 KB
最終ジャッジ日時 2024-04-10 08:39:59
合計ジャッジ時間 20,198 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 865 ms
20,352 KB
testcase_01 AC 495 ms
20,352 KB
testcase_02 AC 773 ms
20,096 KB
testcase_03 AC 587 ms
20,352 KB
testcase_04 AC 787 ms
20,224 KB
testcase_05 AC 454 ms
29,696 KB
testcase_06 AC 3,572 ms
29,312 KB
testcase_07 AC 510 ms
20,224 KB
testcase_08 AC 233 ms
19,968 KB
testcase_09 AC 514 ms
20,224 KB
testcase_10 AC 836 ms
29,056 KB
testcase_11 AC 882 ms
29,184 KB
testcase_12 AC 850 ms
29,312 KB
testcase_13 AC 1,290 ms
25,600 KB
testcase_14 AC 4,479 ms
29,184 KB
testcase_15 AC 236 ms
20,096 KB
testcase_16 AC 233 ms
19,968 KB
testcase_17 AC 261 ms
20,608 KB
testcase_18 AC 279 ms
20,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

X_MAX = 1000000
n = gets.to_i
x = gets.split.map(&:to_i)
dp = Array.new(X_MAX+1){0}
x.each{|i| dp[i] = 1}
ans = 0
(1..X_MAX).each{|i|
	if (dp[i] <= 0) then
		next
	end
	(i*2..X_MAX).step(i).each{|j|
		if (dp[j] >= 1) then
			dp[j] = [dp[j],dp[i]+1].max
		end
	}
	ans = [ans,dp[i]].max
}
p ans
0