結果
| 問題 |
No.1596 Distance Sum in 2D Plane
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 22:34:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 287 ms / 2,000 ms |
| コード長 | 1,498 bytes |
| コンパイル時間 | 6,256 ms |
| コンパイル使用メモリ | 251,692 KB |
| 最終ジャッジ日時 | 2025-01-22 22:16:43 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using pll = std::pair<long long, long long>;
#define rep(i, n) for (long long i = 0LL; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repr(i, n) for (long long i = (long long)(n) - 1; i >= 0LL; i--)
#define repr2(i, n, s) for (long long i = (long long)(n) - 1; i >= (long long)(s); i--)
#define nCr(n, r) ((n) >= (r) ? fac.at(n) * inv_fac.at(r) * inv_fac.at((n) - (r)) : 0)
template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 2e18;
using mint = modint1000000007;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
vector<mint> fac(1'000'000 + 1, 1), inv_fac(1'000'000 + 1, 1);
rep2(i_, 2, 1'000'000 + 1) {
fac[i_] = i_ * fac[i_ - 1];
inv_fac[i_] = fac[i_].inv();
}
ll N, M;
cin >> N >> M;
mint ans = 2 * N * nCr(2 * N, N);
rep(i, M) {
ll t, x, y;
cin >> t >> x >> y;
if (t == 1) {
ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - y);
} else {
ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - x);
}
}
cout << ans.val() << "\n";
}