結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー hangin-svghangin-svg
提出日時 2021-07-10 02:32:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 169,436 KB
実行使用メモリ 6,300 KB
最終ジャッジ日時 2023-09-14 14:11:34
合計ジャッジ時間 5,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,092 KB
testcase_01 AC 6 ms
6,108 KB
testcase_02 AC 251 ms
6,132 KB
testcase_03 AC 255 ms
6,124 KB
testcase_04 AC 252 ms
6,280 KB
testcase_05 AC 255 ms
6,200 KB
testcase_06 AC 252 ms
6,136 KB
testcase_07 AC 254 ms
6,148 KB
testcase_08 AC 252 ms
6,280 KB
testcase_09 AC 249 ms
6,148 KB
testcase_10 AC 248 ms
6,300 KB
testcase_11 AC 223 ms
6,044 KB
testcase_12 AC 221 ms
6,192 KB
testcase_13 AC 221 ms
6,004 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<ll> factorial;

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 = factorial[n], div = factorial[m] * factorial[n-m] %mod;
  return mul * powmod(div,mod-2) %mod;
}


int main(){

  int n,m;
  cin >> n >> m;

  factorial.resize(2*n+1,1);
  for(int i=1; i<=2*n; ++i) {
    factorial[i]= factorial[i-1] * i % mod;
  }

  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