Skip to content

Instantly share code, notes, and snippets.

@aiwas
Last active June 19, 2021 13:58
Show Gist options
  • Save aiwas/73b90431bccfa6150ca0f694e217fecd to your computer and use it in GitHub Desktop.
Save aiwas/73b90431bccfa6150ca0f694e217fecd to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
var d = new Dictionary<int, int>();
foreach (int ax in a) {
if (d.ContainsKey(ax)) {
d[ax] += 1;
} else {
d.Add(ax, 1);
}
}
long dup = 0;
foreach ((_, int count) in d) {
if (count > 1) {
dup += (count * (count - 1) / 2);
}
}
long all = n * (n - 1) / 2;
Console.WriteLine(all - dup);
}
}
@aiwas
Copy link
Author

aiwas commented Jun 19, 2021

7/14しか通らないが原因がわからない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment