結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,616 KB
testcase_01 AC 20 ms
8,656 KB
testcase_02 AC 1,279 ms
9,588 KB
testcase_03 AC 1,384 ms
11,624 KB
testcase_04 AC 1,258 ms
9,440 KB
testcase_05 AC 1,661 ms
11,764 KB
testcase_06 AC 1,648 ms
11,628 KB
testcase_07 AC 1,415 ms
9,224 KB
testcase_08 AC 1,642 ms
11,804 KB
testcase_09 AC 1,370 ms
8,660 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)

        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, digit_value in enumerate(S_bit_digit) if digit_value == len(S)))
            case _:
                raise ValueError


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