結果

問題 No.1100 Boxes
ユーザー cn_449cn_449
提出日時 2020-06-26 23:08:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 6,242 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 124,380 KB
実行使用メモリ 16,360 KB
最終ジャッジ日時 2024-07-04 23:34:32
合計ジャッジ時間 3,600 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,064 KB
testcase_01 AC 9 ms
7,808 KB
testcase_02 AC 9 ms
7,936 KB
testcase_03 AC 8 ms
7,808 KB
testcase_04 AC 9 ms
7,808 KB
testcase_05 AC 9 ms
7,936 KB
testcase_06 AC 9 ms
7,936 KB
testcase_07 AC 9 ms
7,808 KB
testcase_08 AC 9 ms
7,808 KB
testcase_09 AC 9 ms
7,808 KB
testcase_10 AC 8 ms
7,808 KB
testcase_11 AC 8 ms
7,936 KB
testcase_12 AC 9 ms
7,808 KB
testcase_13 AC 9 ms
7,808 KB
testcase_14 AC 9 ms
7,808 KB
testcase_15 AC 8 ms
7,808 KB
testcase_16 AC 9 ms
7,936 KB
testcase_17 AC 9 ms
7,936 KB
testcase_18 AC 8 ms
7,808 KB
testcase_19 AC 11 ms
8,064 KB
testcase_20 AC 14 ms
8,832 KB
testcase_21 AC 38 ms
11,672 KB
testcase_22 AC 82 ms
15,844 KB
testcase_23 AC 40 ms
11,804 KB
testcase_24 AC 41 ms
12,028 KB
testcase_25 AC 41 ms
12,220 KB
testcase_26 AC 85 ms
16,240 KB
testcase_27 AC 80 ms
15,776 KB
testcase_28 AC 23 ms
9,728 KB
testcase_29 AC 85 ms
15,964 KB
testcase_30 AC 83 ms
15,556 KB
testcase_31 AC 25 ms
10,280 KB
testcase_32 AC 43 ms
12,488 KB
testcase_33 AC 86 ms
16,324 KB
testcase_34 AC 87 ms
16,232 KB
testcase_35 AC 10 ms
7,808 KB
testcase_36 AC 78 ms
16,360 KB
testcase_37 AC 9 ms
7,808 KB
testcase_38 AC 40 ms
11,976 KB
testcase_39 AC 85 ms
16,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 998244353;
constexpr ll modsize = 200000;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

template<int mod, int root = 3> class NumberTheoreticTransform {
	inline static constexpr long long gcd(long long a, long long b) {
		return (b ? gcd(b, a % b) : a);
	}
	inline static long long ext_gcd(long long a, long long b, long long &x, long long &y) {
		long long res;
		if (b == 0) res = a, x = 1, y = 0;
		else res = ext_gcd(b, a%b, y, x), y -= a / b * x;
		return res;
	}
	inline static long long inv_mod(long long a, long long b) {
		long long x, y;
		ext_gcd(a, b, x, y);
		return (x%b + b) % b;
	}
	inline static long long pow_mod(long long x, long long n, long long m) {
		long long res = 1;
		for (; n > 0; n >>= 1, (x *= x) %= m) if (n & 1) (res *= x) %= m;
		return res;
	}
	inline static long long garner(vector<long long> b, vector<long long> m, long long d) {
		int N = b.size();
		vector<long long> coe(N + 1, 1), val(N + 1, 0);
		long long g, gl, gr, sum = accumulate(b.begin(), b.end(), 0LL);
		for (int l = 0; l < N; ++l) {
			for (int r = l + 1; r < N; ++r) {
				g = gcd(m[l], m[r]);
				if (sum && (b[l] - b[r]) % g != 0) return -1;
				m[l] /= g, m[r] /= g;
				gl = gcd(m[l], g), gr = g / gl;
				do {
					g = gcd(gl, gr);
					gl *= g, gr /= g;
				} while (g != 1);
				m[l] *= gl, m[r] *= gr;
				b[l] %= m[l], b[r] %= m[r];
			}
		}
		if (!sum) {
			long long lcm = 1;
			for (auto& e : m) (lcm *= e) %= d;
			return lcm;
		}
		m.push_back(d);
		for (int i = 0; i < N; ++i) {
			long long t = (b[i] - val[i]) * inv_mod(coe[i], m[i]);
			((t %= m[i]) += m[i]) %= m[i];
			for (int j = i + 1; j <= N; ++j) {
				(val[j] += t * coe[j]) %= m[j];
				(coe[j] *= m[i]) %= m[j];
			}
		}
		return val.back();
	}
	inline static void ntt(vector<long long>& f, int sgn = 1) {
		int N = f.size();
		int h = pow_mod(root, (mod - 1) / N, mod);
		if (sgn == -1) h = inv_mod(h, mod);
		for (int i = 0, j = 1; j < N - 1; ++j) {
			for (int k = N >> 1; k > (i ^= k); k >>= 1);
			if (j < i) swap(f[i], f[j]);
		}
		for (int i = 1, j = 2; i < N; i *= 2, j *= 2) {
			long long w = 1, base = pow_mod(h, N / j, mod);
			for (int k = 0; k < i; ++k, (w *= base) %= mod) {
				for (int l = k; l < N; l += j) {
					long long u = f[l];
					long long d = f[l + i] * w % mod;
					f[l] = u + d;
					if (f[l] >= mod) f[l] -= mod;
					f[l + i] = u - d;
					if (f[l + i] < 0) f[l + i] += mod;
				}
			}
		}
		for (auto& x : f) if (x < 0) x += mod;
	}
public:
	inline static vector<long long> convolution(vector<long long> g, vector<long long> h) {
		int N; for (N = 1; N < g.size() + h.size(); N *= 2);
		vector<long long> f(N);
		g.resize(N); h.resize(N);
		ntt(g);	ntt(h);
		for (int i = 0; i < N; ++i) (f[i] = g[i] * h[i]) %= mod;
		ntt(f, -1);
		long long inv = inv_mod(N, mod);
		for (auto& x : f) x = x * inv % mod;
		return f;
	}
	inline static vector<long long> convolution_arbitrarymod(vector<long long> g, vector<long long> h) {
		for (auto& a : g) a %= mod;
		for (auto& a : h) a %= mod;
		const int mod1 = 167772161;
		const int mod2 = 469762049;
		const int mod3 = 1224736769;
		auto x = NumberTheoreticTransform<mod1>::convolution(g, h);
		auto y = NumberTheoreticTransform<mod2>::convolution(g, h);
		auto z = NumberTheoreticTransform<mod3>::convolution(g, h);
		vector<long long> res(x.size()), b(3), m(3);
		for (int i = 0; i < x.size(); ++i) {
			m[0] = mod1, b[0] = x[i];
			m[1] = mod2, b[1] = y[i];
			m[2] = mod3, b[2] = z[i];
			res[i] = garner(b, m, mod);
		}
		return res;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	modcalc();

	ll n, k;
	cin >> n >> k;
	vector<ll> a(k + 1), b(k + 1);
	rep(i, k + 1) {
		if (i & 1) b[i] = facinv[i];
		if ((k & 1) != (i & 1)) a[i] = modpow(i, n) * facinv[i] % mod;
		else {
			a[i] = mod - modpow(i, n) * facinv[i] % mod;
			if (a[i] >= mod) a[i] -= mod;
		}
	}
	vector<ll> c = NumberTheoreticTransform<998244353>::convolution(a, b);
	ll ans = 0;
	rep(i, k + 1) ans += c[i] * facinv[k - i] % mod;
	ans %= mod;
	cout << ans * fac[k] % mod << '\n';
}
0