結果
| 問題 |
No.1072 A Nice XOR Pair
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2020-06-07 09:29:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 984 bytes |
| コンパイル時間 | 2,440 ms |
| コンパイル使用メモリ | 105,472 KB |
| 実行使用メモリ | 31,744 KB |
| 最終ジャッジ日時 | 2024-12-23 16:16:24 |
| 合計ジャッジ時間 | 4,108 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
}
}
bluemegane