結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Fu_LFu_L
提出日時 2021-07-09 21:51:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 6,482 ms
コンパイル使用メモリ 262,600 KB
実行使用メモリ 7,068 KB
最終ジャッジ日時 2023-09-14 08:43:11
合計ジャッジ時間 7,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,916 KB
testcase_01 AC 10 ms
6,972 KB
testcase_02 AC 76 ms
7,048 KB
testcase_03 AC 77 ms
7,056 KB
testcase_04 AC 77 ms
7,068 KB
testcase_05 AC 75 ms
7,052 KB
testcase_06 AC 74 ms
6,996 KB
testcase_07 AC 75 ms
7,060 KB
testcase_08 AC 74 ms
6,808 KB
testcase_09 AC 75 ms
6,920 KB
testcase_10 AC 72 ms
6,860 KB
testcase_11 AC 59 ms
6,932 KB
testcase_12 AC 59 ms
6,996 KB
testcase_13 AC 59 ms
6,944 KB
testcase_14 AC 10 ms
6,824 KB
testcase_15 AC 9 ms
6,920 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 9 ms
7,048 KB
testcase_18 AC 10 ms
6,932 KB
testcase_19 AC 10 ms
7,048 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