AtCoderのABC
前のABCの問題へ
ABC402-D Line Crossing
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("8 3");
WillReturn.Add("1 5");
WillReturn.Add("1 8");
WillReturn.Add("2 4");
//2
}
else if (InputPattern == "Input2") {
WillReturn.Add("5 10");
WillReturn.Add("2 5");
WillReturn.Add("1 5");
WillReturn.Add("1 2");
WillReturn.Add("2 4");
WillReturn.Add("2 3");
WillReturn.Add("1 3");
WillReturn.Add("1 4");
WillReturn.Add("3 5");
WillReturn.Add("3 4");
WillReturn.Add("4 5");
//40
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
SplitAct(InputList[0]);
long N = wkArr[0];
long M = wkArr[1];
var KatamukiCntDict = new Dictionary<long, long>();
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
long A = wkArr[0];
long B = wkArr[1];
long KatamukiID = (A + B) % N;
if (KatamukiCntDict.ContainsKey(KatamukiID) == false) {
KatamukiCntDict[KatamukiID] = 0;
}
KatamukiCntDict[KatamukiID]++;
}
long Answer = M * (M - 1) / 2;
foreach (long EachCnt in KatamukiCntDict.Values) {
if (EachCnt >= 2) {
Answer -= EachCnt * (EachCnt - 1) / 2;
}
}
Console.WriteLine(Answer);
}
}
解説