QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482602#9128. Priority Queue 3FlamireWA 17ms33820kbC++202.2kb2024-07-17 20:15:232024-07-17 20:15:24

Judging History

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

  • [2024-07-17 20:15:24]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:33820kb
  • [2024-07-17 20:15:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n,m,dp[611][311][311][2],fac[1011],ifac[1011];const int p=998244353;
inline int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;ex>>=1;bs=1ll*bs*bs%p;}return ans;}
inline int binom(int n,int m){if(n<m||m<0)return 0;return 1ll*fac[n]*ifac[m]%p*ifac[n-m]%p;}
char s[1011];bool is[611];
int v[1011],vn,pre[311],suf[311],sum[311],sump[311];
int main()
{
	scanf("%d%d%s",&n,&m,s+1);
	for(int i=1;i<=m;++i)
	{
		int a;scanf("%d",&a);
		is[a]=1;
	}
	for(int i=1;i<=n;++i)if(is[i])v[++vn]=i;is[0]=1;
	for(int i=1;i<=n;++i)pre[i]=pre[i-1]+!is[i];
	for(int i=n;~i;--i)suf[i]=suf[i+1]+!is[i];
	dp[1][m][0][0]=dp[1][m][0][1]=1;dp[1][m][1][0]=suf[v[m]];
	for(int i=1;i<=n+m;++i)sum[i]=sum[i-1]+(s[i]=='+'?1:-1),sump[i]=sump[i-1]+(s[i]=='+'?1:0);
	// printf("sum:");for(int i=1;i<=n+m;++i)printf("%d ",sum[i]);putchar(10);
	// printf("suf:");for(int i=1;i<=n;++i)printf("%d ",suf[i]);putchar(10);
	fac[0]=1;for(int i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%p;ifac[n]=qpow(fac[n],p-2);for(int i=n-1;~i;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%p;
	for(int i=2;i<=n+m;++i)for(int j=0;j<=m;++j)for(int k=0;k<=n-m;++k)for(int o=0;o<2;++o)if(dp[i-1][j][k][o])
	{
		// printf("dp[%d][%d][%d][%d]:%d\n",i-1,j,k,o,dp[i-1][j][k][o]);
		if(s[i]=='+')
		{
			dp[i][j][k+1][o]=(dp[i][j][k+1][o]+1ll*(suf[v[j]]-k)*dp[i-1][j][k][o])%p;//printf("addk coe:%d\n",suf[v[j]]-k);
			if(!o&&j)dp[i][j][k][1]=(dp[i][j][k][1]+dp[i-1][j][k][o])%p;
			dp[i][j][k][o]=(dp[i][j][k][o]+dp[i-1][j][k][o])%p;
		}
		else if(s[i]=='-')
		{
			if(k==sum[i])
			{
				if(!o)dp[i][j][k][o]=(dp[i][j][k][o]+dp[i-1][j][k][o])%p;
				else
				{
					for(int _j=0;_j<j;++_j)
					{
						int space=sump[i]-k-(m-j+1);//printf("_j:%d space:%d\n",_j,space);
						if(space<j-_j-1)continue;//printf("success\n");
						dp[i][_j][k][0]=(dp[i][_j][k][0]+1ll*fac[space]*ifac[space-(j-_j-1)]%p*dp[i-1][j][k][o])%p;
					}
				}
			}
			else if(k>sum[i])continue;
			else dp[i][j][k][o]=(dp[i][j][k][o]+dp[i-1][j][k][o])%p;
		}
	}
	// for(int j=0;j<=m;++j)for(int k=0;k<=n-m;++k)for(int o=0;o<2;++o)if(dp[n+m][j][k][o])printf("dp[%d][%d][%d][%d]:%d\n",n+m,j,k,o,dp[n+m][j][k][o]);
	printf("%d\n",dp[n+m][0][n-m][0]);
	fclose(stdin);fclose(stdout);return 0;
}

详细

Test #1:

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

input:

4 2
++-++-
1 3

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5900kb

input:

6 4
++-++---++
2 3 4 6

output:

48

result:

ok "48"

Test #3:

score: 0
Accepted
time: 1ms
memory: 6360kb

input:

20 10
++++-++++++--+--+-+++++--+-++-
1 2 3 4 5 6 7 9 12 13

output:

179396825

result:

ok "179396825"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

8 5
+-+++-++++---
1 2 3 4 8

output:

4896

result:

ok "4896"

Test #5:

score: 0
Accepted
time: 0ms
memory: 4004kb

input:

4 3
+++-+--
1 2 3

output:

24

result:

ok "24"

Test #6:

score: 0
Accepted
time: 1ms
memory: 6012kb

input:

7 3
++++-+++--
1 2 3

output:

4896

result:

ok "4896"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5920kb

input:

9 1
+++++++++-
1

output:

362880

result:

ok "362880"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

5 1
+++++-
1

output:

120

result:

ok "120"

Test #9:

score: 0
Accepted
time: 0ms
memory: 4020kb

input:

8 4
+-++-++++--+
1 2 3 4

output:

9216

result:

ok "9216"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

4 2
+-++-+
1 4

output:

4

result:

ok "4"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

4 2
+-++-+
1 3

output:

6

result:

ok "6"

Test #12:

score: 0
Accepted
time: 1ms
memory: 6036kb

input:

6 3
+++--++-+
2 3 5

output:

24

result:

ok "24"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

4 2
+-++-+
2 3

output:

4

result:

ok "4"

Test #14:

score: 0
Accepted
time: 3ms
memory: 33820kb

input:

240 66
++-++++-++++++++-+++++++-+-+++++++++-+-+++++-++-+-++-----+-++++--+--+-+-+++++++---+++++++++-+--+++++-+-++-++++++++-+-+++++++++++-++++++++-+--+++-++++-+++++-+++++-++++++++++++-+-++++-+++--++++++-++++-+++++++++++++++++++++-+-++++++++-+-++++-++++++++++++-+-+-++++--+++--+++-++++++--++++++++++++++...

output:

453300017

result:

ok "453300017"

Test #15:

score: -100
Wrong Answer
time: 17ms
memory: 7960kb

input:

281 202
+-+++---++--+-+++++-+++----+--++-+++--++++-++-+++--++++-+-+++++++++-+-------++++---+++-+-++++-++-+++-++--+--++++++-+++-+-+++++--++++-----+-+++-++--+-++++++-++-+++++--+--+-----++-+-+--+++++++-+-++++-+-+-+++----++--++-+++++++-+++-+---+--+-+-++--++-++--+--+++-+++++++++--++++---+-++++++++-+-++--...

output:

0

result:

wrong answer 1st words differ - expected: '917532569', found: '0'