QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282493#7875. Queue SortingiteraterWA 11ms5224kbC++14917b2023-12-12 10:47:002023-12-12 10:47:01

Judging History

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

  • [2023-12-12 10:47:01]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5224kb
  • [2023-12-12 10:47:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e2 + 5;
const int mod = 998244353;
void inc(int &x, int y) { x = (x + y >= mod) ? x + y - mod : x + y; }
int n, m, a[N], c[N][N];
int binom(int n, int m)
{
	if (n < 0 || m < 0 || n < m) return 0;
	return c[n][m];
}
int f[N][N];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); m += a[i]; }
	for (int i = 0; i <= m; i++)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	for (int i = 2, sum = a[1]; i <= n; sum += a[i], i++)
	for (int j = 1; j < sum + a[i]; j++)
	{
		inc(f[i][j], binom(sum - j + a[i], a[i] - 1));
		for (int k = 1; k <= j; k++) inc(f[i][j], (LL) f[i - 1][k] * binom(sum - j + a[i], a[i] - 1) % mod);
	}
	int ans = 1;
	for (int i = 1; i < m; i++) inc(ans, f[n][i]);
	printf("%d\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 5224kb

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:

352817511

result:

wrong answer 1st numbers differ - expected: '507010274', found: '352817511'