結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Fu_LFu_L
提出日時 2021-07-09 21:51:41
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 3,889 ms
使用メモリ 7,020 KB
最終ジャッジ日時 2023-02-01 23:06:18
合計ジャッジ時間 6,221 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 9 ms
6,996 KB
testcase_01 AC 9 ms
6,892 KB
testcase_02 AC 60 ms
6,884 KB
testcase_03 AC 60 ms
6,844 KB
testcase_04 AC 60 ms
6,980 KB
testcase_05 AC 59 ms
6,900 KB
testcase_06 AC 60 ms
7,020 KB
testcase_07 AC 60 ms
7,012 KB
testcase_08 AC 59 ms
6,996 KB
testcase_09 AC 59 ms
6,892 KB
testcase_10 AC 57 ms
6,848 KB
testcase_11 AC 50 ms
6,840 KB
testcase_12 AC 51 ms
6,972 KB
testcase_13 AC 51 ms
6,872 KB
testcase_14 AC 10 ms
6,868 KB
testcase_15 AC 9 ms
6,876 KB
testcase_16 AC 10 ms
6,972 KB
testcase_17 AC 9 ms
6,848 KB
testcase_18 AC 9 ms
6,856 KB
testcase_19 AC 9 ms
6,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
typedef modint1000000007 mint;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
const ll inf=1e18;
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
} comb(500005);
ll n,m;
ll t,x,y;
mint ans;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>m;
    ans=2*mint(n)*comb(2*n,n);
    rep(i,0,m){
        cin>>t>>x>>y;
        if(t==1){
            ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-y);
        }else{
            ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-x);
        }
    }
    cout<<ans.val()<<endl;
}
0