結果
| 問題 | No.1596 Distance Sum in 2D Plane | 
| コンテスト | |
| ユーザー |  bal4u | 
| 提出日時 | 2021-08-12 07:44:13 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 1,322 bytes | 
| コンパイル時間 | 986 ms | 
| コンパイル使用メモリ | 31,104 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-01 10:05:33 | 
| 合計ジャッジ時間 | 2,930 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
コンパイルメッセージ
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');
      |                 ^~
            
            ソースコード
// 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;
}
            
            
            
        