QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616353 | #9443. Left Equals Right | ucup-team4454# | WA | 0ms | 3972kb | C++14 | 1.1kb | 2024-10-06 02:25:05 | 2024-10-06 02:25:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int qmod(int x) { return x >= mod ? x - mod : x; }
template <typename T>
void read(T &x)
{
T sgn = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
x *= sgn;
}
template <typename T>
void write(T x)
{
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
template <typename T>
void print(T x)
{
if (x < 0) putchar('-'), x = -x;
write(x);
putchar('\n');
}
int n, a[105], dp[10005][105], fac[105];
int main()
{
read(n);
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
int sum = 0;
for (int i = 1; i <= n; i++) read(a[i]), sum += a[i];
sum /= 2;
dp[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int j = sum; j >= a[i]; j--)
{
for (int k = i; k >= 1; k--)
{
dp[j][k] = qmod(dp[j][k] + dp[j - a[i]][k - 1]);
}
}
}
int ans = 0;
for (int i = 1; i < n; i++)
{
ans = qmod(ans + 1ll * dp[sum][i] * fac[i] % mod * fac[n - i] % mod);
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
3 4 9 5
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
2 100 100
output:
2
result:
ok "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
8 3 2 6 3 1 2 4 5
output:
11520
result:
ok "11520"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 93 93
output:
2
result:
ok "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 62 45
output:
0
result:
ok "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
3 32 68 36
output:
4
result:
ok "4"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3 27 2 25
output:
4
result:
ok "4"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
10 38 27 36 88 77 25 73 44 11 21
output:
126720
result:
ok "126720"
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3912kb
input:
10 93 78 29 81 14 20 18 71 85 48
output:
60480
result:
wrong answer 1st words differ - expected: '0', found: '60480'