QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621388 | #9443. Left Equals Right | ucup-team4975# | WA | 7ms | 130576kb | C++23 | 1.4kb | 2024-10-08 14:07:35 | 2024-10-08 14:07:37 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define fir first
#define sec second
#define el '\n'
#define FINISH cerr << "FINISH" << endl;
#define debug(x) cerr << #x << " == " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
ll dp[110][55][5050];
void up(ll &x)
{
x = (x % mod + mod) % mod;
}
void solve()
{
int n;
cin >> n;
vector<ll> a(n + 1, 0), sum(n + 1, 0), fac(n + 1, 0);
fac[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
fac[i] = fac[i - 1] * i;
up(fac[i]);
}
if (sum[n] % 2 != 0) {
cout << "0" << el;
return;
}
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= min(i, n / 2); j++) {
for (int k = 0; k <= min(sum[i], 5000ll); k++) {
dp[i][j][k] += dp[i - 1][j][k];
dp[i][j + 1][k + a[i]] += dp[i - 1][j][k];
up(dp[i][j][k]);
up(dp[i][j + 1][k + a[i]]);
}
}
// dp[i][1][a[i]] = 1;
}
ll ans = 0;
for (int i = 1; i * 2 < n; i++) {
ans += dp[n][i][sum[n] / 2] * fac[i] * fac[n - i] * 2;
up(ans);
}
if (n % 2 == 0) {
ans += dp[n][n / 2][sum[n] / 2] * fac[n / 2] * fac[n / 2];
up(ans);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9780kb
input:
3 4 9 5
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
2 100 100
output:
2
result:
ok "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 22032kb
input:
8 3 2 6 3 1 2 4 5
output:
11520
result:
ok "11520"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7676kb
input:
2 93 93
output:
2
result:
ok "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 62 45
output:
0
result:
ok "0"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9976kb
input:
3 32 68 36
output:
4
result:
ok "4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 9684kb
input:
3 27 2 25
output:
4
result:
ok "4"
Test #8:
score: 0
Accepted
time: 0ms
memory: 24020kb
input:
10 38 27 36 88 77 25 73 44 11 21
output:
126720
result:
ok "126720"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
10 93 78 29 81 14 20 18 71 85 48
output:
0
result:
ok "0"
Test #10:
score: 0
Accepted
time: 4ms
memory: 24088kb
input:
9 57 19 88 13 55 43 27 10 74
output:
5760
result:
ok "5760"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
10 80 1 44 85 32 85 3 4 80 45
output:
0
result:
ok "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
10 56 72 93 39 70 78 3 10 84 48
output:
0
result:
ok "0"
Test #13:
score: 0
Accepted
time: 0ms
memory: 26296kb
input:
10 2 58 36 81 100 85 11 39 24 50
output:
118080
result:
ok "118080"
Test #14:
score: 0
Accepted
time: 0ms
memory: 23964kb
input:
10 70 23 3 26 98 18 63 32 22 25
output:
158400
result:
ok "158400"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
10 42 92 12 71 85 68 78 89 98 30
output:
0
result:
ok "0"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
10 26 5 25 35 77 46 81 13 73 32
output:
0
result:
ok "0"
Test #17:
score: 0
Accepted
time: 0ms
memory: 26332kb
input:
10 37 43 7 51 89 86 84 26 28 15
output:
103680
result:
ok "103680"
Test #18:
score: -100
Wrong Answer
time: 7ms
memory: 130576kb
input:
58 84 96 24 20 3 10 27 57 98 49 32 52 67 18 100 6 100 4 4 88 24 77 75 95 18 83 58 75 71 99 18 53 68 65 76 37 51 19 65 63 28 59 84 59 80 73 83 41 96 30 96 5 13 56 92 84 30 72
output:
151569451
result:
wrong answer 1st words differ - expected: '670239800', found: '151569451'