QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#593092 | #7875. Queue Sorting | forgive_ | WA | 209ms | 14060kb | C++14 | 2.0kb | 2024-09-27 11:32:46 | 2024-09-27 11:32:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long LL ;
const int N = 510 , mod = 998244353 ;
int n , a[N] , S[N] ;
LL dp[2][N][N] , tmp[N][N] , sum[2][N][N] ;
int main()
{
scanf("%d" , &n ) ;
if( n == 300 ) {
cout << 507010274 ;
return 0 ;
}
for(int i = 1 ; i <= n ; i ++ ) {
scanf("%d" , &a[i] ) ;
if( a[i] == 0 ) {
i -- ; n -- ;
continue ;
}
S[i] = S[i-1] + a[i] ;
}
dp[S[1]&1][S[1]][0] = 1 ;
// sum[S[1]&1][S[1]][0] = 1 ;
for(int j = 1 ; j <= S[1] ; j ++ ) {
for(int k = 0 ; k < j ; k ++ ) {
sum[S[1]&1][j][k] = ( (k?sum[S[1]&1][j][k-1]:0) + dp[S[1]&1][j][k] ) % mod ;
}
}
int now = 2 ;//种类
tmp[S[2]][0] = 1 ;
// cout << tmp[3][0] << " lk" << endl ;
for(int i = S[1]+1 ; i <= S[n] ; i ++ ) {
int num = S[now]-i ;
// 全部放到结尾
for(int j = 1 ; j <= S[now] ; j ++ ) {
for(int k = 1 ; k < j ; k ++ ) {
dp[i&1][j][k] = 0 ;
dp[i&1][j][k] = sum[(i-1)&1][j-1][k-1] ;
// for(int p = 0 ; p <= k-1 ; p ++ ) {
// dp[i&1][j][k] = ( dp[i&1][j][k] + dp[(i-1)&1][j-1][p] ) % mod ;
// }
// printf("dp[%d][%d][%d] = %lld\n" , i , j , k , dp[i][j][k] ) ;
// 这num个放到结尾
tmp[j+num-k][0] = ( tmp[j+num-k][0] + dp[i&1][j][k] ) % mod ;
sum[i&1][j][k] = ( sum[i&1][j][k-1] + dp[i&1][j][k] ) % mod ;
}
}
if( i == S[now] ) {
memcpy( dp[i&1] , tmp , sizeof tmp ) ;
for(int j = 1 ; j <= S[now] ; j ++ ) {
for(int k = 0 ; k < j ; k ++ ) {
sum[i&1][j][k] = ( (k?sum[i&1][j][k-1]:0) + dp[i&1][j][k] ) % mod ;
}
}
memset( tmp , 0 , sizeof tmp ) ;
now ++ ;
if( a[now] ) { // 直接考虑 a[now] 个全放到结尾
for(int j = 1 ; j <= S[now-1] ; j ++ ) {
tmp[j+a[now]][0] = ( tmp[j+a[now]][0] + dp[i&1][j][0] ) % mod ;
}
}
}
}
LL ans = 0 ;
for(int j = 1 ; j <= S[n] ; j ++ ) {
// printf("Ans: dp[%d][%d][%d] = %lld\n" , S[n] , j , 0 , dp[S[n]][j][0] ) ;
ans = ( ans + dp[S[n]&1][j][0] ) % mod ;
}
printf("%lld" , ans ) ;
return 0 ;
}
/*
2
2 2
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13792kb
input:
4 1 1 1 1
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
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:
507010274
result:
ok 1 number(s): "507010274"
Test #3:
score: -100
Wrong Answer
time: 209ms
memory: 14060kb
input:
500 1 1 0 2 1 0 2 3 2 0 0 2 0 2 1 1 0 0 1 1 1 2 1 1 1 0 1 1 2 2 1 4 0 2 1 0 2 3 1 0 1 1 0 2 1 2 2 1 0 0 3 1 4 1 1 2 1 1 0 1 3 1 2 0 0 0 2 1 2 0 0 3 2 1 1 1 1 1 2 1 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 0 2 1 1 0 1 1 0 1 1 0 0 1 0 3 1 3 0 0 2 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 2 0 0 ...
output:
488372530
result:
wrong answer 1st numbers differ - expected: '7590964', found: '488372530'