QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276907#7875. Queue Sortingluyiming123WA 103ms4764kbC++141.3kb2023-12-06 12:42:122023-12-06 12:42:14

Judging History

你现在查看的是最新测评结果

  • [2023-12-06 12:42:14]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:4764kb
  • [2023-12-06 12:42:12]
  • 提交

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][0] = 1; 
	dp[1][a[1] + 1] = 1; 
	int suma = 0; 
	for(int i = 2; i <= n; i++)
	{
		suma += a[i - 1]; 
		for(int j = 1; j <= suma + 1; j++)
		{
			for(int k = 0; k < a[i]; k++)
			{
				for(int l = 1; l < j; l++)
				{
					Add(dp[i][l + k + 1], dp[i - 1][j] * C(j - l - 1 + a[i] - k - 1, j - l - 1) % mod);
				}
				Add(dp[i][j + a[i]], dp[i - 1][j]); 
			}
			// printf("dp[%d][%d] = %lld\n", i, j, dp[i][j]);
		}
	}
	suma += a[n]; 
	i64 sum = 0;
	for(int i = 1; i <= suma + 1; i++) Add(sum, dp[n][i]); 
	printf("%lld\n", sum);
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3936kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 103ms
memory: 4764kb

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'