結果
問題 | No.2615 ペアの作り方 |
ユーザー | kobaryo222 |
提出日時 | 2024-01-26 21:37:58 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 8,368 bytes |
コンパイル時間 | 3,177 ms |
コンパイル使用メモリ | 266,816 KB |
実行使用メモリ | 12,188 KB |
最終ジャッジ日時 | 2024-09-28 07:52:06 |
合計ジャッジ時間 | 4,856 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 3 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 118 ms
12,060 KB |
testcase_16 | AC | 115 ms
11,516 KB |
testcase_17 | AC | 121 ms
12,188 KB |
testcase_18 | AC | 122 ms
12,184 KB |
testcase_19 | AC | 109 ms
11,672 KB |
testcase_20 | AC | 109 ms
11,548 KB |
ソースコード
#line 2 "/home/mikunyan/Library/src/template.hpp" /** * @brief テンプレート * @docs docs/template.md */ // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using pl = pair<ll, ll>; using vp = vector<pl>; using vvp = vector<vp>; using vs = vector<string>; using vvs = vector<vs>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) std::begin(x), std::end(x) #define make_unique(v) v.erase(unique(all(v)), v.end()); #define sum(...) accumulate(all(__VA_ARGS__), 0LL) constexpr ll inf = 0x1fffffffffffffffLL; template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << p.first << " " << p.second; return os; } template <class T1, class T2> void input(vector<T1> &v1, vector<T2> &v2) { rep(i, v1.size()) cin >> v1[i] >> v2[i]; } template <class T1, class T2, class T3> void input(vector<T1> &v1, vector<T2> &v2, vector<T3> &v3) { rep(i, v1.size()) cin >> v1[i] >> v2[i] >> v3[i]; } template <class T1, class T2, class T3, class T4> void input(vector<T1> &v1, vector<T2> &v2, vector<T3> &v3, vector<T4> &v4) { rep(i, v1.size()) cin >> v1[i] >> v2[i] >> v3[i] >> v4[i]; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for(auto &x : v) { is >> x; } return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int)v.size(); i++) { if(i != (int)v.size() - 1) os << v[i] << " "; else os << v[i]; } return os; } template <typename T, typename... Args> auto vec(T x, int arg, Args... args) { if constexpr(sizeof...(args) == 0) return vector<T>(arg, x); else return vector(arg, vec<T>(x, args...)); } template <class T> auto min(const T &a) { return *min_element(all(a)); } template <class T> auto max(const T &a) { return *max_element(all(a)); } template <class T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; } constexpr ll bit(ll x) { return 1LL << x; } constexpr ll msk(ll x) { return (1LL << x) - 1; } constexpr bool stand(ll x, int i) { return x & bit(i); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; #line 2 "A.cpp" /** * @brief Modint * @cite https://nyaannyaan.github.io/library/modint/modint.hpp */ template <uint32_t mod> struct LazyMontgomeryModInt { using mint = LazyMontgomeryModInt; using i32 = int32_t; using u32 = uint32_t; using u64 = uint64_t; static constexpr u32 get_r() { u32 ret = mod; for(i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret; return ret; } static constexpr u32 r = get_r(); static constexpr u32 n2 = -u64(mod) % mod; static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30"); static_assert((mod & 1) == 1, "invalid, mod % 2 == 0"); static_assert(r * mod == 1, "this code has bugs."); u32 a; constexpr LazyMontgomeryModInt() : a(0) {} constexpr LazyMontgomeryModInt(const int64_t &b) : a(reduce(u64(b % mod + mod) * n2)){}; static constexpr u32 reduce(const u64 &b) { return (b + u64(u32(b) * u32(-r)) * mod) >> 32; } constexpr mint &operator+=(const mint &b) { if(i32(a += b.a - 2 * mod) < 0) a += 2 * mod; return *this; } constexpr mint &operator-=(const mint &b) { if(i32(a -= b.a) < 0) a += 2 * mod; return *this; } constexpr mint &operator*=(const mint &b) { a = reduce(u64(a) * b.a); return *this; } constexpr mint &operator/=(const mint &b) { *this *= b.inverse(); return *this; } constexpr mint operator+(const mint &b) const { return mint(*this) += b; } constexpr mint operator-(const mint &b) const { return mint(*this) -= b; } constexpr mint operator*(const mint &b) const { return mint(*this) *= b; } constexpr mint operator/(const mint &b) const { return mint(*this) /= b; } constexpr bool operator==(const mint &b) const { return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a); } constexpr bool operator!=(const mint &b) const { return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a); } constexpr mint operator-() const { return mint() - mint(*this); } constexpr mint operator+() const { return mint(*this); } constexpr mint pow(u64 n) const { mint ret(1), mul(*this); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } constexpr mint inverse() const { int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0; while(y > 0) { t = x / y; x -= t * y, u -= t * v; tmp = x, x = y, y = tmp; tmp = u, u = v, v = tmp; } return mint{u}; } friend ostream &operator<<(ostream &os, const mint &b) { return os << b.get(); } friend istream &operator>>(istream &is, mint &b) { int64_t t; is >> t; b = LazyMontgomeryModInt<mod>(t); return (is); } constexpr u32 get() const { u32 ret = reduce(a); return ret >= mod ? ret - mod : ret; } static constexpr u32 get_mod() { return mod; } }; // constexpr long long mod = 1000000007; constexpr long long mod = 998244353; using mint = LazyMontgomeryModInt<mod>; using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>; template <typename T> struct Enumeration { private: static vector<T> _fact, _finv, _inv; inline static void expand(size_t sz) { if(_fact.size() < sz + 1) { int pre_sz = max(1, (int)_fact.size()); _fact.resize(sz + 1, T(1)); _finv.resize(sz + 1, T(1)); _inv.resize(sz + 1, T(1)); for(int i = pre_sz; i <= (int)sz; i++) { _fact[i] = _fact[i - 1] * T(i); } _finv[sz] = T(1) / _fact[sz]; for(int i = (int)sz - 1; i >= pre_sz; i--) { _finv[i] = _finv[i + 1] * T(i + 1); } for(int i = pre_sz; i <= (int)sz; i++) { _inv[i] = _finv[i] * _fact[i - 1]; } } } public: explicit Enumeration(size_t sz = 0) { expand(sz); } static inline T fact(int k) { expand(k); return _fact[k]; } static inline T finv(int k) { expand(k); return _finv[k]; } static inline T inv(int k) { expand(k); return _inv[k]; } static T P(int n, int r) { if(r < 0 || n < r) return 0; return fact(n) * finv(n - r); } static T C(int p, int q) { if(q < 0 || p < q) return 0; return fact(p) * finv(q) * finv(p - q); } static T H(int n, int r) { if(n < 0 || r < 0) return 0; return r == 0 ? 1 : C(n + r - 1, r); } }; template <typename T> vector<T> Enumeration<T>::_fact = vector<T>(); template <typename T> vector<T> Enumeration<T>::_finv = vector<T>(); template <typename T> vector<T> Enumeration<T>::_inv = vector<T>(); int main() { ll N; cin >> N; vl X(N), Y(N); cin >> X >> Y; vl v(X); v.insert(v.end(), all(Y)); sort(all(v)); set<ll> st; rep(i, N) st.insert(v[i]); ll x = 0, y = 0; rep(i, N) { if(st.contains(X[i])) x++; if(st.contains(Y[i])) y++; } Enumeration<mint> comb; cout << comb.fact(x) * comb.fact(y) << endl; }