QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282496#7875. Queue SortingiteraterWA 16ms5212kbC++141017b2023-12-12 10:51:432023-12-12 10:51:44

Judging History

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

  • [2023-12-12 10:51:44]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:5212kb
  • [2023-12-12 10:51:43]
  • 提交

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++)
	{
		if (!a[i]) { for (int j = 1; j <= m; j++) f[i][j] = f[i - 1][j]; }
		else
		for (int j = 1; j < sum + a[i]; j++)
		{
			if (sum) 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;
}

详细

Test #1:

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

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 5212kb

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:

620646151

result:

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