結果
問題 | No.1431 東大文系数学2020第2問改 |
ユーザー | apricity |
提出日時 | 2024-11-25 16:10:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 643 ms / 5,000 ms |
コード長 | 13,232 bytes |
コンパイル時間 | 1,548 ms |
コンパイル使用メモリ | 138,328 KB |
実行使用メモリ | 120,556 KB |
最終ジャッジ日時 | 2024-11-25 16:10:47 |
合計ジャッジ時間 | 16,517 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 260 ms
120,444 KB |
testcase_01 | AC | 269 ms
120,280 KB |
testcase_02 | AC | 246 ms
120,480 KB |
testcase_03 | AC | 584 ms
120,504 KB |
testcase_04 | AC | 240 ms
120,468 KB |
testcase_05 | AC | 603 ms
120,456 KB |
testcase_06 | AC | 597 ms
120,328 KB |
testcase_07 | AC | 632 ms
120,456 KB |
testcase_08 | AC | 643 ms
120,332 KB |
testcase_09 | AC | 613 ms
120,432 KB |
testcase_10 | AC | 539 ms
120,352 KB |
testcase_11 | AC | 549 ms
120,320 KB |
testcase_12 | AC | 543 ms
120,556 KB |
testcase_13 | AC | 532 ms
120,444 KB |
testcase_14 | AC | 508 ms
120,432 KB |
testcase_15 | AC | 521 ms
120,496 KB |
testcase_16 | AC | 496 ms
120,464 KB |
testcase_17 | AC | 481 ms
120,488 KB |
testcase_18 | AC | 519 ms
120,484 KB |
testcase_19 | AC | 622 ms
120,472 KB |
testcase_20 | AC | 524 ms
120,472 KB |
testcase_21 | AC | 571 ms
120,508 KB |
testcase_22 | AC | 412 ms
120,424 KB |
testcase_23 | AC | 621 ms
120,320 KB |
testcase_24 | AC | 616 ms
120,320 KB |
testcase_25 | AC | 234 ms
120,376 KB |
testcase_26 | AC | 235 ms
120,392 KB |
testcase_27 | AC | 229 ms
120,432 KB |
ソースコード
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<numeric> #include<cmath> #include<utility> #include<tuple> #include<array> #include<cstdint> #include<cstdio> #include<iomanip> #include<map> #include<set> #include<unordered_map> #include<unordered_set> #include<queue> #include<stack> #include<deque> #include<bitset> #include<cctype> #include<chrono> #include<random> #include<cassert> #include<cstddef> #include<iterator> #include<string_view> #include<type_traits> #include<functional> #ifdef LOCAL # include "debug_print.hpp" # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast<void>(0)) #endif using namespace std; template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template<typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template<typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template<typename T, class... U, char sep = ' '> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; out(u...); } void outr() {} template<typename T, class... U, char sep = ' '> void outr(const T &t, const U &...u) { cout << t; outr(u...); } using ll = long long; using D = double; using LD = long double; using P = pair<ll, ll>; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i128 = __int128; using u128 = unsigned __int128; using vi = vector<ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vc<T>>; template <class T> using vvvc = vector<vvc<T>>; template <class T> using vvvvc = vector<vvvc<T>>; template <class T> using vvvvvc = vector<vvvvc<T>>; #define vv(type, name, h, ...) \ vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) \ vector<vector<vector<type>>> name( \ h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) #define vvvv(type, name, a, b, c, ...) \ vector<vector<vector<vector<type>>>> name( \ a, vector<vector<vector<type>>>( \ b, vector<vector<type>>(c, vector<type>(__VA_ARGS__)))) template<typename T> using PQ = priority_queue<T,vector<T>>; template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; #define rep1(a) for(ll i = 0; i < a; i++) #define rep2(i, a) for(ll i = 0; i < a; i++) #define rep3(i, a, b) for(ll i = a; i < b; i++) #define rep4(i, a, b, c) for(ll i = a; i < b; i += c) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(a) for(ll i = (a)-1; i >= 0; i--) #define rrep2(i, a) for(ll i = (a)-1; i >= 0; i--) #define rrep3(i, a, b) for(ll i = (b)-1; i >= a; i--) #define rrep4(i, a, b, c) for(ll i = (b)-1; i >= a; i -= c) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define for_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s))) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) #define SZ(v) ll(v.size()) #define MIN(v) *min_element(ALL(v)) #define MAX(v) *max_element(ALL(v)) #define LB(c, x) distance((c).begin(), lower_bound(ALL(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(ALL(c), (x))) template <typename T, typename U> T SUM(const vector<U> &v) { T res = 0; for(auto &&a : v) res += a; return res; } template <typename T> vector<pair<T,int>> RLE(const vector<T> &v) { if (v.empty()) return {}; T cur = v.front(); int cnt = 1; vector<pair<T,int>> res; for (int i = 1; i < (int)v.size(); i++) { if (cur == v[i]) cnt++; else { res.emplace_back(cur, cnt); cnt = 1; cur = v[i]; } } res.emplace_back(cur, cnt); return res; } template<class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, true : false); } template<class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, true : false); } void YESNO(bool flag) { out(flag ? "YES" : "NO"); } void yesno(bool flag) { out(flag ? "Yes" : "No"); } int popcnt(int x) { return __builtin_popcount(x); } int popcnt(u32 x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } int popcnt(u64 x) { return __builtin_popcountll(x); } int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); } int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); } int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); } int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); } int highbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); } int highbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); } int highbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } int highbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); } int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); } int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } template <typename T> T get_bit(T x, int k) { return x >> k & 1; } template <typename T> T set_bit(T x, int k) { return x | T(1) << k; } template <typename T> T reset_bit(T x, int k) { return x & ~(T(1) << k); } template <typename T> T flip_bit(T x, int k) { return x ^ T(1) << k; } template <typename T> T popf(deque<T> &que) { T a = que.front(); que.pop_front(); return a; } template <typename T> T popb(deque<T> &que) { T a = que.back(); que.pop_back(); return a; } template <typename T> T pop(queue<T> &que) { T a = que.front(); que.pop(); return a; } template <typename T> T pop(PQ<T> &que) { T a = que.top(); que.pop(); return a; } template <typename T> T pop(minPQ<T> &que) { T a = que.top(); que.pop(); return a; } template <typename F> ll binary_search(F check, ll ok, ll ng, bool check_ok = true) { if (check_ok) assert(check(ok)); while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; } template <typename F> ll binary_search_real(F check, double ok, double ng, int iter = 60) { for (int _ = 0; _ < iter; _++) { double mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return (ok + ng) / 2; } // max x s.t. b*x <= a ll div_floor(ll a, ll b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b - (a % b < 0); } // max x s.t. b*x < a ll div_under(ll a, ll b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b - (a % b <= 0); } // min x s.t. b*x >= a ll div_ceil(ll a, ll b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b + (a % b > 0); } // min x s.t. b*x > a ll div_over(ll a, ll b) { assert(b != 0); if (b < 0) a = -a, b = -b; return a / b + (a % b >= 0); } // x = a mod b (b > 0), 0 <= x < b ll modulo(ll a, ll b) { assert(b > 0); ll c = a % b; return c < 0 ? c + b : c; } // (q,r) s.t. a = b*q + r, 0 <= r < b (b > 0) // div_floor(a,b), modulo(a,b) pair<ll,ll> divmod(ll a, ll b) { ll q = div_floor(a,b); return {q, a - b*q}; } 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; } }; template<typename T> struct Binomial { vector<T> fact_, inv_, finv_; constexpr Binomial() {} constexpr Binomial(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) { init(n); } constexpr void init(int n) noexcept { constexpr int mod = T::get_mod(); fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); for(int i = 2; i < n; i++){ fact_[i] = fact_[i-1] * i; inv_[i] = -inv_[mod%i] * (mod/i); finv_[i] = finv_[i-1] * inv_[i]; } } constexpr T com(int n, int k) const noexcept { if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n-k]; } constexpr T perm(int n, int k) const noexcept { if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[n-k]; } constexpr T fact(int n) const noexcept { if (n < 0) return 0; return fact_[n]; } constexpr T inv(int n) const noexcept { if (n < 0) return 0; return inv_[n]; } constexpr T finv(int n) const noexcept { if (n < 0) return 0; return finv_[n]; } constexpr T com_naive(int n, int k) const noexcept { if (n < 0 || k < 0 || n < k) return 0; T res = T(1); k = min(k, n-k); for (int i = 1; i <= k; i++)res *= (n--) * inv(i); return res; } template <typename I> constexpr T multi(const vector<I> &v) const noexcept { static_assert(is_integral<I>::value); I n = 0; for (auto& x : v) { if (x < 0) return 0; n += x; } T res = fact(n); for (auto &x : v) res *= finv(x); return res; } // [x^k] (1-x)^{-n} = com(n+k-1, k) constexpr T neg(int n, int k) const noexcept { if (n < 0 || k < 0) return 0; return k == 0 ? 1 : com(n+k-1, k); } }; const int mod = 998244353; //const int mod = 1000000007; using mint = LazyMontgomeryModInt<mod>; Binomial<mint> bc(10000000); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,m,k; in(n,m,k); vector<mint> f(n*2+1); rep(i,n*2+1){ rep(a,i+1){ int b = i-a; f[i] += bc.com(n,a) * bc.com(n,b) * bc.com((n-a)*(n-b),m); } } vector<mint> a(n*2+1), b(n*2+1); b[k] = 1; rep(i,n*2+1) rep(j,i+1) a[i] += b[j] * bc.com(i,j) * ((i-j)%2 ? -1:1); mint ans = 0; rep(i,n*2+1) ans += f[i]*a[i]; out(ans); }