結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | jutama |
提出日時 | 2021-07-09 21:54:16 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 5,641 bytes |
コンパイル時間 | 3,504 ms |
コンパイル使用メモリ | 188,652 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-07-01 16:12:17 |
合計ジャッジ時間 | 5,716 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
6,400 KB |
testcase_01 | AC | 14 ms
6,272 KB |
testcase_02 | AC | 71 ms
8,704 KB |
testcase_03 | AC | 70 ms
8,704 KB |
testcase_04 | AC | 72 ms
8,704 KB |
testcase_05 | AC | 76 ms
8,704 KB |
testcase_06 | AC | 71 ms
8,704 KB |
testcase_07 | AC | 71 ms
8,704 KB |
testcase_08 | AC | 70 ms
8,704 KB |
testcase_09 | AC | 70 ms
8,576 KB |
testcase_10 | AC | 71 ms
8,576 KB |
testcase_11 | AC | 64 ms
8,704 KB |
testcase_12 | AC | 64 ms
8,704 KB |
testcase_13 | AC | 64 ms
8,576 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
ソースコード
#include <atcoder/all>#include <bitset>#include <fstream>#include <functional>#include <iostream>#include <iomanip>#include <limits>#include <map>#include <math.h>#include <queue>#include <set>#include <sstream>#include <stack>#include <stdio.h>#include <stdlib.h>#include <unordered_map>#include <unordered_set>#include <vector>using namespace std;using namespace atcoder;typedef long long ll;typedef long double ld;typedef std::pair<int, int> pii;typedef std::pair<int, ll> pil;typedef std::pair<ll, int> pli;typedef std::pair<ll, ll> pll;typedef std::pair<int, ld> pid;typedef std::pair<int, std::string> pis;typedef std::pair<ll, std::string> pls;typedef std::vector<bool> vb;typedef std::vector<vb> vvb;typedef std::vector<int> vi;typedef std::vector<vi> vvi;typedef std::vector<vvi> vvvi;typedef std::vector<vvvi> vvvvi;typedef std::vector<ll> vl;typedef std::vector<vl> vvl;typedef std::vector<vvl> vvvl;typedef std::vector<vvvl> vvvvl;typedef std::vector<ld> vd;typedef std::vector<vd> vvd;typedef std::vector<std::string> vs;#define rep(i,n) for(auto i=0; i<n; ++i)#define repm(i,s,n) for(auto i=s; i<n; ++i)#define repd(i,n) for(auto i=n-1; i>=0; --i)#define repdm(i,e,n) for(auto i=n-1; i>=e; --i)#define all(a) (a).begin(), (a).end()#define rall(a) (a).rbegin(), (a).rend()template <class T> inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; }template <class T> inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; }template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin>> v; x = v; return is;}template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val();return os;}inline void _n() { std::cout << std::endl; }template <class T> inline void _(const T a) { std::cout << a; }template <class T> inline void _l(const T a) { _(a); _n(); }template <class T> inline void _s(const T a) { _(a); _(' '); }template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); }template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); }template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); }template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } }template <class T> inline void _vvs(const std::vector<std::vector<T>> v) { for(auto a : v) { _vs(a); } }inline void ynl(const bool b) {_l(b ? "yes" : "no");}inline void yns(const bool b) {_l(b ? "Yes" : "No");}inline void ynu(const bool b) {_l(b ? "YES" : "NO");}constexpr int INF = numeric_limits<int>::max() >> 1;constexpr long long INF_LL = numeric_limits<long long>::max() >> 1LL;constexpr long long MOD1 = 1000000007;constexpr long long MOD9 = 998244353;using mint1 = atcoder::modint1000000007;using mint9 = atcoder::modint998244353;//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//struct cmb_mod {using mint = atcoder::modint;public:cmb_mod(long long n, long long m) : _n(n), _mod(m) { init(); }long long factorial(long long n) {assert(0 <= n && n <= _n);mint res = fac[n].val();return res.val();};long long factorial_inv(long long n) {assert(0 <= n && n <= _n);mint res = finv[n].val();return res.val();};long long permutation(long long n, long long k) {assert(0 <= n && n <= _n);assert(0 <= k && k <= n);mint res = fac[n] * finv[n-k];return res.val();};long long combination(long long n, long long k) {assert(0 <= n && n <= _n);assert(0 <= k && k <= n);mint res = fac[n] * finv[k] * finv[n-k];return res.val();};long long combination_with_repetition (long long n, long long k) {return combination(n+k-1, k);};long long multinomial_coefficient (long long n, std::vector<long long> kv) {assert(0 <= n && n <= _n);long long ks = 0;for(auto a : kv) { assert(0 <= a && a <= _n); ks += a; }assert(n == ks);mint res = fac[n];for(auto a : kv) { res *= finv[a]; }return res.val();}private:long long _n;long long _mod;std::vector<mint> fac;std::vector<mint> finv;void init () {assert(0 <= _n);assert(1 <= _mod);mint::set_mod((int)_mod);fac.resize(_n+1, mint(0));finv.resize(_n+1, mint(0));fac[0] = mint(1);for(long long i = 1 ; i <= _n ; ++i) { fac[i] = fac[i-1] * mint(i); }finv[_n] = atcoder::inv_mod(fac[_n].val(), _mod);for(long long i = _n - 1 ; i > -1 ; --i) { finv[i] = finv[i+1] * (i+1); }}};void solve() {int N, M; cin >> N >> M;vi T(M), X(M), Y(M);rep(i, M) cin >> T[i] >> X[i] >> Y[i];cmb_mod cmb(2*N, MOD1);mint1 ans = 2 * N;ans *= cmb.combination(2*N, N);rep(i, M) {mint1 tmp = cmb.combination(X[i] + Y[i], X[i]);tmp *= cmb.combination(2 * N - X[i] - Y[i] - 1, T[i] == 1 ? N - Y[i] : N - X[i]);ans -= tmp;}_l(ans);}//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//int main() {std::ifstream in("input.txt");std::cin.rdbuf(in.rdbuf());std::cin.tie(0);std::cout.tie(0);std::ios::sync_with_stdio(false);solve();return 0;}