結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー monnumonnu
提出日時 2021-07-09 22:08:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 165,276 KB
実行使用メモリ 27,080 KB
最終ジャッジ日時 2023-09-14 09:15:10
合計ジャッジ時間 4,986 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
26,848 KB
testcase_01 AC 24 ms
27,040 KB
testcase_02 AC 171 ms
26,832 KB
testcase_03 AC 170 ms
26,768 KB
testcase_04 AC 174 ms
26,840 KB
testcase_05 AC 176 ms
26,776 KB
testcase_06 AC 174 ms
26,772 KB
testcase_07 AC 172 ms
26,900 KB
testcase_08 AC 172 ms
26,848 KB
testcase_09 AC 170 ms
27,080 KB
testcase_10 AC 174 ms
26,776 KB
testcase_11 AC 152 ms
26,852 KB
testcase_12 AC 152 ms
26,888 KB
testcase_13 AC 150 ms
26,824 KB
testcase_14 AC 24 ms
26,780 KB
testcase_15 AC 25 ms
26,780 KB
testcase_16 AC 25 ms
26,788 KB
testcase_17 AC 23 ms
26,788 KB
testcase_18 AC 23 ms
26,832 KB
testcase_19 AC 24 ms
26,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
//#define INF 1000000000
#define INF 1000000000000000000

ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;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;
  }
}

ll COM(int n,int k){
  if(n<k){
    return 0;
  }
  if(n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


int main(){
  int N,M;
  cin>>N>>M;
  COMinit();
  ll ans=2*(ll)N*COM(2*N,N)%MOD;
  //cout<<ans<<endl;

  for(int i=0;i<M;i++){
    int t,x,y;
    cin>>t>>x>>y;
    if(t==1){
      ans+=MOD-COM(x+y,x)*COM(2*N-x-y-1,N-y)%MOD;
    }else{
      ans+=MOD-COM(x+y,x)*COM(2*N-x-y-1,N-x)%MOD;
    }
    ans%=MOD;
  }
  cout<<ans<<endl;
}
0