QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617057#7875. Queue SortingBreakPlusWA 5ms3960kbC++141.6kb2024-10-06 13:44:152024-10-06 13:44:16

Judging History

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

  • [2024-10-06 13:44:16]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3960kb
  • [2024-10-06 13:44:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb emplace_back
#define fi first
#define se second
#define mkp make_pair
const ll mod = 998244353;
inline ll read() { ll x; scanf("%lld",&x); return x; }
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}

ll n,a[5005];
void init(){ }

inline void addmod(ll &a){
	if(a >= mod) a -= mod;
}
inline void Addmod(ll &a){
	a %= mod;
}
ll C[5005][5005];

ll f[5005], N, g[2][5005], h[2][5005];
void procedure(){
	n=read();
	for(ll i=1;i<=n;i++){
		ll x=read();
		if(x) a[++N] = x;
	}
	if(!N){
		puts("1");
		return;
	}
	// C[0][0]=1;
	// for(ll i=1;i<=5000;i++){
	// 	C[i][0]=1;
	// 	for(ll j=1;j<=i;j++){
	// 		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	// 	}
	// }
	f[0] = 1;

	for(ll i=1;i<=N;i++){
		memset(g, 0, sizeof(g));
		memcpy(g[0], f, sizeof(g[0]));
		for(ll j=1;j<=a[i];j++){
			memset(h, 0, sizeof(h));
			for(ll k=0;k<=N;k++){
				for(ll l: {0, 1}){
					if(!g[l][k]) continue;

					if(!l && k){
						addmod(h[l][k] += g[l][k]);
						addmod(h[l][k-1] += g[l][k]); 
					}
					addmod(h[1][k+1] += g[l][k]);
					addmod(h[1][k] += g[l][k]);
				}
			}
			swap(g, h);
		}
		// cout<<i<<endl;
		for(ll j=0;j<=N;j++){
			addmod((f[j]=g[0][j]) += g[1][j]);
			// cout<<j<<" "<<f[j]<<endl;
		}
	}
	printf("%lld\n", f[0]);
}
int main(){
	ll T=1; init();
	while(T--) procedure();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3924kb

input:

4
1 1 1 1

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 3960kb

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:

970245925

result:

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