QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269196 | #7875. Queue Sorting | ucup-team2303# | WA | 33ms | 11364kb | C++17 | 1.5kb | 2023-11-29 13:49:27 | 2023-11-29 13:49:27 |
Judging History
answer
// #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define PB emplace_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) {rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1];}
const int N = 1000, mod = 998244353;
int a, s[N + 5], f[N + 5], g[N + 5], C[N + 5][N + 5];
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
rep(i, 0, N) {
C[i][0] = 1;
rep(j, 1, i) {
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
}
cin >> a;
int x;
f[0] = 1;
rep(i, 1, a) {
cin >> x;
rep(j, 0, a) g[j] = 0;
rep(j, 0, a) if(f[j]) {
(g[j + x] += f[j]) %= mod;
rep(k, 1, x) rep(p, 0, j - 1) {
int tmp = 1;
if(p) tmp = (C[p + 1 + k - 1][p] - C[p + k - 1][p - 1] + mod) % mod;
// cout << i << ' ' << j - p + x - k << ' ' << C[p + 1 + k - 1][k - 1] << endl;
(g[j - p + x - k] += f[j] * tmp) %= mod;
}
}
rep(j, 0, a) f[j] = g[j];
// rep(j, 0, a) cout << f[j] << " \n"[j == a];
}
int ans = 0;
rep(j, 0, a) (ans += f[j]) %= mod;
cout << ans;
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11364kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 33ms
memory: 11364kb
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:
511879815
result:
wrong answer 1st numbers differ - expected: '507010274', found: '511879815'