結果

問題 No.2195 AND Set
ユーザー ThetaTheta
提出日時 2023-01-27 15:11:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,259 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 17,140 KB
最終ジャッジ日時 2023-09-10 10:13:59
合計ジャッジ時間 24,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,504 KB
testcase_01 AC 19 ms
8,516 KB
testcase_02 AC 1,228 ms
9,476 KB
testcase_03 AC 1,416 ms
11,640 KB
testcase_04 AC 1,264 ms
9,600 KB
testcase_05 AC 1,634 ms
11,708 KB
testcase_06 AC 1,680 ms
11,640 KB
testcase_07 AC 1,455 ms
9,344 KB
testcase_08 AC 1,611 ms
11,580 KB
testcase_09 AC 1,401 ms
8,800 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 = [0 for _ in range(30)]

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

        if query_type == 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

        elif query_type == 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
        elif query_type == 3:
            if not S:
                print(-1)
            else:
                bitwise_ = 0
                for digit_idx, digit_value in enumerate(S_bit_digit):
                    if digit_value == len(S):
                        bitwise_ += 2 ** digit_idx
                print(bitwise_)
        else:
            raise ValueError


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