結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー hangin-svghangin-svg
提出日時 2021-07-10 02:25:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 945 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 165,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 14:03:16
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 10 ms
4,376 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;
typedef unsigned long long ull;
const ll mod = 1000000007;

ll powmod(ll n,int m){
  if(n==0) return 0;
  if(m==0 || n==1) return 1;
  if(m%2) return powmod(n*n %mod, m/2) *n %mod;
  else    return powmod(n*n %mod, m/2);
}

ll comb(int n,int m){
  if(m>n || m<0) return 0;
  m = min(n-m,m);
  if(m==0) return 1;
  ll mul = 1, div = 1;
  while(m>0){
    (mul *= n) %= mod;
    (div *= m) %= mod;
    n--;
    m--;
  }
  return mul * powmod(div,mod-2) %mod;
}


int main(){

  int n,m;
  cin >> n >> m;
  ll ans = comb(2*n,n) * 2*n %mod;
  ll minus = 0;
  for(int i=0; i<m; ++i) {
    int t,x,y;
    cin >> t >> x >> y;
    //cout << x << ' ' << y << endl;
    //cout << comb(x+y,x) << ' ' << comb(2*n-x-y-1, t==1 ? n-y : n-x) << endl;
    minus += (ll)comb(x+y,x) * comb(2*n-x-y-1, t==1 ? n-y : n-x) %mod;
    minus %= mod;
  }

  cout << (ans + mod - minus) % mod << endl;


}
0