結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,180 KB
testcase_01 AC 86 ms
15,148 KB
testcase_02 AC 83 ms
15,416 KB
testcase_03 AC 81 ms
15,328 KB
testcase_04 AC 82 ms
15,092 KB
testcase_05 AC 84 ms
15,312 KB
testcase_06 AC 83 ms
15,364 KB
testcase_07 AC 84 ms
15,096 KB
testcase_08 AC 83 ms
15,424 KB
testcase_09 AC 83 ms
15,440 KB
testcase_10 AC 82 ms
15,296 KB
testcase_11 AC 84 ms
15,244 KB
testcase_12 AC 86 ms
15,172 KB
testcase_13 AC 85 ms
15,044 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 {|a,b| b <=> a}.inject(0) {|s, v|
    (s + dp[v]) % 1000003
}

puts total
0