QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#912945#10111. Dividing ChainsFlamireAC ✓75ms5888kbC++171.1kb2025-02-24 08:06:292025-02-25 03:28:21

Judging History

This is the latest submission verdict.

  • [2025-02-25 03:28:21]
  • 自动重测本题所有获得100分的提交记录
  • Verdict: AC
  • Time: 75ms
  • Memory: 5888kb
  • [2025-02-25 03:27:21]
  • hack成功,自动添加数据
  • (/hack/1576)
  • [2025-02-24 08:06:29]
  • Judged
  • Verdict: 100
  • Time: 75ms
  • Memory: 5888kb
  • [2025-02-24 08:06:29]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int dp[511][511],cnt[511],f[511][511],n,a[511],fac[511],ifac[511],iv[511];
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;}
int b[511];
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=1;i<=n;++i)b[i]=b[i-1]+(a[i]!=a[i-1]);
	for(int i=1;i<=n;++i)a[i]=b[i];
	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=1;i<=n;++i)iv[i]=qpow(i,p-2);
	for(int l=n;l;--l)
	{
		for(int r=l;r<=n;++r)
		{
			for(int k=l+1;k<=r;++k)dp[l][r]=(dp[l][r]-1ll*f[k][r]*dp[l][k-1])%p;
			if(a[l]==a[r])f[l][r]=1;
			else if(a[l]+1==a[r])
			{
				int cl=0;
				for(int i=l;i<=r;++i)if(a[i]==a[l])++cl;
				f[l][r]=1ll*fac[r-l+1]*ifac[cl]%p*ifac[r-l+1-cl]%p;
			}
			else
			{
				f[l][r]=-2*dp[l][r]%p;
				if(a[r-1]==a[r])f[l][r]=(f[l][r]-f[l][r-2])%p;
				if(a[l]==a[l+1])f[l][r]=(f[l][r]-f[l+2][r])%p;
			}
			dp[l][r]=(dp[l][r]+f[l][r])%p;
		}
	}
	printf("%d\n",(f[1][n]%p+p)%p);
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

3
2 3 3

output:

3

result:

ok "3"

Test #2:

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

input:

5
1 1 3 3 5

output:

29

result:

ok "29"

Test #3:

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

input:

9
1 2 3 5 5 6 7 8 9

output:

26276

result:

ok "26276"

Test #4:

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

input:

10
1 2 2 3 4 5 8 10 10 10

output:

42088

result:

ok "42088"

Test #5:

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

input:

10
1 2 4 5 5 5 5 6 10 10

output:

17210

result:

ok "17210"

Test #6:

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

input:

10
1 2 3 5 6 6 6 8 9 9

output:

41826

result:

ok "41826"

Test #7:

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

input:

10
2 6 6 7 7 8 9 10 10 10

output:

26684

result:

ok "26684"

Test #8:

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

input:

10
1 1 3 3 4 5 9 9 10 10

output:

33378

result:

ok "33378"

Test #9:

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

input:

10
1 1 2 3 4 4 9 9 10 10

output:

33348

result:

ok "33348"

Test #10:

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

input:

10
1 3 4 4 5 5 8 8 10 10

output:

32826

result:

ok "32826"

Test #11:

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

input:

10
1 3 3 4 5 6 9 9 9 10

output:

42136

result:

ok "42136"

Test #12:

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

input:

10
1 1 1 2 2 4 4 5 5 6

output:

16274

result:

ok "16274"

Test #13:

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

input:

10
1 3 5 5 5 6 7 8 8 9

output:

42088

result:

ok "42088"

Test #14:

score: 0
Accepted
time: 73ms
memory: 5632kb

input:

500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12...

output:

316934967

result:

ok "316934967"

Test #15:

score: 0
Accepted
time: 72ms
memory: 5888kb

input:

500
1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 7 7 7 7 7 8 8 9 9 10 10 10 10 10 11 11 11 11 12 12 12 12 12 13 13 14 14 14 14 15 15 15 16 16 16 17 17 17 17 17 17 17 18 18 18 18 18 18 19 19 19 19 19 19 19 19 20 21 21 21 21 21 21 22 22 22 22 22 22 22 22 22 23 23 23 23 23 23 23 ...

output:

211204090

result:

ok "211204090"

Test #16:

score: 0
Accepted
time: 74ms
memory: 5760kb

input:

500
1 1 1 2 3 4 4 4 4 4 4 4 4 5 5 5 6 7 7 7 7 8 8 9 9 10 10 10 10 10 10 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13 14 14 14 14 15 15 15 16 16 16 16 18 19 19 19 19 19 20 20 21 21 21 22 22 22 22 22 22 23 23 24 24 24 24 24 24 24 25 26 26 27 27 27 28 28 29 29 29 30 30 31 31 31 31 31 32 32 32 32 33 33 ...

output:

66910402

result:

ok "66910402"

Test #17:

score: 0
Accepted
time: 72ms
memory: 5888kb

input:

500
1 1 2 2 2 2 3 4 4 4 4 4 5 6 6 7 8 8 8 9 9 9 9 9 10 10 11 12 12 13 13 14 14 15 15 15 16 16 17 17 17 17 17 17 18 18 18 19 19 19 19 19 20 20 21 21 21 21 22 22 22 23 23 24 24 25 25 25 25 26 26 26 27 27 27 28 28 28 28 29 30 30 31 31 32 32 33 33 34 34 34 35 35 35 36 36 36 36 37 37 37 37 37 37 38 38 39...

output:

778673575

result:

ok "778673575"

Test #18:

score: 0
Accepted
time: 73ms
memory: 5888kb

input:

500
1 1 1 2 4 4 4 5 6 6 6 7 7 8 8 8 8 9 9 13 14 14 14 15 15 16 16 16 16 16 17 18 19 20 21 21 21 22 22 22 22 23 23 24 24 24 25 25 26 26 26 27 27 28 28 28 28 28 28 30 30 30 31 31 32 32 33 34 34 34 35 36 36 36 37 37 39 39 39 40 40 40 41 42 42 42 43 43 43 44 44 45 45 45 46 47 48 48 48 49 49 49 49 50 51 ...

output:

626585352

result:

ok "626585352"

Test #19:

score: 0
Accepted
time: 74ms
memory: 5888kb

input:

500
1 2 3 3 4 5 5 5 6 6 8 8 8 10 11 12 13 13 13 13 13 13 14 14 15 15 17 18 18 18 18 19 19 20 20 20 21 21 21 25 25 26 26 27 27 29 30 30 30 32 33 33 33 34 34 34 35 36 36 37 37 37 38 38 38 39 40 40 40 42 42 43 44 44 45 45 46 47 47 48 50 54 54 55 55 57 57 57 58 59 59 60 61 62 63 63 63 64 65 65 66 66 66 ...

output:

918943801

result:

ok "918943801"

Test #20:

score: 0
Accepted
time: 70ms
memory: 5888kb

input:

500
1 1 2 3 3 3 4 4 5 6 7 9 9 9 11 12 13 13 14 14 14 14 15 15 16 19 19 20 22 23 24 25 25 26 26 27 30 31 32 33 33 33 34 35 35 36 37 38 38 39 43 43 45 45 46 46 47 47 48 48 50 51 51 52 52 52 52 53 54 57 58 58 58 59 60 60 61 62 62 63 63 64 64 64 65 66 66 66 68 68 70 70 70 72 72 73 73 73 75 75 75 76 78 7...

output:

593100090

result:

ok "593100090"

Test #21:

score: 0
Accepted
time: 75ms
memory: 5888kb

input:

500
1 2 2 3 4 4 5 5 6 6 7 8 9 11 11 12 12 13 14 14 14 14 16 17 19 19 20 21 22 22 24 26 26 26 27 27 28 28 29 29 35 39 40 41 42 43 46 47 48 49 49 50 50 51 52 52 52 56 56 56 56 57 59 59 59 60 61 61 65 66 68 69 69 71 71 72 72 73 73 74 74 75 75 76 76 76 79 80 82 82 84 85 87 87 88 88 89 90 91 91 91 94 95 ...

output:

51077903

result:

ok "51077903"

Test #22:

score: 0
Accepted
time: 72ms
memory: 5888kb

input:

500
1 2 3 3 4 4 4 5 6 6 7 9 10 11 11 12 14 14 15 15 15 16 16 17 17 17 18 18 18 18 18 19 19 20 20 21 22 23 24 25 25 25 31 32 32 32 32 33 33 34 35 36 36 37 37 38 38 45 46 47 48 50 50 51 52 52 53 56 58 60 61 61 61 61 62 62 62 62 63 63 63 63 63 64 64 65 67 67 68 71 72 73 74 74 75 75 76 77 77 77 77 77 77...

output:

645029056

result:

ok "645029056"

Test #23:

score: 0
Accepted
time: 73ms
memory: 5888kb

input:

500
1 1 2 2 2 6 8 8 9 9 11 11 11 12 13 13 13 13 15 16 16 19 19 19 20 20 20 20 22 23 24 25 25 26 27 29 31 31 33 33 33 35 35 39 39 39 40 40 40 45 46 46 47 47 47 48 49 50 52 53 53 53 54 55 57 57 58 59 61 62 64 64 66 66 66 68 69 70 71 72 74 74 75 75 76 76 78 80 81 83 83 84 85 85 85 86 88 89 90 90 91 92 ...

output:

799979293

result:

ok "799979293"

Test #24:

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

input:

1
1

output:

1

result:

ok "1"

Test #25:

score: 0
Accepted
time: 74ms
memory: 5888kb

input:

500
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

output:

903664836

result:

ok "903664836"

Test #26:

score: 0
Accepted
time: 72ms
memory: 5888kb

input:

500
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...

output:

1

result:

ok "1"

Extra Test:

score: 0
Extra Test Passed