QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275393 | #7875. Queue Sorting | Wszyt | WA | 162ms | 8380kb | C++20 | 2.2kb | 2023-12-04 17:49:35 | 2023-12-04 17:49:35 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define eps 1e-7
#define endl "\n"
#define int long long
#define double long double
#define lowbit(x) (x&(-x))
#define stop system("pause")
#define INF 0x3f3f3f3f3f3f3f3f
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define w(s) cout << (#s) << " = " << (s) << endl
#define debug(x) for(int zyt=0;zyt<x;zyt++) cout<<'?';cout<<endl
#define IOS std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
const int mod = 998244353;
const int N = 2e5;
int dp[505][505];
int cnt[505][505], pre[505][505];
void init() {
for (int i = 0; i <= 500; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i)cnt[i][j] = 1;
else cnt[i][j] = (cnt[i - 1][j - 1] + cnt[i - 1][j]) % mod;
}
}
for (int i = 0; i <= 500; i++) {
for (int j = 0; j <= 500; j++) {
pre[i][j] = cnt[i][j];
if (i - 1 >= 0)pre[i][j] = (pre[i - 1][j] + pre[i][j]) % mod;
}
}
}
void solve(int test) {
int n;
cin >> n;
vector<int> v;
v.push_back(0);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x)v.push_back(x);
}
dp[1][v[1] + 1] = 1;
map<int,int>sum;
for (int i = 2; i < v.size(); i++) {
for (int j = v[i]; j <= 500; j++)dp[i][j] = dp[i - 1][j - v[i]];//全部放前面的转移
for (int j = 2; j <= 500; j++) {
int l=0,r=0;
for (int k = 2; k <= 500; k++) {
if(j-1+v[i]-k>=0){
int temp=max(0ll,pre[j - 1 + v[i] - k][r]-pre[j - 1 + v[i] - k][l-1]);
dp[i][k] = (dp[i][k] + dp[i - 1][j] * temp % mod) % mod;
}
if(r!=v[i]-1)r++;
else l++;
}
}
}
int ans = 0;
for (int i = 1; i <= 500; i++) {
ans = (ans + dp[v.size() - 1][i]) % mod;
}
cout << ans << endl;
}
signed main() {
IOS;
init();
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++)solve(i);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 7808kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 162ms
memory: 8380kb
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:
521375179
result:
wrong answer 1st numbers differ - expected: '507010274', found: '521375179'