結果

問題 No.1245 ANDORゲーム(calc)
ユーザー semisagisemisagi
提出日時 2020-10-02 22:03:23
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 577 bytes
コンパイル時間 16,548 ms
コンパイル使用メモリ 256,076 KB
実行使用メモリ 12,976 KB
最終ジャッジ日時 2023-09-13 12:05:50
合計ジャッジ時間 22,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,392 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,408 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,380 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 181 ms
12,976 KB
testcase_26 AC 186 ms
12,976 KB
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def get_ints
    read_line.split.map(&.to_i)
end

n, q = get_ints
a = get_ints
s = read_line.chomp.chars
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