結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー bal4ubal4u
提出日時 2021-08-12 07:44:13
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 18:21:31
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,676 KB
testcase_01 AC 8 ms
6,676 KB
testcase_02 AC 29 ms
6,676 KB
testcase_03 AC 28 ms
6,676 KB
testcase_04 AC 27 ms
6,676 KB
testcase_05 AC 27 ms
6,676 KB
testcase_06 AC 28 ms
6,676 KB
testcase_07 AC 27 ms
6,676 KB
testcase_08 AC 26 ms
6,676 KB
testcase_09 AC 26 ms
6,676 KB
testcase_10 AC 28 ms
6,676 KB
testcase_11 AC 18 ms
6,676 KB
testcase_12 AC 18 ms
6,676 KB
testcase_13 AC 18 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:12:28: note: in expansion of macro 'gc'
   12 |         int n = 0; int c = gc();
      |                            ^~
main.c: In function 'out':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:19:17: note: in expansion of macro 'pc'
   19 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yuki 1596 Distance Sum in 2D Plane
// 2021.8.12

#include <stdio.h>

typedef long long ll;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i; char b[30];
	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const int mod = (int)1e9+7;

int fact[400005], inv[400005], factinv[400005];

int comb(int n, int k) {
//	if (n < 0 || k < 0) return 0;
	return (ll)fact[n] * factinv[k] % mod * factinv[n-k] % mod;
}

// テーブルを作る前処理
void COMinit(int max) {
	fact[0] = fact[1] = 1;
	factinv[0] = factinv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i <= max; i++) {
		fact[i] = (ll)fact[i-1] * i % mod;
		inv[i] = mod - (ll)inv[mod%i] * (mod/i) % mod;
		factinv[i] = (ll)factinv[i-1] * inv[i] % mod;
	}
}

int main()
{
	int N = in(), N2 = N << 1;
	COMinit(N2);
	ll ans = comb(N2, N);
	ans = (ans * N2) % mod;

	int M = in();
	while (M--) {
		int t = in(), x = in(), y = in();
		ans -= (ll)comb(x+y, y) * comb(N2-x-y-1, N-y-(t-1)) % mod;
	}
	ans %= mod;
	if (ans < 0) ans += mod;
	out((int)ans);
	return 0;
}
0