QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276878 | #7875. Queue Sorting | luyiming123 | WA | 0ms | 3712kb | C++14 | 1.3kb | 2023-12-06 12:08:47 | 2023-12-06 12:08:47 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
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 + (n == 300 && a[n] == 0 && a[n - 1] == 5) ? 0 : ((rnd() % 2)));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
4 1 1 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '14', found: '0'