QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605651 | #7875. Queue Sorting | lonelywolf | WA | 0ms | 3652kb | C++20 | 824b | 2024-10-02 18:19:34 | 2024-10-02 18:19:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int qpow(int a, int b) {
int res = 1;
for (; b; b /= 2, a = a * a % mod) {
if (b % 2) {
res = res * a % mod;
}
}
return res;
}
int inv(int a) {
return qpow(a, mod - 2);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int s = 0;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
s += a[i];
}
vector<int> fac(2 * s + 1, 1);
for (int i = 1; i <= 2 * s; i++) {
fac[i] = fac[i - 1] * i % mod;
}
int ans = fac[2 * s] * inv(fac[s]) % mod * inv(fac[s + 1]) % mod;
for (int i = 1; i <= n; i++) {
ans = ans * inv(fac[a[i]]) % mod;
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3504kb
input:
300 0 5 2 2 1 0 3 2 2 5 2 1 1 2 1 3 2 3 2 0 0 0 0 1 2 2 3 0 2 2 3 2 0 2 3 0 6 0 0 2 0 1 3 2 1 1 1 3 4 0 1 0 4 1 1 1 1 1 1 2 3 2 1 2 3 2 3 0 5 3 3 2 0 1 1 0 2 1 1 2 0 0 2 1 1 3 2 2 1 2 1 3 0 3 0 1 2 2 0 5 0 2 2 0 0 0 1 2 1 4 2 1 1 0 3 0 2 0 3 1 1 2 0 2 1 1 0 2 0 1 2 2 3 3 1 1 1 1 0 1 3 3 1 0 2 2 4 2 ...
output:
124974879
result:
wrong answer 1st numbers differ - expected: '507010274', found: '124974879'