結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,052 KB
testcase_01 AC 82 ms
15,148 KB
testcase_02 AC 84 ms
15,416 KB
testcase_03 AC 82 ms
15,316 KB
testcase_04 AC 79 ms
15,272 KB
testcase_05 AC 79 ms
15,300 KB
testcase_06 AC 80 ms
15,152 KB
testcase_07 AC 80 ms
15,076 KB
testcase_08 AC 80 ms
15,428 KB
testcase_09 AC 80 ms
15,536 KB
testcase_10 AC 81 ms
15,092 KB
testcase_11 AC 80 ms
15,080 KB
testcase_12 AC 80 ms
15,236 KB
testcase_13 AC 80 ms
15,048 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

# Here your code !
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.sort.reverse.inject(0) {|s, v|
    (s + dp[v]) % 1000003
}

puts total
0