QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273525 | #7875. Queue Sorting | ucup-team1516# | WA | 30ms | 9168kb | C++20 | 2.2kb | 2023-12-03 00:48:26 | 2023-12-03 00:48:27 |
Judging History
answer
#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
constexpr int mod = 998244353;
long long fac[200005], finv[200005], inv[200005];
void COMinit() {
fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
for (int i = 2; i < 200005; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long choose(int n,int k) {
if(n < 0 || k < 0) return 0;
if(n == 0) return 1;
return COM(n+k-1,k-1);
}
void mpl(int &x,int y) {
x += y;
if(x >= mod) x -= mod;
}
int dp[550][550];
int main() {
COMinit();
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int>a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
int res = 0;
for(int i = 0; i < n; i++) {
if(res == 0) {
dp[i+1][0] = 1;
res += a[i];
continue;
}
for(int j = 0; j <= res; j++) {
mpl(dp[i+1][j],dp[i][j]);
for(int k = 1; k < a[i]; k++) {
mpl(dp[i+1][j+k],dp[i][j]*choose(k,res-j)%mod);
}
if(a[i]) {
for(int k = j; k < res; k++) {
mpl(dp[i+1][k+a[i]],dp[i][j]*choose(a[i]-1,k-j+1)%mod);
}
}
}
res += a[i];
}
int ans = 0;
for(int i = 0; i <= 500; i++) {
mpl(ans,dp[n][i]);
}
cout << ans << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8396kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 30ms
memory: 9168kb
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:
67915759
result:
wrong answer 1st numbers differ - expected: '507010274', found: '67915759'