結果

問題 No.1245 ANDORゲーム(calc)
ユーザー semisagisemisagi
提出日時 2020-10-02 21:57:45
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 561 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 22,452 KB
最終ジャッジ日時 2023-09-24 12:15:33
合計ジャッジ時間 6,282 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
22,452 KB
testcase_01 AC 84 ms
15,024 KB
testcase_02 AC 83 ms
15,292 KB
testcase_03 AC 84 ms
15,092 KB
testcase_04 AC 84 ms
15,048 KB
testcase_05 AC 83 ms
15,284 KB
testcase_06 AC 84 ms
15,140 KB
testcase_07 AC 171 ms
15,888 KB
testcase_08 AC 108 ms
15,712 KB
testcase_09 AC 161 ms
15,928 KB
testcase_10 AC 154 ms
16,352 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def get_ints
    gets.split.map(&:to_i)
end

n, q = get_ints
a = get_ints
s = gets.chomp
t = get_ints

cost = Array.new(2) { [0] * 30 }

(0 ... 2).each do |i|
    (0 ... 30).each do |j|
        x = i
        (0 ... n).each do |k|
            if s[k] == '0'
                y = x & (a[k] >> j & 1)
            else
                y = x | (a[k] >> j & 1)
            end
            cost[i][j] += (y - x).abs << j
            x = y
        end
    end
end

(0 ... q).each do |i|
    answer = (0 ... 30).map { |j| cost[t[i] >> j & 1][j] }.sum
    puts answer
end
0