結果

問題 No.2237 Xor Sum Hoge
ユーザー rabimearabimea
提出日時 2023-03-03 22:20:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,547 ms / 10,000 ms
コード長 2,411 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 209,212 KB
実行使用メモリ 11,808 KB
最終ジャッジ日時 2023-10-18 02:31:12
合計ジャッジ時間 27,452 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,537 ms
11,808 KB
testcase_01 AC 8 ms
6,764 KB
testcase_02 AC 7 ms
6,748 KB
testcase_03 AC 8 ms
6,764 KB
testcase_04 AC 8 ms
6,764 KB
testcase_05 AC 9 ms
6,804 KB
testcase_06 AC 8 ms
6,772 KB
testcase_07 AC 8 ms
6,772 KB
testcase_08 AC 9 ms
6,800 KB
testcase_09 AC 9 ms
6,800 KB
testcase_10 AC 10 ms
6,808 KB
testcase_11 AC 6 ms
6,668 KB
testcase_12 AC 6 ms
6,668 KB
testcase_13 AC 6 ms
6,668 KB
testcase_14 AC 729 ms
9,240 KB
testcase_15 AC 7 ms
6,668 KB
testcase_16 AC 1,512 ms
11,068 KB
testcase_17 AC 6 ms
6,668 KB
testcase_18 AC 706 ms
8,800 KB
testcase_19 AC 706 ms
8,616 KB
testcase_20 AC 1,498 ms
10,912 KB
testcase_21 AC 1,533 ms
11,752 KB
testcase_22 AC 1,532 ms
11,692 KB
testcase_23 AC 1,547 ms
11,792 KB
testcase_24 AC 1,537 ms
11,784 KB
testcase_25 AC 1,531 ms
11,720 KB
testcase_26 AC 1,529 ms
11,752 KB
testcase_27 AC 1,532 ms
11,760 KB
testcase_28 AC 1,529 ms
11,744 KB
testcase_29 AC 1,525 ms
11,720 KB
testcase_30 AC 1,541 ms
11,800 KB
testcase_31 AC 6 ms
6,732 KB
testcase_32 AC 6 ms
6,732 KB
testcase_33 AC 9 ms
6,812 KB
testcase_34 AC 6 ms
6,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using vi = vector <int>;
const ll mod = 998244353;

const int N = 12e4 + 11;
ll inv[N], fac[N], ifac[N];
ll binom(int n, int m) {
	if(n < m || m < 0) return 0; // n >= 0
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

ll qpow(ll a, ll b) {
	ll r = 1, t = a;
	for(; b; b /= 2) {
		if(b & 1)
			r = r * t % mod;
		t = t * t % mod;
	}
	return r;
}
using vl = vector <ll>;

ll f[N];
const ll P = mod, G = 3;
ll INV(ll x) { return qpow(x, P - 2); }
void ntt(vl &a, int op = 1) { // P: 模数, G: 原根
	int n = a.size();
	for (int i = 1, j = 0; i < n - 1; ++i) {
		for (int s = n; j ^= s >>= 1, ~j & s;) {}
		if (i < j) swap(a[i], a[j]);
	}
	for (int i = 1; i < n; i *= 2) {
		ll u = qpow(G, (P - 1) / (i * 2));
		if (op == -1) u = INV(u);
		for (int j = 0; j < n; j += i * 2) {
			ll w = 1;
			for (int k = 0; k < i; ++k, w = w * u % P) {
				int x = a[j + k], y = w * a[j + k + i] % P;
				#define modto(x) ({if ((x) >= P) (x) -= P;})
				a[j + k] = x + y; modto(a[j + k]);
				a[j + k + i] = x - y + P; modto(a[j + k + i]);
				#undef modto
	}}}
	if (op == -1) { ll inv = INV(n);
		for (int i = 0; i < n; ++i) a[i] = a[i] * inv % P; }
}
vl multi(vl a, vl b) {
	int m = a.size() + b.size() - 1;
	int n = 1; while (n < m) n *= 2;
	vl fa(n), fb(n), fc(n);
	copy(a.begin(), a.end(), fa.begin()); ntt(fa);
	copy(b.begin(), b.end(), fb.begin()); ntt(fb);
	for (int i = 0; i < n; ++i) fc[i] = fa[i] * fb[i] % P;
	ntt(fc, -1); fc.resize(m);
	return fc;
}

int main() {
	inv[1] = fac[0] = ifac[0] = 1;
	for(int i = 2; i < N; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i < N; i ++) {
		fac[i] = i * fac[i - 1] % mod;
		ifac[i] = inv[i] * ifac[i - 1] % mod;
	}
	ios::sync_with_stdio(0);
	
	int n; ll b, c;
	cin >> n >> b >> c;

	if(b < c) {
		cout << 0 << '\n';
		return 0;
	}

	f[0] = 1;
	while(b > 0) {
		
		vl F(f, f + n + 1);
		vl G(n + 1);
		for(int i = 0; i <= n; i ++) if(i % 2 == c % 2)
			G[i] = binom(n, i);
		
		//~ for(int i = 0; i <= n; i ++) cout << F[i] << ' '; cout << '\n';
		//~ for(int i = 0; i <= n; i ++) cout << G[i] << ' '; cout << '\n';
		
		G = multi(F, G);
		//~ for(int i = 0; i < G.size(); i ++) cout << G[i] << ' '; cout << '\n';
		
		G.resize(2 * n + 2);
		for(int i = 0; i <= n; i ++)
			f[i] = G[i * 2 + (b & 1)];
		
		b /= 2;
		c /= 2;
	}
	
	cout << f[0] << '\n';
}
0