結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー cai_lwcai_lw
提出日時 2021-07-09 21:53:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 930 bytes
コンパイル時間 1,977 ms
コンパイル使用メモリ 203,600 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-14 08:49:50
合計ジャッジ時間 7,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
5,200 KB
testcase_01 AC 1,135 ms
6,700 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P=1000000007;

int mpow(int x,int n){
  if(n==1)return x;
  ll half=mpow(x,n/2),ret=half*half%P;
  if(n%2)ret=ret*x%P;
  return ret;
}

int inv(int x){
  return mpow(x,P-2);
}

int fac(int n){
  vector<int> cache{1};
  while(cache.size()<=n)
    cache.push_back(1ll*cache.back()*cache.size()%P);
  return cache[n];
}

int ifac(int n){
  vector<int> cache{1};
  while(cache.size()<=n)
    cache.push_back(1ll*cache.back()*inv(cache.size())%P);
  return cache[n];
}

int binom(int n,int m){
  return 1ll*fac(n)*ifac(m)%P*ifac(n-m)%P;
}

int main(){
  int n,m;
  cin>>n>>m;
  int ans=0;
  for(int i=0;i<m;i++){
    int t,x0,y0;
    cin>>t>>x0>>y0;
    int x1=x0,y1=y0;
    if(t==1)x1++;
    else y1++;
    ans+=1ll*binom(x0+y0,x0)*binom(n*2-x1-y1,n-x1)%P;
    if(ans>=P)ans-=P;
  }
  ans=1ll*binom(n*2,n)*n*2%P-ans;
  if(ans<0)ans+=P;
  cout<<ans<<endl;
}
0