結果

問題 No.2195 AND Set
ユーザー bluemeganebluemegane
提出日時 2023-01-21 07:07:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 1,065 ms
コンパイル使用メモリ 65,360 KB
実行使用メモリ 34,136 KB
最終ジャッジ日時 2023-09-05 22:03:47
合計ジャッジ時間 11,143 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
22,312 KB
testcase_01 AC 62 ms
22,276 KB
testcase_02 AC 485 ms
26,764 KB
testcase_03 AC 505 ms
27,100 KB
testcase_04 AC 486 ms
26,560 KB
testcase_05 AC 683 ms
25,180 KB
testcase_06 AC 697 ms
25,028 KB
testcase_07 AC 673 ms
26,560 KB
testcase_08 AC 697 ms
27,152 KB
testcase_09 AC 673 ms
26,568 KB
testcase_10 AC 647 ms
32,200 KB
testcase_11 AC 638 ms
30,132 KB
testcase_12 AC 643 ms
34,136 KB
testcase_13 AC 638 ms
32,152 KB
testcase_14 AC 639 ms
30,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        var q = int.Parse(Console.ReadLine().Trim());
        getAns(q);
    }
    static void getAns(int q)
    {
        var b = new int[30];
        var hs = new HashSet<int>();
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "1")
            {
                var x = int.Parse(line[1]);
                if (hs.Add(x))
                {
                    for (int j = 0; j < 30; j++)
                    {
                        if (((x >> j) & 1) == 1) b[j]++;
                    }
                }
            }
            else if (line[0] == "2")
            {
                var x = int.Parse(line[1]);
                if (hs.Remove(x))
                {
                    for (int j = 0; j < 30; j++)
                    {
                        if (((x >> j) & 1) == 1) b[j]--;
                    }
                }
            }
            else
            {
                var hsc = hs.Count;
                if (hsc == 0) { Console.WriteLine(-1); continue; }
                var ans = 0;
                for (int j = 0; j < 30; j++)
                {
                    if (b[j] == hsc) ans |= 1 << j;
                }
                Console.WriteLine(ans);
            }
        }
    }
}
0