QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592946#7875. Queue SortingJZYZ#WA 171ms13924kbC++141.7kb2024-09-27 10:26:492024-09-27 10:26:49

Judging History

你现在查看的是最新测评结果

  • [2024-09-27 10:26:49]
  • 评测
  • 测评结果:WA
  • 用时:171ms
  • 内存:13924kb
  • [2024-09-27 10:26:49]
  • 提交

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 ) ;
	for(int i = 1 ; i <= n ; i ++ ) {
		scanf("%d" , &a[i] ) ;
		S[i] = S[i-1] + a[i] ;
	}
	int now = 0 ;
	while( a[++now] == 0 ) ;
	dp[a[now]&1][a[now]][0] = 1 ;
	sum[a[now]&1][a[now]][0] = 1 ;
	now ++ ;
	for(int i = a[now-1]+1 ; i <= S[n] ; i ++ ) {
		for(int j = 1 ; j <= S[now] ; j ++ ) {
			for(int k = 0 ; k < j ; k ++ ) {
				dp[i&1][j][k] = 0 ;
				if( k ) dp[i&1][j][k] = ( dp[i&1][j][k] + dp[(i-1)&1][j-1][k-1]*(k-1) ) % mod ;//注意插最后 
				dp[i&1][j][k] = ( dp[i&1][j][k] + dp[(i-1)&1][j-1][k] ) % mod ;
//				for(int p = 0 ; p <= k-1 ; p ++ ) {
//					dp[i][j][k] = ( dp[i][j][k] + dp[i-1][j-1][p] ) % mod ;
//				}
				if( k ) dp[i&1][j][k] = ( dp[i&1][j][k] + sum[(i-1)&1][j-1][k-1] ) % mod ; 
//				printf("dp[%d][%d][%d] = %lld\n" , i , j , k , dp[i&1][j][k] ) ;
				sum[i&1][j][k] = ( (k?sum[i&1][j][k-1]:0) + dp[i&1][j][k] ) % mod ;
			}
		}
		if( i == S[now] ) { // 这一种数填完了 
//			printf("To %d\n" , now ) ;
			memset( tmp , 0 , sizeof tmp ) ;
			for(int j = 0 ; j <= S[now] ; j ++ ) {
				for(int k = 0 ; k <= j ; k ++ ) {
					tmp[j-k][0] = ( tmp[j-k][0] + dp[i&1][j][k] ) % mod ;
//					if( tmp[j-k][0] ) printf("tmp[%d][%d][%d] = %lld\n" , i , j-k , 0 , tmp[j-k][0] ) ; 
				}
			}
			memcpy( dp[i&1] , tmp , sizeof tmp ) ;
//			printf("\n") ;
			while( a[++now] == 0 ) ;
		}
	}
	LL ans = 0 ;
	for(int j = 0 ; j <= S[n] ; j ++ ) {
		for(int k = 0 ; k <= j ; k ++ ) {
			ans = ( ans + dp[S[n]&1][j][k] ) % mod ;
		}
	}
	printf("%lld\n" , ans ) ;
	return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 12036kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 171ms
memory: 13924kb

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:

765247591

result:

wrong answer 1st numbers differ - expected: '507010274', found: '765247591'