結果

問題 No.16 累乗の加算
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-06-03 13:23:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 232 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2023-09-08 11:37:52
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,176 KB
testcase_01 AC 84 ms
15,288 KB
testcase_02 AC 84 ms
15,500 KB
testcase_03 AC 82 ms
15,104 KB
testcase_04 AC 83 ms
15,244 KB
testcase_05 AC 84 ms
15,052 KB
testcase_06 AC 83 ms
15,384 KB
testcase_07 AC 81 ms
15,252 KB
testcase_08 AC 83 ms
15,476 KB
testcase_09 AC 83 ms
15,372 KB
testcase_10 AC 84 ms
15,316 KB
testcase_11 AC 81 ms
15,144 KB
testcase_12 AC 82 ms
15,124 KB
testcase_13 AC 85 ms
15,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

x,n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
dp = Hash.new do |h,k|
    h[k] = (h[(k + 1) / 2] * h[k / 2]) % 1000003
end
dp[0] = 1
dp[1] = x
total = a.sort.reverse.inject(0) {|s, v|
    (s + dp[v]) % 1000003
}

puts total
0