結果

問題 No.1072 A Nice XOR Pair
ユーザー bluemeganebluemegane
提出日時 2020-06-07 09:13:23
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,133 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 63,212 KB
実行使用メモリ 45,016 KB
最終ジャッジ日時 2023-08-25 04:00:07
合計ジャッジ時間 6,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
28,032 KB
testcase_01 AC 61 ms
21,536 KB
testcase_02 AC 60 ms
21,660 KB
testcase_03 AC 61 ms
21,496 KB
testcase_04 AC 58 ms
20,856 KB
testcase_05 AC 62 ms
23,628 KB
testcase_06 AC 69 ms
21,660 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
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]);
        var a = new int[n];
        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;
        var a = d.ToArray();
        var aL = a.Length;
        for (int i = 0; i < aL - 1; i++)
            for (int j = i + 1; j < aL; j++)
                if ((a[i].Key ^ a[j].Key) == x)
                    res += (long)a[i].Value * a[j].Value;
        return res;
    }
    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