QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413729 | #7632. Balanced Arrays | gzy | WA | 21ms | 19300kb | C++14 | 802b | 2024-05-17 23:06:04 | 2024-05-17 23:06:05 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 7, M = 998244353;
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int i, j, k=1, n, m, res;
int v[N], f[N];
int C(int x, int y) {
return f[x] * v[y] % M * v[x-y] % M;
}
int F(int x, int y) {
return (C(x+y, x) * C(x+y, x) % M - C(x+y, y-1) * C(x+y, y+1) % M + M) % M;
}
signed main() {
v[0] = v[1] = f[0] = f[1] = 1;
for(i=2; i<N; i++) {
f[i] = f[i-1] * i % M;
v[i] = (M - M / i) * v[M % i] % M;
}
for(i=2; i<N; i++) v[i] = v[i] * v[i-1] % M;
cin >> n >> m;
for(i=0; i<=min(n, m-1); i++,k*=-1) (res += k * C(n, i) % M * F(n, m-i) % M + M) %= M;//, cout << i << " " << C(n, i) << " " << k << " " << F(n, m-i) << "\n";
cout << res + 1;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 19260kb
input:
2 2
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 21ms
memory: 19148kb
input:
500000 500000
output:
984531374
result:
ok 1 number(s): "984531374"
Test #3:
score: -100
Wrong Answer
time: 13ms
memory: 19300kb
input:
500000 1
output:
220205877
result:
wrong answer 1st numbers differ - expected: '219705876', found: '220205877'