結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー JupytorJupytor
提出日時 2021-07-09 23:42:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 2,450 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 91,352 KB
実行使用メモリ 12,852 KB
最終ジャッジ日時 2023-09-14 11:02:40
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
12,852 KB
testcase_01 AC 10 ms
12,724 KB
testcase_02 AC 169 ms
12,708 KB
testcase_03 AC 168 ms
12,648 KB
testcase_04 AC 165 ms
12,716 KB
testcase_05 AC 163 ms
12,708 KB
testcase_06 AC 163 ms
12,640 KB
testcase_07 AC 164 ms
12,712 KB
testcase_08 AC 161 ms
12,652 KB
testcase_09 AC 164 ms
12,644 KB
testcase_10 AC 160 ms
12,712 KB
testcase_11 AC 145 ms
12,756 KB
testcase_12 AC 143 ms
12,720 KB
testcase_13 AC 144 ms
12,724 KB
testcase_14 AC 3 ms
7,360 KB
testcase_15 AC 2 ms
7,524 KB
testcase_16 AC 3 ms
7,528 KB
testcase_17 AC 2 ms
7,500 KB
testcase_18 AC 2 ms
7,352 KB
testcase_19 AC 2 ms
7,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
#define pf(dans) printf("%.12lf", dans)
#define pfn(dans) pf(dans); cout << endl;
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9 + 10;
const ll LINF = (ll)1e18 + 10;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define reprev(i, n) for (i = n - 1; i >= 0; i--)

template <typename T>
T my_abs(T x){
    return (x >= 0)? x : -x;
}

template <typename T>
void chmax(T &a, T b){
    a = max(a, b);
}

template <typename T>
void chmin(T &a, T b){
    a = min(a, b);
}

ll gcd(ll a, ll b){
    if (a > b) return gcd(b, a);
    if (a == 0) return b;
    return gcd(b % a, a);
}

bool incld_bit(ll bit, int i){
    return ((bit>>i) & 1) == 1;
}

// --------------------------------------------------------------------------------

#define N 400007
#define commod mod1
ll fac[N], inv[N], finv[N];

void cominit(int n) {
    int i;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (i = 2; i < n + 2; i++) {
        fac[i] = fac[i - 1] * i % commod;
        inv[i] = commod - inv[commod % i] * (commod / i) % commod;
        finv[i] = finv[i - 1] * inv[i] % commod;
    }
    return;
}

ll com(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    if (r == 0 || r == n) return 1;
    return (fac[n] * finv[r]) % commod * finv[n - r] % commod;
}

int main(void){
    int i, j;
    int n, m;
    int t, x, y;
    ll otoku;

    otoku = 0;

    cin >> n >> m;

    cominit(n * 2);

    rep0(i, m){
        cin >> t >> x >> y;
        if (t == 1){
            otoku = (otoku + com(x + y, x) * com(n * 2 - x - y - 1, n - x - 1) % mod1) % mod1;
        }else{
            otoku = (otoku + com(x + y, x) * com(n * 2 - x - y - 1, n - y - 1) % mod1) % mod1;
        }
    }

    ll ans;
    ans = (ll)n * 2 * com(n * 2, n) % mod1;
    ans = (ans + mod1 - otoku) % mod1;

    cout << ans << endl;

    return 0;
}
0