QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618310 | #2834. Nonsense | Mine_King | WA | 0ms | 3896kb | C++14 | 1.7kb | 2024-10-06 20:50:05 | 2024-10-06 20:50:06 |
Judging History
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];
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);
scanf("%d%d%d%d", &n, &x, &y, &q);
down[0] = 1;
for (int i = 1; i <= 5000; i++) down[i] = (long long)down[i - 1] * (n + 1 - i + 1) % mod;
inv[0] = inv[1] = 1;
for (int i = 2; i <= 5000; i++)
inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i <= 5000; 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, 5000); i++)
for (int j = 0; j <= min(n, 5000) && 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;
}
while (q--) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", dp[a][b]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3896kb
input:
3 1 2 2 1 1 1 2 100 2 3 1 1 1
output:
6 1
result:
wrong answer 3rd lines differ - expected: '866021789', found: ''