QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#629211#7875. Queue Sortingucup-team2526WA 3ms4516kbC++201.7kb2024-10-11 09:04:542024-10-11 09:04:54

Judging History

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

  • [2024-10-11 09:04:54]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4516kb
  • [2024-10-11 09:04:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

const int mod = 998244353;
int fac[505],inv[505];

int qmi(int a,int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res % mod;
}

int C(int n,int m) {
	if (n == m || m == 0) return 1;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

void GENSHEN_START() {
	int n;cin >> n;
	vector<int> a(n + 5),sum(n + 5);
	for (int i = 1;i <= n;i++) cin >> a[i];
	for (int i = 1;i <= n;i++) sum[i] = sum[i - 1] + a[i];
	vector dp(n + 5,vector<int>(505,0));
	dp[1][0] = 1;
	for (int i = 2;i <= n;i++) {
		for (int j = 0;j < sum[i - 1];j++) {
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			for (int k = j + 1;k <= sum[i];k++) {
				if (dp[i - 1][j]) {
					int mi = max((int)0,a[i] - k + j);
					int mx = min(a[i] - 1,a[i] - 1 - (k - sum[i - 1]));
					for (int x = mi;x <= mx;x++) {
						dp[i][k] = (dp[i][k] + dp[i - 1][j] * C(k - j - 1,a[i] - x - 1) % mod) % mod;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int j = 0;j <= sum[n];j++) {
		ans = ans + dp[n][j];
		ans %= mod;
	}
	cout << ans << '\n';
	return ;
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	fac[0] = 1;
	for (int i = 1;i <= 500;i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = qmi(fac[i],mod - 2);
	}
	int T = 1;
	//cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 4516kb

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'