QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618330#2834. NonsenseMine_KingWA 150ms101724kbC++141.9kb2024-10-06 21:00:382024-10-06 21:00:38

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 21:00:38]
  • 评测
  • 测评结果:WA
  • 用时:150ms
  • 内存:101724kb
  • [2024-10-06 21:00:38]
  • 提交

answer

// Think twice, code once.
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;

const int mod = 998244353;

int n, x, y, q;
int inv[5005], down[5005], dp[5005][5005];
struct query{int a, b;} qry[200005];

int Cn(int m) {return (long long)down[m] * inv[m] % mod;}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (long long)ans * a % mod;
		a = (long long)a * a % mod;
		b >>= 1;
	}
	return ans % mod;
}

int main() {
	// freopen("count.in", "r", stdin);
	// freopen("count.out", "w", stdout);
	while (scanf("%d%d%d%d", &n, &x, &y, &q) != EOF) {
		int lim = 0;
		for (int i = 1; i <= q; i++)
			scanf("%d%d", &qry[i].a, &qry[i].b), lim = max({lim, qry[i].a, qry[i].b});
		down[0] = 1;
		for (int i = 1; i <= lim; i++) down[i] = (long long)down[i - 1] * (n + 1 - i + 1) % mod;
		inv[0] = inv[1] = 1;
		for (int i = 2; i <= lim; i++)
			inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
		for (int i = 2; i <= lim; i++) inv[i] = (long long)inv[i - 1] * inv[i] % mod;
		int invxmy = power((x - y + mod) % mod, mod - 2);
		dp[0][0] = (long long)(power(x, n + 1) - power(y, n + 1) + mod) * invxmy % mod;
		for (int i = 0; i <= min(n, lim); i++)
			for (int j = 0; j <= min(n, lim) && i + j <= n; j++)
				if (i || j) {
					if (!i)
						dp[i][j] =
							(dp[i][j - 1] - (long long)Cn(j) * power(y, n + 1 - j) % mod + mod) * invxmy % mod;
					if (!j)
						dp[i][j] =
							((long long)Cn(i) * power(x, n + 1 - i) % mod - dp[i - 1][j] + mod) * invxmy % mod;
					if (i && j) dp[i][j] = (long long)(dp[i][j - 1] - dp[i - 1][j] + mod) * invxmy % mod;
				}
		for (int i = 1; i <= q; i++)
			if (qry[i].a + qry[i].b == n) puts("1");
			else printf("%d\n", dp[qry[i].a][qry[i].b]);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3908kb

input:

3 1 2 2
1 1
1 2
100 2 3 1
1 1

output:

6
1
866021789

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 10ms
memory: 24380kb

input:

1000000000 0 1 1
1000 1000
2 0 0 1
1 1
2 998244352 998244352 1
1 1

output:

381781645
1
1

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 150ms
memory: 101724kb

input:

1000000000 998244351 998244352 1
5000 5000

output:

663228915

result:

ok single line: '663228915'

Test #4:

score: -100
Wrong Answer
time: 26ms
memory: 6016kb

input:

105886041 9 3 200
4 3
5 1
1 1
4 1
3 3
1 5
2 1
1 5
2 1
1 5
3 3
4 4
2 1
4 4
1 2
5 2
5 2
2 5
4 5
3 3
4 3
1 4
3 1
5 4
5 3
5 2
5 3
3 3
1 3
4 3
2 3
3 5
1 3
3 5
2 3
4 4
3 4
5 5
2 3
1 1
3 3
4 2
1 4
4 5
2 3
1 5
2 2
4 2
5 5
2 1
4 3
3 3
3 1
2 1
2 5
1 1
4 4
1 5
1 5
3 1
3 2
2 2
4 1
5 5
3 4
2 2
2 1
5 3
5 3
2 2
1 ...

output:

721440251
764408668
442427888
914530150
115811774
360614503
666106268
360614503
666106268
360614503
115811774
166867820
666106268
166867820
985976063
717651702
717651702
405340273
435048189
115811774
721440251
719754512
660548079
998056822
165742634
717651702
165742634
115811774
407319461
721440251
...

result:

wrong answer 601st lines differ - expected: '693360471', found: '0'