結果

問題 No.2195 AND Set
ユーザー ThetaTheta
提出日時 2023-01-27 13:53:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,252 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 17,128 KB
最終ジャッジ日時 2023-09-10 09:20:49
合計ジャッジ時間 27,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,508 KB
testcase_01 AC 19 ms
8,676 KB
testcase_02 AC 1,272 ms
9,604 KB
testcase_03 AC 1,397 ms
11,752 KB
testcase_04 AC 1,254 ms
9,600 KB
testcase_05 AC 1,670 ms
11,652 KB
testcase_06 AC 1,676 ms
11,612 KB
testcase_07 AC 1,403 ms
9,360 KB
testcase_08 AC 1,628 ms
11,576 KB
testcase_09 AC 1,358 ms
8,584 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def main():
    S = set()
    S_bit_digit = defaultdict(int)

    for _ in range(int(input())):
        query = input().split()
        if len(query) == 1:
            query_type = 3
        else:
            query_type, x = map(int, query)

        match query_type:
            case 1:
                if x in S:
                    continue
                S.add(x)

                digit_idx = 0
                while x > 0:
                    if x & 1:
                        S_bit_digit[digit_idx] += 1
                    x >>= 1
                    digit_idx += 1

            case 2:
                if x not in S:
                    continue
                S.remove(x)

                digit_idx = 0
                while x > 0:
                    if x & 1:
                        S_bit_digit[digit_idx] -= 1
                    x >>= 1
                    digit_idx += 1
            case 3:
                if not S:
                    print(-1)
                else:
                    print(
                        sum(2**digit_idx for digit_idx in S_bit_digit if S_bit_digit[digit_idx] == len(S)))
            case _:
                raise ValueError


if __name__ == "__main__":
    main()
0