結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Ryushi-techRyushi-tech
提出日時 2021-07-21 08:12:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 4,047 ms
コンパイル使用メモリ 262,040 KB
実行使用メモリ 6,252 KB
最終ジャッジ日時 2023-09-24 13:01:29
合計ジャッジ時間 5,997 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,140 KB
testcase_01 AC 7 ms
6,140 KB
testcase_02 AC 61 ms
6,140 KB
testcase_03 AC 61 ms
5,984 KB
testcase_04 AC 59 ms
6,096 KB
testcase_05 AC 60 ms
6,016 KB
testcase_06 AC 56 ms
5,992 KB
testcase_07 AC 58 ms
5,980 KB
testcase_08 AC 57 ms
6,144 KB
testcase_09 AC 57 ms
6,136 KB
testcase_10 AC 57 ms
5,992 KB
testcase_11 AC 52 ms
6,208 KB
testcase_12 AC 52 ms
6,088 KB
testcase_13 AC 52 ms
6,144 KB
testcase_14 AC 8 ms
5,984 KB
testcase_15 AC 7 ms
6,252 KB
testcase_16 AC 8 ms
6,004 KB
testcase_17 AC 7 ms
6,148 KB
testcase_18 AC 7 ms
6,144 KB
testcase_19 AC 7 ms
6,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define cnts(x,c) count(all(x),c)
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) {a = b; return 1;} return 0;}
template<class T> void print(const T &t) {cout<<t<<"\n";}
template<class T> void PRINT(const T &t) {rep(i,sz(t)) cout<<t[i]<<" \n"[i==sz(t)-1];}
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

#include<atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using vm = vector<mint>;

int max_n=4e5+200;
vm fact(max_n+1,1),inv(max_n+1,1);

void init() {
    rep1(i,max_n) fact[i]=i*fact[i-1];
    inv[max_n]=fact[max_n].inv();
    rrep1(i,max_n) inv[i-1]=i*inv[i];
}

mint nCr(int a,int b){
    if(fact[2]==1) init();
    if(a<b||a<0||b<0) return 0;
    return fact[a]*inv[b]*inv[a-b];
}

int n,q,t,x,y;

int main() {
    fio(); cin>>n>>q;
    mint ans=2*n*nCr(2*n,n);
    rep(i,q){
        cin>>t>>x>>y;
        if(t==1) ans-=nCr(x+y,x)*nCr(n-x+n-y-1,n-x-1);
        else ans-=nCr(x+y,x)*nCr(n-x+n-y-1,n-y-1);
    }
   print(ans.val());
}
0