結果

問題 No.1245 ANDORゲーム(calc)
ユーザー semisagisemisagi
提出日時 2020-10-02 21:59:57
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 567 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 11,352 KB
実行使用メモリ 66,552 KB
最終ジャッジ日時 2023-09-24 12:23:04
合計ジャッジ時間 47,145 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,156 KB
testcase_01 AC 83 ms
15,272 KB
testcase_02 AC 81 ms
15,136 KB
testcase_03 AC 82 ms
15,288 KB
testcase_04 AC 85 ms
15,152 KB
testcase_05 AC 82 ms
15,264 KB
testcase_06 AC 82 ms
15,232 KB
testcase_07 AC 150 ms
15,936 KB
testcase_08 AC 102 ms
15,484 KB
testcase_09 AC 142 ms
15,944 KB
testcase_10 AC 137 ms
16,084 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

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