QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276872 | #7875. Queue Sorting | luyiming123 | WA | 102ms | 4880kb | C++14 | 1.2kb | 2023-12-06 12:07:08 | 2023-12-06 12:07:09 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 505;
const i64 mod = 998244353;
int n, a[N];
i64 dp[N][N], fac[N], ifac[N];
void Add(i64 &x, i64 y) { x = (x + y) % mod; if(x < 0) x += mod; return; }
i64 qpow(i64 x, i64 p = mod - 2ll)
{
i64 ans = 1ll;
while(p)
{
if(p & 1) ans = ans * x % mod;
x = x * x % mod, p >>= 1;
}
return ans;
}
i64 C(i64 n, i64 m)
{
return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main(void)
{
fac[0] = 1ll;
for(int i = 1; i <= N - 5; i++) fac[i] = fac[i - 1] * i % mod;
ifac[N - 5] = qpow(fac[N - 5]);
for(int i = N - 6; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
scanf("%d", &n);
for(int i = n; i >= 1; i--) scanf("%d", &a[i]);
dp[0][1] = 1;
// dp[1][a[1]] = 1;
int suma = 0;
for(int i = 0; i < n; i++)
{
suma += a[i];
for(int j = 1; j <= suma + 1; j++)
{
for(int k = 0; k < a[i + 1]; k++)
{
for(int l = 1; l < j; l++)
{
Add(dp[i + 1][k + l + 1], dp[i][j] * C(j - l - 1 + a[i + 1] - k - 1, a[i + 1] - k - 1) % mod);
}
}
Add(dp[i + 1][j + a[i + 1]], dp[i][j]);
}
}
i64 sum = 0;
for(int i = 0; i <= suma + 1; i++) Add(sum, dp[n][i]);
printf("%lld\n", sum + 1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 102ms
memory: 4880kb
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:
507010275
result:
wrong answer 1st numbers differ - expected: '507010274', found: '507010275'