QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286983#7976. 最后的晚餐zhouhuanyi32 37ms8208kbC++201.6kb2023-12-19 10:27:202023-12-19 10:27:20

Judging History

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

  • [2023-12-19 10:27:20]
  • 评测
  • 测评结果:32
  • 用时:37ms
  • 内存:8208kb
  • [2023-12-19 10:27:20]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 12
#define M 24000
#define mod 998244353
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int n,cnt[N+1],dp[N+1][M+1],DP[N+1][M+1],DSP[N+1][M+1][2],F[M+1],ans;
int main()
{
	int x,res=0,res2=0,res3=0,d;
	n=read(),dp[0][0]=DP[0][0]=DSP[0][0][0]=1;
	for (int i=1;i<=n;++i) x=read(),cnt[x]++;
	for (int i=1;i<=12;++i)
	{
		for (int j=0;j<=res;++j)
	   	    for (int k=0;k<=cnt[i];++k)
				Adder(dp[i][j+i*k],dp[i-1][j]);
		res+=i*cnt[i];
	}
	res2=0;
	for (int i=1;i<=10;++i)
	{
		for (int j=0;j<=res2;++j)
	   	    for (int k=0;k<=cnt[i];++k)
				Adder(DP[i][j+(10-i)*k],DP[i-1][j]);
		res2+=(10-i)*cnt[i];
	}
	res3=0;
	for (int i=1;i<=10;++i)
	{
		for (int j=0;j<=res2;++j)
	   	    for (int k=(i==1?1:0);k<=cnt[i];++k)
				for (int op=0;op<=1;++op)
					Adder(DSP[i][j+(10-i)*k][op^((i!=1&&(i&1))?(j&1):0)],DSP[i-1][j][op]);
		res3+=(10-i)*cnt[i];
	}
	for (int i=0;i<=res;++i) Adder(ans,1ll*dp[12][i]*(i/10+1)%mod);
	for (int i=0;i<=cnt[11];++i)
		for (int j=0;j<=cnt[12];++j)
			F[i+(j<<1)]++;
	for (int i=0;i<=cnt[11]+(cnt[12]<<1);++i)
		for (int j=0;j<i;++j)
			Adder2(ans,-1ll*F[i]*DP[10][j]%mod*((i-j)/10)%mod);
	for (int i=0;i<=cnt[12];++i)
		for (int j=9;j<=res3;++j)
		{
			d=max(((i<<1)-(j-9))/10,0)-max(((i<<1)-j)/10,0);
			if (d) Adder2(ans,-1ll*DSP[10][j][0]*d%mod);
		}
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 1ms
memory: 5960kb

input:

5
1 1 4 5 1 4

output:

19

result:

ok single line: '19'

Test #2:

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

input:

20
6 1 8 6 10 8 4 3 9 3 6 8 5 11 6 8 3 12 1 12

output:

203040

result:

ok single line: '203040'

Test #3:

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

input:

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

output:

656102

result:

ok single line: '656102'

Test #4:

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

input:

20
1 11 11 7 11 11 5 3 4 8 10 5 12 7 12 1 11 11 1 12

output:

133044

result:

ok single line: '133044'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 12
Accepted
time: 0ms
memory: 7912kb

input:

25
7 12 12 4 7 2 2 4 5 3 10 1 2 10 12 7 4 9 8 12 3 5 4 7 5

output:

1209600

result:

ok single line: '1209600'

Test #6:

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

input:

30
2 8 12 3 4 5 9 1 11 1 12 6 3 4 5 8 10 1 9 10 5 10 10 9 2 12 5 4 1 12

output:

11070000

result:

ok single line: '11070000'

Test #7:

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

input:

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

output:

28068252

result:

ok single line: '28068252'

Test #8:

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

input:

30
10 5 1 1 8 12 5 10 1 1 5 10 1 11 11 5 11 12 12 8 1 1 10 12 4 1 11 4 12 9

output:

1312095

result:

ok single line: '1312095'

Test #9:

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

input:

27
9 6 5 5 10 1 10 9 7 10 3 6 1 11 11 9 9 4 9 1 9 1 4 9 4 9 6

output:

979772

result:

ok single line: '979772'

Test #10:

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

input:

40
8 9 2 4 8 2 9 8 4 10 1 9 4 4 9 6 7 11 7 2 1 7 10 6 2 10 5 11 3 4 5 10 1 6 6 4 9 7 3 7

output:

171460800

result:

ok single line: '171460800'

Test #11:

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

input:

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

output:

522240000

result:

ok single line: '522240000'

Test #12:

score: -12
Wrong Answer
time: 1ms
memory: 6008kb

input:

40
1 12 1 11 1 5 1 1 1 12 12 1 9 4 1 11 6 12 5 9 11 4 1 12 1 12 12 4 9 9 11 11 12 11 11 7 9 11 11 10

output:

8721818

result:

wrong answer 1st lines differ - expected: '8721848', found: '8721818'

Subtask #3:

score: 16
Accepted

Test #13:

score: 16
Accepted
time: 1ms
memory: 6060kb

input:

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

output:

7029577

result:

ok single line: '7029577'

Test #14:

score: 0
Accepted
time: 37ms
memory: 6876kb

input:

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

output:

371307514

result:

ok single line: '371307514'

Test #15:

score: 0
Accepted
time: 20ms
memory: 6548kb

input:

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

output:

513895468

result:

ok single line: '513895468'

Test #16:

score: 0
Accepted
time: 8ms
memory: 8128kb

input:

2000
4 11 10 11 1 11 11 11 11 11 11 5 11 5 11 11 11 11 10 5 11 3 11 11 5 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 4 11 7 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 1 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 9 11 11 11 11 11 11 11 11 11 1 11 6 11 11 11 11 11 11 3 11 ...

output:

359825045

result:

ok single line: '359825045'

Subtask #4:

score: 12
Accepted

Test #17:

score: 12
Accepted
time: 1ms
memory: 6068kb

input:

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

output:

537422792

result:

ok single line: '537422792'

Test #18:

score: 0
Accepted
time: 26ms
memory: 8208kb

input:

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

output:

839026549

result:

ok single line: '839026549'

Test #19:

score: 0
Accepted
time: 19ms
memory: 6220kb

input:

2000
12 11 12 12 12 12 11 11 4 11 12 5 11 11 12 11 11 12 6 12 11 11 12 12 11 12 12 12 11 11 7 5 11 11 11 10 5 12 12 12 11 11 12 12 11 11 11 11 12 11 12 11 12 12 6 12 12 11 11 12 12 11 11 12 11 12 11 12 12 11 11 12 12 12 12 12 7 11 11 12 11 12 4 11 12 12 11 11 12 11 11 11 11 11 12 11 11 11 11 11 12 1...

output:

58568833

result:

ok single line: '58568833'

Test #20:

score: 0
Accepted
time: 18ms
memory: 6352kb

input:

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

output:

815809248

result:

ok single line: '815809248'

Test #21:

score: 0
Accepted
time: 24ms
memory: 6136kb

input:

2000
12 11 12 12 12 12 11 12 12 12 12 12 11 5 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 12 12 5 5 12 12 12 11 12 11 12 12 12 12 12 12 12 12 12 12 11 12 11 12 12 12 12 12 12 12 11 8 12 12 12 12 12 10 12 11 12 12 11 12 12 11 11 12 11 12 12 12 3 7 11 12 12 12 12 12 12 11 12 12 11 12 12 1...

output:

444619177

result:

ok single line: '444619177'

Subtask #5:

score: 0
Wrong Answer

Test #22:

score: 12
Accepted
time: 1ms
memory: 5924kb

input:

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

output:

970946217

result:

ok single line: '970946217'

Test #23:

score: -12
Wrong Answer
time: 1ms
memory: 7996kb

input:

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

output:

242285141

result:

wrong answer 1st lines differ - expected: '242285391', found: '242285141'

Subtask #6:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 1ms
memory: 6120kb

input:

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

output:

160323251

result:

wrong answer 1st lines differ - expected: '160323719', found: '160323251'

Subtask #7:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 1ms
memory: 6128kb

input:

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

output:

81213912

result:

wrong answer 1st lines differ - expected: '81214287', found: '81213912'

Subtask #8:

score: 0
Wrong Answer

Test #42:

score: 0
Wrong Answer
time: 1ms
memory: 6072kb

input:

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

output:

348282053

result:

wrong answer 1st lines differ - expected: '348282473', found: '348282053'