結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,040 KB
testcase_01 AC 81 ms
15,040 KB
testcase_02 AC 83 ms
15,532 KB
testcase_03 AC 82 ms
15,148 KB
testcase_04 AC 82 ms
15,016 KB
testcase_05 AC 81 ms
15,076 KB
testcase_06 AC 83 ms
15,100 KB
testcase_07 AC 81 ms
15,056 KB
testcase_08 AC 82 ms
15,596 KB
testcase_09 AC 83 ms
15,308 KB
testcase_10 AC 81 ms
15,132 KB
testcase_11 AC 83 ms
15,188 KB
testcase_12 AC 83 ms
15,064 KB
testcase_13 AC 83 ms
15,108 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|
    if k.odd?
        h[k] = (h[k - 1]) * h[1] % 1000003
    else
        h[k] = (h[k / 2] ** 2) % 1000003
    end
end
dp[0] = 1
dp[1] = x
total = a.inject(0) {|s, v|
    (s + dp[v]) % 1000003
}

puts total
0