結果

問題 No.1072 A Nice XOR Pair
ユーザー bluemeganebluemegane
提出日時 2020-06-07 09:29:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 65,460 KB
実行使用メモリ 37,340 KB
最終ジャッジ日時 2023-08-25 04:02:12
合計ジャッジ時間 3,342 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
20,704 KB
testcase_01 AC 59 ms
18,628 KB
testcase_02 AC 59 ms
22,704 KB
testcase_03 AC 58 ms
20,836 KB
testcase_04 AC 58 ms
20,836 KB
testcase_05 AC 60 ms
22,724 KB
testcase_06 AC 60 ms
20,680 KB
testcase_07 AC 194 ms
37,340 KB
testcase_08 AC 148 ms
26,792 KB
testcase_09 AC 148 ms
26,856 KB
testcase_10 AC 152 ms
26,764 KB
testcase_11 AC 155 ms
29,268 KB
testcase_12 AC 174 ms
36,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        var d = new Dictionary<int, int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var x = int.Parse(line[1]);
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(Console.ReadLine().Trim());
            if (d.ContainsKey(w)) d[w]++;
            else d[w] = 1;
        }
        Console.WriteLine(x == 0 ? case0(d) : caseNz(x, d));
    }
    static long caseNz(int x, Dictionary<int, int> d)
    {
        var res = 0L;
        foreach(var y in d)
        {
            var t = y.Key ^ x;
            if (d.ContainsKey(t)) res += (long)y.Value * d[t];
        }
        return res / 2;
    }
    static long case0(Dictionary<int, int> d)
    {
        var res = 0L;
        foreach (var x in d)
            if (x.Value >= 2) res += (long)x.Value * (x.Value - 1) / 2;
        return res;
    }
}
0