結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | seven_three |
提出日時 | 2021-07-09 21:51:28 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 230 ms / 2,000 ms |
コード長 | 1,153 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 91,368 KB |
実行使用メモリ | 12,996 KB |
最終ジャッジ日時 | 2023-09-14 08:42:45 |
合計ジャッジ時間 | 5,151 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
12,736 KB |
testcase_01 | AC | 35 ms
12,732 KB |
testcase_02 | AC | 230 ms
12,732 KB |
testcase_03 | AC | 227 ms
12,996 KB |
testcase_04 | AC | 228 ms
12,732 KB |
testcase_05 | AC | 224 ms
12,700 KB |
testcase_06 | AC | 225 ms
12,760 KB |
testcase_07 | AC | 226 ms
12,732 KB |
testcase_08 | AC | 228 ms
12,684 KB |
testcase_09 | AC | 229 ms
12,844 KB |
testcase_10 | AC | 227 ms
12,736 KB |
testcase_11 | AC | 181 ms
12,796 KB |
testcase_12 | AC | 184 ms
12,740 KB |
testcase_13 | AC | 182 ms
12,800 KB |
testcase_14 | AC | 37 ms
12,776 KB |
testcase_15 | AC | 38 ms
12,756 KB |
testcase_16 | AC | 38 ms
12,996 KB |
testcase_17 | AC | 35 ms
12,760 KB |
testcase_18 | AC | 39 ms
12,780 KB |
testcase_19 | AC | 40 ms
12,688 KB |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; long long fac[400040], finv[400040], inv[400040]; long long mod = 1000000007; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 400040; 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; } } long long COM(long long n, long long 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() { COMinit(); long long n, m; cin >> n >> m; long long ans = COM(n + n, n) * 2 * n % mod; for (int i = 0; i < m; i++) { int t, x, y; cin >> t >> x >> y; if (t == 1) { ans -= COM(x + y, y) * COM((n - x - 1) + (n - y), n - x - 1) % mod; } else { ans -= COM(x + y, y) * COM((n - x) + (n - y - 1), n - x) % mod; } ans %= mod; } cout << (ans + mod) % mod << endl; }