結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー jxkokojxkoko
提出日時 2021-07-27 09:02:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,488 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 166,780 KB
実行使用メモリ 29,376 KB
最終ジャッジ日時 2023-09-30 07:10:50
合計ジャッジ時間 5,538 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
29,132 KB
testcase_01 AC 31 ms
29,100 KB
testcase_02 AC 77 ms
29,264 KB
testcase_03 AC 78 ms
29,272 KB
testcase_04 AC 79 ms
29,108 KB
testcase_05 AC 78 ms
29,108 KB
testcase_06 AC 79 ms
29,224 KB
testcase_07 AC 73 ms
29,220 KB
testcase_08 AC 72 ms
29,128 KB
testcase_09 AC 75 ms
29,160 KB
testcase_10 AC 77 ms
29,376 KB
testcase_11 AC 65 ms
29,128 KB
testcase_12 AC 74 ms
29,112 KB
testcase_13 AC 75 ms
29,140 KB
testcase_14 AC 30 ms
29,144 KB
testcase_15 AC 30 ms
29,344 KB
testcase_16 AC 28 ms
29,200 KB
testcase_17 AC 22 ms
29,152 KB
testcase_18 AC 23 ms
29,132 KB
testcase_19 AC 24 ms
29,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
bool range(int x,int y,int X,int Y){if(0<=x&&x<X&&0<=y&&y<Y){return true;} return false;}
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cerr<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cerr<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cerr<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cerr<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cerr<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define debug_ar(v) do{cerr<<#v": ";for(auto x : v) cerr<<x<<' '; cerr<<endl;}while(0)
#else
#define debug(...)
#define debug_ar(v)
#endif
#pragma endregion
//------------------------------------------------------------------------------------------------------------------------------

const int MAX = 1100000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

ll COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,m;cin>>n>>m;
    COMinit();
    ll tot = (COM(2*n,n)*2*n);
    ll c = 0;
    for(int i = 0; i < m; i++) {
        int t,x,y;cin>>t>>x>>y;
        if(t==1) (c+=(COM(x+y,y)*COM(2*n-x-y-1,n-y))%MOD)%=MOD;
        else (c+=(COM(x+y,y)*COM(2*n-x-y-1,n-x))%MOD)%=MOD;
    }
    cout<<(tot-c+MOD)%MOD<<endl;
}

0