結果
| 問題 |
No.1596 Distance Sum in 2D Plane
|
| コンテスト | |
| ユーザー |
MZKi
|
| 提出日時 | 2021-07-09 22:14:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 2,000 ms |
| コード長 | 2,745 bytes |
| コンパイル時間 | 1,352 ms |
| コンパイル使用メモリ | 160,064 KB |
| 実行使用メモリ | 20,136 KB |
| 最終ジャッジ日時 | 2024-07-01 16:48:41 |
| 合計ジャッジ時間 | 5,037 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
struct mint {
ll x;
mint(ll x = 0) :x((x%mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
mint inv() const {
return pow(mod - 2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
bool operator==(const mint a) const {
return x == a.x;
}
bool operator!=(const mint a) const {
return x != a.x;
}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
const int MAX = 710000;
long long fac[MAX], finv[MAX], inv[MAX];
//使う前に実行
//pが素数かつp>nが条件
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod%i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
int n, m;
cin >> n >> m;
COMinit();
mint ans = COM(2*n, n);
ans *= 2*n;
rep(i, m){
int t, x, y;
cin >> t >> x >> y;
if(t == 1){
mint now = 1;
now *= COM(x+y, x);
now *= COM(2*n-x-y-1, n-y);
ans -= now;
}else{
mint now = 1;
now *= COM(x+y, x);
now *= COM(2*n-x-y-1, n-x);
ans -= now;
}
}
cout << ans << endl;
}
MZKi