結果

問題 No.1100 Boxes
ユーザー QCFiumQCFium
提出日時 2020-06-26 21:54:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 4,820 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 178,088 KB
実行使用メモリ 7,788 KB
最終ジャッジ日時 2024-07-04 20:56:34
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 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 4 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 37 ms
5,376 KB
testcase_22 AC 79 ms
7,328 KB
testcase_23 AC 40 ms
5,376 KB
testcase_24 AC 44 ms
5,548 KB
testcase_25 AC 49 ms
5,676 KB
testcase_26 AC 91 ms
7,584 KB
testcase_27 AC 76 ms
7,404 KB
testcase_28 AC 22 ms
5,376 KB
testcase_29 AC 85 ms
7,532 KB
testcase_30 AC 74 ms
7,264 KB
testcase_31 AC 28 ms
5,376 KB
testcase_32 AC 55 ms
5,652 KB
testcase_33 AC 94 ms
7,648 KB
testcase_34 AC 93 ms
7,788 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 87 ms
7,664 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 45 ms
5,376 KB
testcase_39 AC 95 ms
7,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
	std::vector<int> conv(const std::vector<int> &a_, const std::vector<int> &b_) {
		if (!a_.size() || !b_.size()) return {};
		std::vector<int> a = a_, b = b_;
		size_t size = 1;
		for (; size < a_.size() + b_.size(); size <<= 1);
		a.resize(size);
		b.resize(size);
		ntt(a, false);
		ntt(b, false);
		for (size_t i = 0; i < size; i++) a[i] = (int64_t) a[i] * b[i] % mod;
		ntt(a, true);
		a.resize(a_.size() + b_.size() - 1);
		return a;
	}
	std::vector<int> self_conv(std::vector<int> a) {
		if (!a.size()) return {};
		size_t n_ = a.size();
		size_t size = 1;
		for (; size < n_ + n_; size <<= 1);
		a.resize(size);
		ntt(a, false);
		for (auto &i : a) i = (int64_t) i * i % mod;
		ntt(a, true);
		a.resize(n_ + n_ - 1);
		return a;
	}
};

template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};

template<int mod> struct MComb {
	using mint = ModInt<mod>;
	std::vector<mint> fact;
	std::vector<mint> inv;
	MComb (int n) { // O(n + log(mod))
		fact = std::vector<mint>(n + 1, 1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
		inv.resize(n + 1);
		inv[n] = fact[n] ^ (mod - 2);
		for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
	}
	mint ncr(int n, int r) {
		return fact[n] * inv[r] * inv[n - r];
	}
	mint npr(int n, int r) {
		return fact[n] * inv[n - r];
	}
	mint nhr(int n, int r) {
		assert(n + r - 1 < (int) fact.size());
		return ncr(n + r - 1, r);
	}
};

#define MOD 998244353
typedef ModInt<MOD> mint;


int main() {
	int n = ri();
	int k = ri();
	MComb<998244353> com(k);
	
	std::vector<int> r0(k + 1);
	std::vector<int> r1(k + 1);
	for (int i = 0; i <= k; i++) r0[i] = (int) ((mint(i) ^ n) / com.fact[i]);
	for (int i = 0; i <= k; i++) r1[i] = (int) ((mint(-1) ^ i) / com.fact[i]);
	auto tmp = NTT<998244353, 3>().conv(r0, r1);
	
	mint res = 0;
	for (int i = 1; i <= k; i += 2) res += mint(tmp[k - i]) * com.fact[k - i] * com.ncr(k, i);
	std::cout << res << std::endl;
	return 0;
}
0