結果

問題 No.420 mod2漸化式
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 14:56:25
言語 Ruby
(3.3.0)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 564 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 11,564 KB
実行使用メモリ 15,376 KB
最終ジャッジ日時 2023-08-25 15:39:40
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
15,292 KB
testcase_01 AC 78 ms
15,040 KB
testcase_02 AC 72 ms
15,084 KB
testcase_03 AC 72 ms
15,044 KB
testcase_04 AC 70 ms
15,292 KB
testcase_05 AC 72 ms
15,176 KB
testcase_06 AC 71 ms
15,196 KB
testcase_07 AC 72 ms
15,108 KB
testcase_08 AC 72 ms
15,364 KB
testcase_09 AC 71 ms
15,200 KB
testcase_10 AC 73 ms
15,104 KB
testcase_11 AC 72 ms
15,368 KB
testcase_12 AC 72 ms
15,080 KB
testcase_13 AC 74 ms
15,276 KB
testcase_14 AC 72 ms
15,108 KB
testcase_15 AC 74 ms
15,100 KB
testcase_16 AC 73 ms
15,104 KB
testcase_17 AC 73 ms
15,316 KB
testcase_18 AC 75 ms
15,364 KB
testcase_19 AC 77 ms
15,328 KB
testcase_20 AC 77 ms
15,080 KB
testcase_21 AC 73 ms
15,148 KB
testcase_22 AC 73 ms
15,376 KB
testcase_23 AC 72 ms
15,152 KB
testcase_24 AC 74 ms
15,180 KB
testcase_25 AC 73 ms
15,184 KB
testcase_26 AC 74 ms
15,176 KB
testcase_27 AC 74 ms
15,108 KB
testcase_28 AC 74 ms
15,372 KB
testcase_29 AC 73 ms
15,108 KB
testcase_30 AC 74 ms
15,288 KB
testcase_31 AC 74 ms
15,048 KB
testcase_32 AC 77 ms
15,104 KB
testcase_33 AC 71 ms
15,292 KB
testcase_34 AC 71 ms
15,160 KB
testcase_35 AC 71 ms
15,196 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
if n==0
	puts "1 0"
elsif n>31
	puts "0 0"
else
	dp = Array.new(31).map{Array.new(31,0)}
	dp2= Array.new(31).map{Array.new(31,0)}
	ans=0
	r=1
	31.times{|i|
		dp[0][i]=1
		dp2[0][i]=r
		ans+=r
		r*=2
	}
	if n==1
		puts [31 ,ans]*" "
	else
		(n-1).times{|p1|
			r=1
			31.times{|p2|
				r2=r*2
				((p2+1)..(30)).each{|p3|
					dp[p1+1][p3]+=dp[p1][p2]
					dp2[p1+1][p3]+=dp[p1][p2]*r2+dp2[p1][p2]
					r2*=2
				}
				r=r*2
			}
		}
		ans1=dp[n-1].inject{|sum,e|
			sum+e
		}
		ans2=dp2[n-1].inject{|sum,e|
			sum+e
		}
		puts [ans1,ans2]*" "
	end
end
0