結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 22:14:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,527 bytes |
コンパイル時間 | 2,887 ms |
コンパイル使用メモリ | 198,648 KB |
最終ジャッジ日時 | 2025-01-22 21:58:51 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template <typename T, typename Compare = less<T>> T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); } template <typename T, typename Compare = less<T>> T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); } #include <atcoder/modint> using mint = atcoder::modint1000000007; int main() { int n, m; cin >> n >> m; auto fact = vec<mint>(uns, 2 * n + 1); fact[0] = 1; for (int i = 1; i <= 2 * n; ++i) { fact[i] = fact[i - 1] * i; } auto comb = [&](int n, int r) { return fact[n] / (fact[r] * fact[n - r]); }; auto ans = comb(2 * n, n) * 2 * n; for (int i = 0; i < m; ++i) { int t, y, x; cin >> t >> y >> x; if (t == 1) { ans -= comb(y + x, y) * comb(n - y + n - x - 1, n - y - 1); } if (t == 2) { ans -= comb(y + x, y) * comb(n - y + n - x - 1, n - x - 1); } } cout << ans.val() << endl; }