public override void Solve(IOManager io) { var n = io.ReadInt(); var k = io.ReadInt(); var pows = new ModInt[k + 1][]; pows[0] = new ModInt[n]; pows[0].Fill(ModInt.One); pows[1] = new ModInt[n]; for (int i = 0; i < pows[1].Length; i++) { pows[1][i] = ModInt.Raw(io.ReadInt()); } var combination = new ModCombination <Mod998244353>(300); for (int p = 2; p < pows.Length; p++) { pows[p] = new ModInt[n]; for (int i = 0; i < pows[p].Length; i++) { pows[p][i] = pows[p - 1][i] * pows[1][i]; } } var sums = new ModInt[k + 1]; for (int p = 0; p < pows.Length; p++) { var sum = ModInt.Zero; for (int i = 0; i < pows[p].Length; i++) { sum += pows[p][i]; } sums[p] = sum; } var invTwo = ModInt.Raw(2).Inverse(); for (int x = 1; x < pows.Length; x++) { var result = ModInt.Zero; for (int r = 0; r <= x; r++) { result += combination.Combination(x, r) * sums[r] * sums[x - r]; } var sub = ModInt.Raw(2).Pow(x) * sums[x]; result -= sub; result *= invTwo; io.WriteLine(result); } }
static RerootingTest() { Combination = new ModCombination <Mod1000000007>(); }
public void Test組み合わせ(long m, long n, long expected) { var c = new ModCombination(); Assert.Equal(expected, c.Combination(m, n)); }
public override void Solve(IOManager io) { var n = io.ReadInt(); var threshold = io.ReadInt(); var a = new int[n, n]; var combinaton = new ModCombination <Mod998244353>(100); for (int row = 0; row < n; row++) { for (int column = 0; column < n; column++) { a[row, column] = io.ReadInt(); } } var rowUf = new UnionFind(n); var colUf = new UnionFind(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { var ok = true; for (int column = 0; column < n; column++) { ok &= a[i, column] + a[j, column] <= threshold; } if (ok) { colUf.Unite(i, j); } } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { var ok = true; for (int row = 0; row < n; row++) { ok &= a[row, i] + a[row, j] <= threshold; } if (ok) { rowUf.Unite(i, j); } } } var result = ModInt.One; foreach (var g in colUf.GetAllGroups()) { result *= combinaton.Factorial(g.Length); } foreach (var g in rowUf.GetAllGroups()) { result *= combinaton.Factorial(g.Length); } io.WriteLine(result); }
public ModIntCombinationTest() { _combination = new ModCombination <Mod1000000007>(); }