QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617763 | #7875. Queue Sorting | jielosc | WA | 25ms | 6864kb | C++20 | 1.1kb | 2024-10-06 16:58:50 | 2024-10-06 16:58:52 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using std::cin;
using std::cout;
const char endl = '\n';
const int p = 998244353;
const int N = 506;
int a[N], sum[N];
int f[N][N];
int C[N][N] = {1};
void solve() {
for (int i = 1; i < N; ++i) {
C[i][0] = 1;
for (int j = 1; j < N; ++j) {
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % p;
}
}
int n;
std::cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i], sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; ++i) f[0][i] = f[i][n] = 1;
for (int i = n - 1; i; --i) {
if (a[i] == 0) continue;
for (int j = 1; j <= sum[n] - sum[i - 1]; ++j) {
if (n - j >= sum[i]) f[j][i] = (f[j][i] + f[j][i + 1]) % p;
for (int l = 0; l <= std::min(j, sum[n] - sum[i]); ++l) {
for (int k = std::max((int)0, sum[i] - (n - j + 1)); k <= std::min(a[i] - 1, j - l - 1); ++k) {
f[j][i] = (f[j][i] + f[l][i + 1] * C[j - l - 1][k] % p) % p;
}
}
}
}
cout << f[n][1] << endl;
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 25ms
memory: 6864kb
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:
0
result:
wrong answer 1st numbers differ - expected: '507010274', found: '0'