結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-16 10:37:56 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 963 ms / 2,000 ms |
コード長 | 1,890 bytes |
コンパイル時間 | 1,028 ms |
コンパイル使用メモリ | 107,008 KB |
実行使用メモリ | 22,912 KB |
最終ジャッジ日時 | 2024-07-05 18:49:53 |
合計ジャッジ時間 | 14,644 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using static System.Math; using System; class Modulo { public const int MOD = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD); public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) m_facs[i] = Mul(m_facs[i - 1], i); } public int Fac(int n) => m_facs[n]; public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2)); public int Ncr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } public class Hello { public static int MOD = Modulo.MOD; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); var md = new Modulo(n + n); long ans = md.Ncr(n + n, n); ans *= n + n; ans %= MOD; for (int i = 0; i < m; i++) { line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var x = int.Parse(line[1]); var y = int.Parse(line[2]); long from = md.Ncr(x + y, x); long to = c == 1 ? md.Ncr(2 * n - x - y - 1, n - y) : md.Ncr(2 * n - x - y - 1, n - x); from *= to; from %= MOD; ans -= from; if (ans < 0) ans += MOD; } Console.WriteLine(ans); } }