QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286950#7976. 最后的晚餐zhouhuanyi4 471ms17276kbC++201.0kb2023-12-19 09:37:062023-12-19 09:37:07

Judging History

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

  • [2023-12-19 09:37:07]
  • 评测
  • 测评结果:4
  • 用时:471ms
  • 内存:17276kb
  • [2023-12-19 09:37:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#define N 12
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;
}
struct reads
{
	int d[N+1];
	bool operator < (const reads &t)const
	{
		for (int i=1;i<=12;++i)
			if (d[i]!=t.d[i])
				return d[i]<t.d[i];
		return 0;
	}
};
reads zero;
map<reads,int>dp;
int n,cnt[N+1],ans;
int F(reads x)
{
	int res=0;
	for (int i=1;i<=12;++i) res+=x.d[i]*i;
	return res/10;
}
int main()
{
	reads top,st;
	queue<reads>q;
	int x;
	n=read();
	for (int i=1;i<=n;++i) x=read(),cnt[x]++;
	q.push(zero),dp[zero]=1;
	while (!q.empty())
	{
		top=q.front(),q.pop();
		for (int i=1;i<=12;++i)
			if (top.d[i]+1<=cnt[i])
			{
				st=top,st.d[i]++;
				if (dp.find(st)==dp.end()) dp[st]=dp[top]+(F(st)!=F(top)),q.push(st);
				else dp[st]=max(dp[st],dp[top]+(F(st)!=F(top)));
			}
	}
	for (auto it:dp) ans+=it.second;
	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: 3732kb

input:

5
1 1 4 5 1 4

output:

19

result:

ok single line: '19'

Test #2:

score: 0
Accepted
time: 99ms
memory: 6464kb

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: 423ms
memory: 13904kb

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: 40ms
memory: 5524kb

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
Time Limit Exceeded

Test #5:

score: 12
Accepted
time: 471ms
memory: 17276kb

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: -12
Time Limit Exceeded

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:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

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:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

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:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

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:


result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #27:

score: 0
Time Limit Exceeded

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:


result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #34:

score: 0
Time Limit Exceeded

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:


result:


Subtask #8:

score: 0
Time Limit Exceeded

Test #42:

score: 0
Time Limit Exceeded

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:


result: