結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー 👑 NachiaNachia
提出日時 2021-07-09 22:00:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 151,936 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2023-09-14 09:02:38
合計ジャッジ時間 4,736 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,836 KB
testcase_01 AC 12 ms
7,772 KB
testcase_02 AC 62 ms
7,888 KB
testcase_03 AC 64 ms
7,776 KB
testcase_04 AC 64 ms
7,780 KB
testcase_05 AC 63 ms
7,776 KB
testcase_06 AC 63 ms
7,892 KB
testcase_07 AC 64 ms
7,828 KB
testcase_08 AC 64 ms
7,892 KB
testcase_09 AC 66 ms
7,780 KB
testcase_10 AC 65 ms
7,776 KB
testcase_11 AC 56 ms
7,832 KB
testcase_12 AC 56 ms
7,776 KB
testcase_13 AC 55 ms
7,904 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull MOD = 1000000007;
using mll = static_modint<1000000007>;
#define rep(i,n) for(int i=0; i<(n); i++)


vector<mll> F,I,iF;
void initComb(int Z){
  F.assign(Z+1,1);
  for(int i=1; i<=Z; i++) F[i] = F[i-1] * i;
  I.assign(Z+1,1);
  for(int i=2; i<=Z; i++) I[i] = -(I[MOD%i] * (MOD / i));
  iF.assign(Z+1,1);
  for(int i=1; i<=Z; i++) iF[i] = iF[i-1] * I[i];
}

mll Comb(int n,int r){ return F[n] * iF[r] * iF[n-r]; }

int main(){
  int N,M; cin >> N >> M;
  initComb(N+N);
  mll ans = Comb(N+N,N) * N * 2;
  rep(i,M){
    int t,x,y; cin >> t >> x >> y;
    mll d = 1;
    d *= Comb(x+y,x);
    if(t == 1) d *= Comb(N-x-1+N-y,N-y);
    if(t == 2) d *= Comb(N-x+N-y-1,N-x);
    ans -= d;
  }
  cout << ans.val() << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0