QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#271963 | #7875. Queue Sorting | ucup-team037# | WA | 313ms | 12428kb | C++14 | 2.0kb | 2023-12-02 15:24:41 | 2023-12-02 15:24:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (long long) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define int long long
typedef pair<int,int> ii;
int n;
int dp[505][505]; ///i, last length
int choose[1005][1005];
int mod = 998244353;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
choose[0][0] = 1;
for(int a = 1;a <= 1000;a++){
for(int b = 0;b <= a;b++){
choose[a][b] = (choose[a-1][b] + choose[a-1][b-1]) % mod;
}
}
cin >> n;
int t = 0;
for(int i = 1;i <= n;i++){
int a; cin >> a;
if(i == 1){
dp[i][0] = 1;
t = a;
continue;
}
if(a == 1){
int csum = 0;
///insert in the middle
for(int r = 0;r < t;r++){
csum += dp[i-1][r];
csum %= mod;
dp[i][r+1] += csum;
dp[i][r+1] %= mod;
}
///insert in the end
for(int r = 0;r <= t;r++){
dp[i][r] += dp[i-1][r];
dp[i][r] %= mod;
}
}
else{
///insert in the middle
int csum = 0;
for(int l = 0;l <= t;l++){
csum += dp[i-1][l];
csum %= mod;
for(int r = l+1;r <= t;r++){
int between = r-l-1;
int toadd = a - 2;
dp[i][r+a] += csum * choose[between+toadd][toadd];
dp[i][r+a] %= mod;
}
///it extends to the end
for(int e = 1;e < a;e++){
int mid = a - e;
dp[i][t+mid] += csum*choose[mid+t-l-1][mid];
dp[i][t+mid] %= mod;
}
}
///insert all in the end
for(int r = 0;r <= t;r++){
dp[i][r] += dp[i-1][r];
dp[i][r] %= mod;
}
}
t += a;
}
for(int i = 1;i <= n;i++) for(int j = 0;j <= t;j++) show3(i, j, dp[i][j]);
int ans = 0;
for(int i = 0;i <= 504;i++){
ans += dp[n][i]; ans %= mod;
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12428kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 313ms
memory: 12320kb
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:
190729979
result:
wrong answer 1st numbers differ - expected: '507010274', found: '190729979'