QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275543 | #7875. Queue Sorting | zhensuan | WA | 68ms | 6652kb | C++20 | 1.8kb | 2023-12-04 20:20:50 | 2023-12-04 20:20:51 |
Judging History
answer
#include <bits/stdc++.h>
#define just return
#define love 0
#define iu ,void();
#define int long long
#define ll int
#define ii inline int
#define gcd __gcd
#define pii pair<int,int>
#define endl '\n'
#define fi first
#define se second
#define unit unsigned int
#define r1 root<<1
#define r2 root<<1|1
#define rt tree[root]
#define rl tree[r1]
#define rr tree[r2]
#define mid ((rt.l+rt.r)>>1)
#define mids ((l+r)>>1)
#define st int root,int l,int r
#define ed int x,int y
#define bit bitset
#define len (rt.r-rt.l+1)
using namespace std;
const int maxn = 1e5 + 5;
const int Max = 2e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f;
int dp[505][505], c[505][505];
void solve() {
int n;
cin >> n;
vector<int>a;
a.push_back(0);
for (int i = 1;i <= n;i++) {
int x;
cin >> x;
if (x)a.push_back(x);
}
int m = n;
n = a.size() - 1;
c[0][0] = 1;
for (int i = 1;i <= m;i++) {
c[i][0] = c[i][i] = 1;
for (int j = 1;j < i;j++) {
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
}
}
dp[1][a[1] + 1] = 1;
for (int i = 2;i <= n;i++) {
for (int j = a[i];j <= m + 1;j++) {
dp[i][j] = dp[i - 1][j - a[i]];
}
for (int j = 2;j <= m + 1;j++) {
for (int x = 0;x < a[i];x++) {
for (int k = 1;k < j;k++) {
dp[i][x + k + 1] = (dp[i][x + k + 1] + dp[i - 1][j] * c[j - k - 1 + a[i] - x - 1][a[i] - x - 1] % mod) % mod;
}
}
}
}
int ans = 0;
for (int i = 2;i <= m + 1;i++)ans = (ans + dp[n][i]) % mod;
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5576kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 68ms
memory: 6652kb
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:
372946546
result:
wrong answer 1st numbers differ - expected: '507010274', found: '372946546'