結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー bayashikobayashiko
提出日時 2021-07-09 21:41:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,569 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 201,520 KB
実行使用メモリ 15,572 KB
最終ジャッジ日時 2023-09-14 08:12:37
合計ジャッジ時間 4,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,360 KB
testcase_01 AC 14 ms
15,316 KB
testcase_02 AC 81 ms
15,312 KB
testcase_03 AC 81 ms
15,368 KB
testcase_04 AC 82 ms
15,404 KB
testcase_05 AC 82 ms
15,320 KB
testcase_06 AC 82 ms
15,404 KB
testcase_07 AC 80 ms
15,572 KB
testcase_08 AC 79 ms
15,420 KB
testcase_09 AC 81 ms
15,348 KB
testcase_10 AC 79 ms
15,360 KB
testcase_11 AC 59 ms
15,420 KB
testcase_12 AC 58 ms
15,324 KB
testcase_13 AC 58 ms
15,320 KB
testcase_14 AC 14 ms
15,312 KB
testcase_15 AC 13 ms
15,552 KB
testcase_16 AC 14 ms
15,356 KB
testcase_17 AC 14 ms
15,304 KB
testcase_18 AC 14 ms
15,360 KB
testcase_19 AC 14 ms
15,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

lint fac[510000],finv[510000],inv[510000];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<510000;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;
    }
}
lint COM(lint n,lint k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
lint facdiv(lint n,lint k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return (fac[n]*finv[k])%MOD;
}

lint bigN(lint n,lint r){
    if(n<r) return 0;
    if(n<0 || r<0) return 0;
    lint ans=1;
    for(lint i=n;i>n-r;i--) ans=(ans*i)%MOD;
    return (ans*finv[r])%MOD;
}

// COMinit();でテーブル準備を行うこと

int main(void){
    COMinit();
    lint N,M;
    cin >> N >> M;
    lint ans=COM(2*N,N)*N*2;
    ans%=MOD;
    lint minus=0;
    rep(i,M){
        int t,x,y;
        cin >> t >> x >> y;
        int sx=x,sy=y,gx=x,gy=y;
        if(t==1){
            gx++;
            minus+=(COM(sx+sy,sx)*COM(2*N-gx-gy,N-gx));
            minus%=MOD;
        }
        else{
            gy++;
            minus+=(COM(sx+sy,sx)*COM(2*N-gx-gy,N-gx));
            minus%=MOD;
        }
    }
    cout << (ans-minus+MOD)%MOD << endl;
}
0