QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#902949#8147. Math ExamPengztAC ✓238ms238288kbC++141.5kb2025-02-16 20:50:132025-02-16 20:50:16

Judging History

This is the latest submission verdict.

  • [2025-02-16 20:50:16]
  • Judged
  • Verdict: AC
  • Time: 238ms
  • Memory: 238288kb
  • [2025-02-16 20:50:13]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
mt19937_64 eng(time(0) ^ clock());
template <typename T>
T rnd(T l, T r) { return eng() % (r - l + 1) + l; }
const int P = 998244353;
ll fac[10000005], inv[10000005], ifac[10000005];
void Init(int n) {
	fac[0] = fac[1] = inv[1] = ifac[0] = ifac[1] = 1;
	for (int i = 2; i <= n; i++) {
		fac[i] = fac[i - 1] * i % P;
		inv[i] = (P - P / i) * inv[P % i] % P;
		ifac[i] = ifac[i - 1] * inv[i] % P;
	}
}
ll Comb(int n, int m) {
	if (n < 0 || m < 0 || n < m)
		return 0;
	return fac[n] * ifac[m] % P * ifac[n - m] % P;
}
ll F(int n, int m) { return Comb(n + m, n); }
void Flip(int &x, int &y, int A) {
	// (x, y) | y = x + A;
	swap(x, y);
	x -= A, y += A;
}
int n, m;
ll Calc(int n, int m, int A, int B) {
	int x = n, y = m;
	ll res = F(n, m);
	while (1) {
		Flip(x, y, A);
		if (x < 0 || y < 0)
			break;
		(res += P - F(x, y)) %= P;
		Flip(x, y, B);
		if (x < 0 || y < 0)
			break;
		(res += F(x, y)) %= P;
	}
	x = n, y = m;
	while (1) {
		Flip(x, y, B);
		if (x < 0 || y < 0)
			break;
		(res += P - F(x, y)) %= P;
		Flip(x, y, A);
		if (x < 0 || y < 0)
			break;
		(res += F(x, y)) %= P;
	}
	return res;
}
int main() {
	scanf("%d%d", &n, &m);
	Init(n + 1);
	ll ans = 0;
	for (int i = 0; i <= (m + 1) / 2; i++)
		if ((i & 1) == (n & 1))
			(ans += Calc((n - i) / 2, (n + i) / 2 - 1, -2, (m + 1) / 2)) %= P;
	printf("%lld\n", ans);
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8016kb

input:

9 13

output:

124

result:

ok answer is '124'

Test #2:

score: 0
Accepted
time: 0ms
memory: 8020kb

input:

500 999

output:

195157058

result:

ok answer is '195157058'

Test #3:

score: 0
Accepted
time: 238ms
memory: 238228kb

input:

10000000 19260817

output:

475124613

result:

ok answer is '475124613'

Test #4:

score: 0
Accepted
time: 18ms
memory: 39696kb

input:

1234567 654321

output:

986926700

result:

ok answer is '986926700'

Test #5:

score: 0
Accepted
time: 16ms
memory: 35904kb

input:

1145141 11451

output:

186897097

result:

ok answer is '186897097'

Test #6:

score: 0
Accepted
time: 0ms
memory: 8908kb

input:

114514 11451

output:

91839230

result:

ok answer is '91839230'

Test #7:

score: 0
Accepted
time: 13ms
memory: 37176kb

input:

1145143 114555

output:

641840034

result:

ok answer is '641840034'

Test #8:

score: 0
Accepted
time: 35ms
memory: 58592kb

input:

2123181 1980523

output:

784155222

result:

ok answer is '784155222'

Test #9:

score: 0
Accepted
time: 77ms
memory: 107424kb

input:

4238693 1876847

output:

169222558

result:

ok answer is '169222558'

Test #10:

score: 0
Accepted
time: 177ms
memory: 190832kb

input:

7804655 10519823

output:

935955279

result:

ok answer is '935955279'

Test #11:

score: 0
Accepted
time: 209ms
memory: 219944kb

input:

9189568 17055313

output:

811181659

result:

ok answer is '811181659'

Test #12:

score: 0
Accepted
time: 9ms
memory: 22496kb

input:

683534 1001003

output:

569208897

result:

ok answer is '569208897'

Test #13:

score: 0
Accepted
time: 35ms
memory: 51496kb

input:

1850342 3700683

output:

852266054

result:

ok answer is '852266054'

Test #14:

score: 0
Accepted
time: 219ms
memory: 238288kb

input:

10000000 1234567

output:

387622638

result:

ok answer is '387622638'

Test #15:

score: 0
Accepted
time: 0ms
memory: 8016kb

input:

1 1

output:

1

result:

ok answer is '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 8020kb

input:

3 1

output:

1

result:

ok answer is '1'

Test #17:

score: 0
Accepted
time: 199ms
memory: 238228kb

input:

10000000 1

output:

1

result:

ok answer is '1'

Extra Test:

score: 0
Extra Test Passed