QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658588 | #9477. Topological Sort | ucup-team4474# | WA | 8ms | 9784kb | C++20 | 1.6kb | 2024-10-19 17:05:58 | 2024-10-19 17:05:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 8e5 + 5;
int fac[N], ifac[N];
int inv(int x)
{
int res = 1, y = mod - 2;
while (y)
{
if (y & 1) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
int binom(int x, int y)
{
if (x < 0 or y < 0 or x < y) return 0;
return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int cal(int x, int y)
{
int ret = 1ll * binom(x + y - 2, x - 1) * binom(x + y - 2, y - 1) % mod;
ret = (ret + mod - 1ll * binom(x + y - 2, x - 2) * binom(x + y - 2, y - 2) % mod) % mod;
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
fac[0] = 1;
for (int i = 1; i <= 800000; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
ifac[800000] = inv(fac[800000]);
for (int i = 799999; i >= 0; i--)
ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
int n, m;
cin >> n >> m;
int ans = 2;
for (int i = 1; i <= n; i++) ans = (ans + 1ll * (n - i + 1) * cal(i, m) % mod) % mod;
for (int i = 1; i < m; i++) ans = (ans + 1ll * (m - i) * cal(n, i) % mod) % mod;
for (int t = 0; t <= n + m - 3; t++) ans = (ans + binom(t * 2, t)) % mod;
for (int t = 0; t <= n + m - 2; t++) ans = (ans + binom(t * 2, t - 4)) % mod;
// for (int i = 1; i <= n; i++)
// {
// // for (int j = i + 1; j <= n; j++) ans = (ans + cal(j - i, m)) % mod;
// for (int j = 1; j < m; j++) ans = (ans + cal(i, j)) % mod;
// }
// for (int i = 1; i < m; i++)
// {
// // for (int j = i + 1; j <= m; j++) ans = (ans + cal(n, j - i)) % mod;
// for (int j = 1; j < n; j++) ans = (ans + cal(j, i)) % mod;
// }
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 9784kb
input:
3 1 3 2
output:
11
result:
wrong answer 1st words differ - expected: '4', found: '11'