結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 ygussanyygussany
提出日時 2021-05-11 20:44:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 30,040 KB
実行使用メモリ 8,180 KB
最終ジャッジ日時 2023-09-14 06:56:43
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,072 KB
testcase_01 AC 8 ms
7,964 KB
testcase_02 AC 83 ms
8,088 KB
testcase_03 AC 79 ms
8,180 KB
testcase_04 AC 79 ms
8,076 KB
testcase_05 AC 79 ms
8,008 KB
testcase_06 AC 78 ms
8,072 KB
testcase_07 AC 77 ms
8,124 KB
testcase_08 AC 78 ms
8,052 KB
testcase_09 AC 77 ms
8,104 KB
testcase_10 AC 77 ms
8,060 KB
testcase_11 AC 57 ms
8,060 KB
testcase_12 AC 57 ms
8,116 KB
testcase_13 AC 57 ms
8,032 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;
long long fact[400001], fact_inv[400001];

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}

int main()
{
	int i, N, M;
	scanf("%d %d", &N, &M);
	for (i = 1, fact[0] = 1; i <= N * 2; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N * 2 - 1, fact_inv[N*2] = div_mod(1, fact[N*2], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;

	int t, x, y;
	long long ans = combination(N * 2, N) * N * 2 % Mod;
	for (i = 1; i <= M; i++) {
		scanf("%d %d %d", &t, &x, &y);
		if (t == 1) ans -= combination(x + y, x) * combination(N * 2 - x - y - 1, N - y) % Mod;
		else ans -= combination(x + y, x) * combination(N * 2 - x - y - 1, N - x) % Mod;
	}
	printf("%lld\n", (ans % Mod + Mod) % Mod);
	fflush(stdout);
	return 0;
}
0