結果

問題 No.2300 Substring OR Sum
ユーザー simansiman
提出日時 2023-05-15 18:19:09
言語 Ruby
(3.3.0)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 216 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 31,404 KB
最終ジャッジ日時 2023-08-20 19:11:32
合計ジャッジ時間 10,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
15,148 KB
testcase_01 AC 69 ms
15,272 KB
testcase_02 AC 68 ms
15,088 KB
testcase_03 AC 269 ms
18,704 KB
testcase_04 AC 229 ms
18,388 KB
testcase_05 AC 275 ms
19,164 KB
testcase_06 AC 173 ms
17,016 KB
testcase_07 AC 790 ms
31,116 KB
testcase_08 AC 354 ms
20,496 KB
testcase_09 AC 295 ms
19,416 KB
testcase_10 AC 598 ms
25,124 KB
testcase_11 AC 692 ms
26,820 KB
testcase_12 AC 834 ms
31,356 KB
testcase_13 AC 783 ms
31,404 KB
testcase_14 AC 734 ms
26,988 KB
testcase_15 AC 366 ms
20,756 KB
testcase_16 AC 597 ms
24,824 KB
testcase_17 AC 783 ms
31,136 KB
testcase_18 AC 70 ms
15,260 KB
testcase_19 AC 68 ms
15,040 KB
testcase_20 AC 68 ms
15,120 KB
testcase_21 AC 68 ms
15,160 KB
testcase_22 AC 68 ms
15,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

ans = 0

30.times do |i|
  base = 2 ** i
  last = 0

  A.each.with_index(1) do |a, idx|
    if a[i] == 1
      last = idx
    end

    ans += base * last
  end
end

puts ans
0