結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー さかぽんさかぽん
提出日時 2021-07-10 22:57:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 1,942 bytes
コンパイル時間 5,058 ms
コンパイル使用メモリ 105,832 KB
実行使用メモリ 35,524 KB
最終ジャッジ日時 2023-09-14 19:59:54
合計ジャッジ時間 14,242 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
28,396 KB
testcase_01 AC 287 ms
26,428 KB
testcase_02 AC 553 ms
31,064 KB
testcase_03 AC 552 ms
35,384 KB
testcase_04 AC 554 ms
33,164 KB
testcase_05 AC 553 ms
31,136 KB
testcase_06 AC 558 ms
33,356 KB
testcase_07 AC 564 ms
35,312 KB
testcase_08 AC 566 ms
33,300 KB
testcase_09 AC 566 ms
33,272 KB
testcase_10 AC 559 ms
33,120 KB
testcase_11 AC 526 ms
35,524 KB
testcase_12 AC 523 ms
35,212 KB
testcase_13 AC 528 ms
33,160 KB
testcase_14 AC 58 ms
20,684 KB
testcase_15 AC 58 ms
20,712 KB
testcase_16 AC 58 ms
20,684 KB
testcase_17 AC 58 ms
20,696 KB
testcase_18 AC 58 ms
20,848 KB
testcase_19 AC 58 ms
20,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static (int t, int x, int y) Read3() { var a = Read(); return (a[0], a[1], a[2]); }
	static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var (n, m) = Read2();
		var ps = Array.ConvertAll(new bool[m], _ => Read3());

		var n2 = 2 * n;
		var mc = new MCombination(n2);
		var r = n2 * mc.MNcr(n2, n) % M;

		foreach (var (t, x, y) in ps)
		{
			if (t == 1)
			{
				r -= mc.MNcr(x + y, x) * mc.MNcr(n2 - x - y - 1, n - y) % M;
			}
			else
			{
				r -= mc.MNcr(x + y, x) * mc.MNcr(n2 - x - y - 1, n - x) % M;
			}
		}

		return MInt(r);
	}

	const long M = 1000000007;
	static long MInt(long x) => (x %= M) < 0 ? x + M : x;
}

public class MCombination
{
	//const long M = 998244353;
	const long M = 1000000007;
	static long MPow(long b, long i)
	{
		long r = 1;
		for (; i != 0; b = b * b % M, i >>= 1) if ((i & 1) != 0) r = r * b % M;
		return r;
	}
	static long MInv(long x) => MPow(x, M - 2);

	static long[] MFactorials(int n)
	{
		var f = new long[n + 1];
		f[0] = 1;
		for (int i = 1; i <= n; ++i) f[i] = f[i - 1] * i % M;
		return f;
	}

	// nPr, nCr を O(1) で求めるため、階乗を O(n) で求めておきます。
	long[] f, f_;
	public MCombination(int nMax)
	{
		f = MFactorials(nMax);
		f_ = Array.ConvertAll(f, MInv);
	}

	public long MFactorial(int n) => f[n];
	public long MInvFactorial(int n) => f_[n];
	public long MNpr(int n, int r) => n < r ? 0 : f[n] * f_[n - r] % M;
	public long MNcr(int n, int r) => n < r ? 0 : f[n] * f_[n - r] % M * f_[r] % M;

	// nMax >= 2n としておく必要があります。
	public long MCatalan(int n) => f[2 * n] * f_[n] % M * f_[n + 1] % M;
}
0