結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー JiKuaiJiKuai
提出日時 2021-07-09 22:17:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 2,041 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 200,096 KB
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-09-14 09:32:25
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,264 KB
testcase_01 AC 5 ms
6,104 KB
testcase_02 AC 179 ms
6,140 KB
testcase_03 AC 176 ms
6,164 KB
testcase_04 AC 176 ms
6,328 KB
testcase_05 AC 179 ms
6,288 KB
testcase_06 AC 179 ms
6,192 KB
testcase_07 AC 182 ms
6,132 KB
testcase_08 AC 179 ms
6,264 KB
testcase_09 AC 180 ms
6,176 KB
testcase_10 AC 183 ms
6,132 KB
testcase_11 AC 159 ms
6,208 KB
testcase_12 AC 158 ms
6,196 KB
testcase_13 AC 157 ms
6,228 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() { EmiliaMyWife
	int n, m;
	cin >> n >> m;
	vector<ll> fac(n * 2 + 3, 1);
	for(int i = 1; i <= n * 2 + 2; i++)
		fac[i] = fac[i - 1] * i % MOD;
	auto mpow = [&](ll a, int b) {
		ll res = 1;
		for(; b; b >>= 1, a = a * a % MOD)
			if(b & 1)
				res = res * a % MOD;
		return res;
	};
	auto cnm = [&](int n, int m) {
		if(n < m)
			return ll(0);
		return fac[n] * mpow(fac[m], MOD - 2) % MOD * mpow(fac[n - m], MOD - 2) % MOD;
	};
	auto cal = [&](int a, int b) { return cnm(a + b, a); };
	ll ans = cal(n, n) * n * 2 % MOD;
	//debug(ans);
	while(m--) {
		int t, x, y;
		cin >> t >> x >> y;
		int dx = x, dy = y;
		if(t == 1)
			dx++;
		else
			dy++;
		ans = (ans - cal(x, y) * cal(n - dx, n - dy) % MOD + MOD) % MOD;
	}
	
	cout << ans << '\n';
}
0