Skip to content

Instantly share code, notes, and snippets.

@sakapon
Created June 3, 2021 00:14
Show Gist options
  • Save sakapon/6b576cd576f0ac72e8d92a992d8e4512 to your computer and use it in GitHub Desktop.
Save sakapon/6b576cd576f0ac72e8d92a992d8e4512 to your computer and use it in GitHub Desktop.
競プロ典型 90 問 / Q046
using System;
using System.Linq;
class Q046
{
const int M = 46;
static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
static void Main()
{
var n = int.Parse(Console.ReadLine());
var r = new bool[3].Select(_ => Read()).Select(Tally).Aggregate(Convolve);
Console.WriteLine(r[0]);
}
static long[] Tally(int[] a)
{
var r = new long[M];
foreach (var x in a) ++r[x % M];
return r;
}
static long[] Convolve(long[] a, long[] b)
{
var r = new long[M];
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++)
r[(i + j) % M] += a[i] * b[j];
return r;
}
}
@sakapon
Copy link
Author

sakapon commented Jun 3, 2021

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