結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ironairona
提出日時 2021-07-10 09:44:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 3,823 ms
コンパイル使用メモリ 227,876 KB
実行使用メモリ 6,416 KB
最終ジャッジ日時 2023-09-14 18:45:11
合計ジャッジ時間 10,551 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,212 KB
testcase_01 AC 12 ms
6,416 KB
testcase_02 AC 440 ms
6,092 KB
testcase_03 AC 435 ms
6,256 KB
testcase_04 AC 455 ms
6,124 KB
testcase_05 AC 449 ms
6,084 KB
testcase_06 AC 448 ms
6,412 KB
testcase_07 AC 451 ms
6,104 KB
testcase_08 AC 446 ms
6,116 KB
testcase_09 AC 439 ms
6,152 KB
testcase_10 AC 436 ms
6,260 KB
testcase_11 AC 394 ms
6,168 KB
testcase_12 AC 395 ms
6,204 KB
testcase_13 AC 393 ms
6,152 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 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>
#define pll pair<ll,ll>
#define count __builtin_popcountll

using namespace std;
using namespace atcoder;
using mint = modint1000000007;

const ll mod=1000000007;//998244353;
const ll inf=1000000000000000000;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

void modsum(ll &a,ll b,ll m){
  a+=b;
  a%=m;
}

void modsub(ll &a,ll b,ll m){
  a-=b;
  a+=m;
  a%=m;
}

void modmul(ll &a,ll b,ll m){
  a*=b;
  a%=m;
}

void modquo(ll &a,ll b,ll m){
  a*=modinv(b,m);
  a%=m;
}

int main(){
  cout << fixed << setprecision(15);

  ll n,m;
  cin >> n >> m;

  mint ans=0;
  ans=combmod(2*n,n,mod);
  ans*=(2*n);

  vector<ll> f(2*n+1);
  f[0]=1;
  for(ll i=1;i<2*n+1;i++){
    f[i]=f[i-1]*i%mod;
  }


  for(ll i=0;i<m;i++){
    ll t,x,y;
    cin >> t >> x >> y;
    mint ret=1;
    ret*=f[x+y];
    ret*=modinv(f[x],mod);
    ret*=modinv(f[y],mod);
    ret*=f[2*n-x-y-1];    
    if(t==1){
      ret*=modinv(f[n-x-1],mod);
      ret*=modinv(f[n-y],mod);
    }
    else{
      ret*=modinv(f[n-x],mod);
      ret*=modinv(f[n-y-1],mod);
    }
    ans-=ret;
  }

  cout << ans.val() << endl;

  return 0;
}
0