結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ransewhaleransewhale
提出日時 2021-07-10 00:47:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 77,736 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-09-14 12:09:39
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
9,808 KB
testcase_01 AC 76 ms
9,868 KB
testcase_02 AC 238 ms
9,788 KB
testcase_03 AC 238 ms
9,772 KB
testcase_04 AC 235 ms
9,804 KB
testcase_05 AC 240 ms
9,940 KB
testcase_06 AC 238 ms
10,016 KB
testcase_07 AC 236 ms
9,744 KB
testcase_08 AC 237 ms
9,808 KB
testcase_09 AC 235 ms
9,732 KB
testcase_10 AC 238 ms
9,776 KB
testcase_11 AC 209 ms
9,812 KB
testcase_12 AC 208 ms
9,840 KB
testcase_13 AC 209 ms
9,744 KB
testcase_14 AC 78 ms
9,752 KB
testcase_15 AC 76 ms
9,840 KB
testcase_16 AC 77 ms
9,772 KB
testcase_17 AC 77 ms
9,832 KB
testcase_18 AC 77 ms
9,720 KB
testcase_19 AC 77 ms
9,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll fc[410410]={1ll},nv[410410]={1ll};

ll rwpw(ll a, ll p = MOD-2){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

ll c(int n, int k){
	ll ret = fc[n];
	mul_mod(ret,nv[k]);
	mul_mod(ret,nv[n-k]);
	return ret;
}

int main(void){
	int n,i,m,t,x,y;
	ll ans,tmp;
	for(i=1; i<410410; ++i){
		fc[i] = fc[i-1]*i%MOD;
		nv[i] = rwpw(fc[i]);
	}
	std::cin >> n >> m;
	ans = c(n*2,n);
	mul_mod(ans,n*2);
	for(i=0; i<m; ++i){
		std::cin >> t >> x >> y; --t;
		tmp = c(x+y,x);
		if(t){
			++y;
		}else{
			++x;
		}
		x = n-x; y = n-y;
		mul_mod(tmp,c(x+y,y));
		add_mod(ans,MOD-tmp);
	}
	std::cout << ans << std::endl;
	return 0;
}
0