結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー trineutrontrineutron
提出日時 2021-07-09 21:57:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 941 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 203,448 KB
実行使用メモリ 6,664 KB
最終ジャッジ日時 2023-09-14 08:53:35
合計ジャッジ時間 6,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
6,460 KB
testcase_01 AC 61 ms
6,664 KB
testcase_02 AC 218 ms
6,340 KB
testcase_03 AC 222 ms
6,488 KB
testcase_04 AC 222 ms
6,524 KB
testcase_05 AC 219 ms
6,516 KB
testcase_06 AC 222 ms
6,392 KB
testcase_07 AC 222 ms
6,388 KB
testcase_08 AC 221 ms
6,464 KB
testcase_09 AC 218 ms
6,340 KB
testcase_10 AC 219 ms
6,456 KB
testcase_11 AC 195 ms
6,460 KB
testcase_12 AC 195 ms
6,460 KB
testcase_13 AC 198 ms
6,516 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint1000000007;

vector<mint> fact, inv;

void init(int n)
{
    fact.push_back(1);
    inv.push_back(1);
    for (int i = 0; i < n; i++)
    {
        fact.push_back(fact.at(i) * (i + 1));
        inv.push_back(fact.at(i + 1).inv());
    }
}

mint ncr(int n, int r)
{
    if (r < 0 or n < r)
    {
        return 0;
    }
    return fact.at(n) * inv.at(r) * inv.at(n - r);
}

int main()
{
    int n, m;
    cin >> n >> m;
    init(2 * n);
    mint ans = 2 * n * ncr(2 * n, n);
    for (int i = 0; i < m; i++)
    {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1)
        {
            ans -= ncr(x + y, x) * ncr(2 * n - x - y - 1, n - x - 1);
        }
        else
        {
            ans -= ncr(x + y, x) * ncr(2 * n - x - y - 1, n - x);
        }
    }
    cout << ans.val() << endl;
    return 0;
}
0