結果

問題 No.822 Bitwise AND
ユーザー maguroflymagurofly
提出日時 2023-03-16 22:12:53
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 321 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 17,568 KB
最終ジャッジ日時 2023-10-18 13:14:49
合計ジャッジ時間 4,833 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 84 ms
16,076 KB
testcase_03 AC 85 ms
16,076 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 84 ms
16,076 KB
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)

if N == 0
    if K == 0
        puts 1
    else
        puts "INF"
    end
    exit
end

values = (0 ... 1<<18).filter { |x| N & x == N }
M = values.size
ans = 0
(0 ... M).each do |i|
    j_max = (i ... M).bsearch { |j| values[j] - values[i] > K } || M
    ans += j_max - i + 1
end
puts ans
0