結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー chocoruskchocorusk
提出日時 2021-07-09 21:38:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 3,925 ms
コンパイル使用メモリ 189,112 KB
実行使用メモリ 19,264 KB
最終ジャッジ日時 2023-09-14 08:04:41
合計ジャッジ時間 6,591 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
18,960 KB
testcase_01 AC 12 ms
18,964 KB
testcase_02 AC 156 ms
19,000 KB
testcase_03 AC 156 ms
19,264 KB
testcase_04 AC 155 ms
19,052 KB
testcase_05 AC 154 ms
19,092 KB
testcase_06 AC 154 ms
19,040 KB
testcase_07 AC 155 ms
19,040 KB
testcase_08 AC 158 ms
19,068 KB
testcase_09 AC 159 ms
19,036 KB
testcase_10 AC 158 ms
19,096 KB
testcase_11 AC 145 ms
18,960 KB
testcase_12 AC 144 ms
19,096 KB
testcase_13 AC 143 ms
19,088 KB
testcase_14 AC 8 ms
19,040 KB
testcase_15 AC 7 ms
19,032 KB
testcase_16 AC 8 ms
19,196 KB
testcase_17 AC 7 ms
18,996 KB
testcase_18 AC 7 ms
19,132 KB
testcase_19 AC 7 ms
18,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint1000000007;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int main()
{
    int n, m;
    cin>>n>>m;
    fac(2*n);
    mint ans=mint(2*n)*comb(2*n, n);
    for(int i=0; i<m; i++){
        int t, x, y;
        cin>>t>>x>>y;
        if(t==1){
            mint c=comb(x+y, x)*comb(n-x-1+n-y, n-y);
            ans-=c;
        }else{
            mint c=comb(x+y, x)*comb(n-x-1+n-y, n-x);
            ans-=c;
        }
    }
    cout<<ans.val()<<endl;
    return 0;
}
0