結果
| 問題 |
No.420 mod2漸化式
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2018-03-17 14:55:07 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 556 bytes |
| コンパイル時間 | 48 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-12-24 00:25:54 |
| 合計ジャッジ時間 | 5,098 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 WA * 4 |
コンパイルメッセージ
Syntax OK
ソースコード
n=gets.to_i
if n==0
puts 0
elsif n>31
puts 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
horiesiniti