結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | ocvret_ |
提出日時 | 2021-07-11 10:25:35 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 1,391 bytes |
コンパイル時間 | 1,523 ms |
コンパイル使用メモリ | 168,096 KB |
実行使用メモリ | 9,532 KB |
最終ジャッジ日時 | 2023-09-14 20:06:45 |
合計ジャッジ時間 | 5,755 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
9,280 KB |
testcase_01 | AC | 19 ms
9,452 KB |
testcase_02 | AC | 191 ms
9,496 KB |
testcase_03 | AC | 198 ms
9,240 KB |
testcase_04 | AC | 201 ms
9,368 KB |
testcase_05 | AC | 201 ms
9,532 KB |
testcase_06 | AC | 200 ms
9,448 KB |
testcase_07 | AC | 201 ms
9,248 KB |
testcase_08 | AC | 199 ms
9,288 KB |
testcase_09 | AC | 202 ms
9,264 KB |
testcase_10 | AC | 199 ms
9,448 KB |
testcase_11 | AC | 159 ms
9,360 KB |
testcase_12 | AC | 159 ms
9,264 KB |
testcase_13 | AC | 159 ms
9,296 KB |
testcase_14 | AC | 1 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,380 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 1 ms
4,380 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 1 ms
4,376 KB |
ソースコード
#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; }