public void Solve() { int N = Reader.Int(); var table = Reader.IntTable(N); int MaxVal = table.Max(t => Math.Max(t[0], t[1])); var dp = new int[MaxVal * 2 + 2, MaxVal * 2 + 2]; foreach (var t in table) { dp[MaxVal - t[0], MaxVal - t[1]]++; } for (int a = 0; a <= MaxVal * 2; a++) { for (int b = 0; b <= MaxVal * 2; b++) { Add(ref dp[a + 1, b], dp[a, b]); Add(ref dp[a, b + 1], dp[a, b]); } } var C = new ModC(MaxVal * 4, Mod); long ans = 0; foreach (var t in table) { ans += dp[t[0] + MaxVal, t[1] + MaxVal]; ans -= C[(t[0] + t[1]) * 2, t[0] * 2]; } ans = (ans % Mod * ModPower(2, Mod - 2, Mod) % Mod + Mod) % Mod; Console.WriteLine(ans); }
public void Solve() { int A = Reader.Int(), B = Reader.Int(), C = Reader.Int(); if (B > C) { int t = B; B = C; C = t; } long ans = 0; var Comb = new ModC(A + B + C, Mod); long BCcomb = 1; for (int S = A - 1; S <= A - 1 + B + C; S++) { long count = Comb[S, A - 1]; ans = (ans + count * BCcomb % Mod * ModPower(3, A + B + C - S - 1, Mod)) % Mod; BCcomb = BCcomb * 2 % Mod; int rem = S - A + 1; if (rem >= B) { BCcomb = (BCcomb + Mod - Comb[rem, B]) % Mod; } if (rem >= C) { BCcomb = (BCcomb + Mod - Comb[rem, rem - C]) % Mod; } } Console.WriteLine(ans); }
public void Solve() { int H = Reader.Int(), W = Reader.Int(), A = Reader.Int(), B = Reader.Int(); var C = new ModC(H + W, Mod); int ans = 0; long last = 0; for (int x = B; x < W; x++) { int h1 = H - A - 1; int w1 = x; int h2 = A; int w2 = W - x - 1; long a = C[h1 + w1, w1], b = C[h2 + w2, w2]; if (last > 0) { a = a + Mod - last; } last = C[h1 + w1, w1]; Add(ref ans, (int)(a * b % Mod)); } Console.WriteLine(ans); }
public void Solve() { int A = Reader.Int(), B = Reader.Int(), C = Reader.Int(); if (B > C) { int t = B; B = C; C = t; } long ans = 0; var Comb = new ModC(A + B + C, Mod); var pow3 = new long[A + B + C]; pow3[0] = 1; for (int i = 1; i < pow3.Length; i++) { pow3[i] = pow3[i - 1] * 3 % Mod; } long BCcomb = 1; for (int S = A - 1; S <= A - 1 + B + C; S++) { ans = (ans + Comb[S, A - 1] * BCcomb % Mod * pow3[A + B + C - S - 1]) % Mod; BCcomb = BCcomb * 2 % Mod; int rem = S - A + 1; if (rem >= B) { BCcomb = (BCcomb + Mod - Comb[rem, B]) % Mod; } if (rem >= C) { BCcomb = (BCcomb + Mod - Comb[rem, rem - C]) % Mod; } } Console.WriteLine(ans); }
public void Solve() { int N = Reader.Int(), X = Reader.Int(), Y = Reader.Int(); var dic = new Dictionary <int, List <int> >(); int[] C = new int[N], W = new int[N]; for (int i = 0; i < N; i++) { C[i] = Reader.Int(); W[i] = Reader.Int(); AddDic(dic, C[i], i); } if (dic.Count == 1) { Console.WriteLine(1); return; } var mins = new List <int>(); var uf = new UnionFind(N); foreach (var A in dic.Values) { int minW = int.MaxValue, who = 0; foreach (int i in A) { if (CheckMin(ref minW, W[i])) { who = i; } } mins.Add(who); foreach (int i in A) { if (minW + W[i] <= X) { uf.Unite(who, i); } } } mins = mins.OrderBy(i => W[i]).ToList(); foreach (var A in dic.Values) { for (int mi = 0; mi < 2; mi++) { if (C[mins[mi]] != C[A[0]]) { foreach (int i in A) { if (W[mins[mi]] + W[i] <= Y) { uf.Unite(mins[mi], i); } } } } } long ans = 1; modC = new ModC(N, Mod); foreach (var A in uf.Components().Values) { var count = new Dictionary <int, List <int> >(); foreach (int i in A) { AddDic(count, C[i], 1); } ans *= Count(count.Values.Select(v => v.Count).ToArray()); ans %= Mod; } Console.WriteLine(ans); }