結果
| 問題 |
No.1596 Distance Sum in 2D Plane
|
| コンテスト | |
| ユーザー |
ocvret_
|
| 提出日時 | 2021-07-11 10:25:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 1,391 bytes |
| コンパイル時間 | 1,611 ms |
| コンパイル使用メモリ | 168,788 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-07-02 03:00:40 |
| 合計ジャッジ時間 | 5,239 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
// 2020/12/06 rechecked
class Comb{
public:
const int n;
const int mod = 1000000007;
// const int mod = 998244353;
vector<long long> fac,refac;
Comb(int N) : n(N),fac(N+1,1),refac(N+1,1) {
for(int i = 0;i < n;i++)fac[i+1] = fac[i]*(i+1)%mod;
refac[n] = modpow(fac[n],mod-2);
for(int i = n;i > 0;i--)refac[i-1] = refac[i]*i%mod;
}
long long comb(long long n,long long r){
if(n < r)return 0;
long long res = fac[n]*refac[r]%mod;
res = res*refac[n-r]%mod;
return res;
}
long long modpow(long long n,long long r){
long long res = 1;
while(r){
if(r & 1)res = res*n%mod;
n = n*n%mod;
r >>= 1;
}
return res;
}
};
int main(){
ll n,m;
cin >> n >> m;
Comb cb(2*n);
ll res = 0;
res = (2*n)*cb.comb(2*n,n)%MOD;
rep(i,m){
ll t,x,y;cin >> t >> x >> y;
int nx = n-x,ny = n-y;
if(t == 1)nx--;
else ny--;
res = (res - cb.comb(x+y,x)*cb.comb(nx+ny,nx)%MOD + MOD)%MOD;
}
cout << res << "\n";
return 0;
}
ocvret_