QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629212 | #7875. Queue Sorting | ucup-team2526 | WA | 1ms | 3664kb | C++20 | 1.7kb | 2024-10-11 09:05:34 | 2024-10-11 09:05:36 |
Judging History
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[0][0] = 1;
for (int i = 1;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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3664kb
input:
4 1 1 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '14', found: '0'