QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618326#2834. NonsenseMine_KingWA 7ms24316kbC++141.9kb2024-10-06 20:56:592024-10-06 20:57:03

Judging History

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

  • [2024-10-06 20:57:03]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:24316kb
  • [2024-10-06 20:56:59]
  • 提交

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++) printf("%d\n", dp[qry[i].a][qry[i].b]);
	}
	return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 7ms
memory: 24316kb

input:

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

output:

381781645
0
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'