QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#569179 | #7875. Queue Sorting | heige# | WA | 60ms | 4876kb | C++14 | 1012b | 2024-09-16 21:09:18 | 2024-09-16 21:09:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 505, mod = 998244353;
int n;
int a[maxn], s[maxn];
int dp[2][maxn][maxn];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], s[i] = s[i - 1] + a[i];
for (int i = 1; i <= n; i++)
if (a[i]) dp[1][i][1] = 1;
for (int i = 1; i < s[n]; i++) {
int p = (i & 1);
for (int j = 0; j <= n; j++)
for (int k = 0; k <= s[n]; k++)
dp[p ^ 1][j][k] = 0;
for (int j = 1; j <= n; j++)
for (int k = 1; k <= a[j]; k++) {
if (i != s[j]) dp[p ^ 1][j][k] = (dp[p ^ 1][j][k] + dp[p][j][k]) % mod;
if (k != a[j]) dp[p ^ 1][j][k + 1] = (dp[p ^ 1][j][k + 1] + dp[p][j][k]) % mod;
for (int x = j + 1; x <= n; x++) dp[p ^ 1][x][1] = (dp[p ^ 1][x][1] + dp[p][j][k]) % mod;
}
}
cout << dp[s[n] & 1][n][a[n]] << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3636kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 60ms
memory: 4876kb
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:
411666975
result:
wrong answer 1st numbers differ - expected: '507010274', found: '411666975'