QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559218#6355. 5Jessica2333TL 11ms16088kbC++141.3kb2024-09-11 20:51:442024-09-11 20:51:47

Judging History

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

  • [2024-09-11 20:51:47]
  • 评测
  • 测评结果:TL
  • 用时:11ms
  • 内存:16088kb
  • [2024-09-11 20:51:44]
  • 提交

answer

#include<iostream>
#include<vector>
using namespace std;
int N,S,A[200008],buc[400008],W[508],V[508];
struct NODE{
	int l,r;
};
vector<NODE> f[400008];
int vis[400008];
int O;
void add_(int p,int l,int r)
{
	if(f[p].empty()) f[p].push_back({l,r});
	else
	{
		vector<NODE> vec;
		for(auto v:f[p]) vec.push_back(v);
		f[p].clear();
		bool flag=1;
		for(auto v:vec)
		{
			if(v.r<l-1) f[p].push_back(v);
			else if(l<=v.l&&v.r<=r) continue;
			else if(v.l>r+1) f[p].push_back({l,r}),f[p].push_back(v),flag=0;
			else l=min(l,v.l),r=max(r,v.r);
		}
		if(flag) f[p].push_back({l,r});
	}
}
signed main()
{
	cin>>N>>S;O=N;
	for(int i=1;i<=N;i++) cin>>A[i],buc[A[i]]++;
	int N2=0;
	for(int i=1;i<=N;i++)
		for(int j=0;buc[A[i]];j++) V[++N2]=A[i]*min(1<<j,buc[A[i]]),W[N2]=min(1<<j,buc[A[i]]),buc[A[i]]-=W[N2];
	f[O].push_back({0,0});
	for(int i=1;i<=N2;i++)
	{
		if(V[i]>0)
		{
			for(int j=S+O-1;j>=0;j--)
			{
				if(j+V[i]-W[i]>=S+O) continue;
				for(auto v:f[j])
				{
					add_(j+V[i]-W[i],v.l+W[i],v.r+W[i]);
				}
			}
		}
		else
		{
			for(int j=0;j<S+O;j++)
			{
				if(j+V[i]-W[i]<0) continue;
				for(auto v:f[j])
				{
					add_(j+V[i]-W[i],v.l+W[i],v.r+W[i]);
				}
			}
		}
	}
	long long ans=0;
	for(int i=0;i<S+O;i++) for(auto v:f[i]) ans+=v.r-v.l+1;
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

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

input:

10 33
9 9 8 1 1 1 1 1 1 1

output:

48

result:

ok 1 number(s): "48"

Test #3:

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

input:

10 14
2 4 4 1 0 1 0 1 0 1

output:

81

result:

ok 1 number(s): "81"

Test #4:

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

input:

10 14
3 5 3 0 1 0 1 0 1 0

output:

87

result:

ok 1 number(s): "87"

Test #5:

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

input:

40 50
1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1

output:

1067

result:

ok 1 number(s): "1067"

Test #6:

score: 0
Accepted
time: 2ms
memory: 13876kb

input:

1200 1000
1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...

output:

737899

result:

ok 1 number(s): "737899"

Test #7:

score: 0
Accepted
time: 11ms
memory: 14332kb

input:

12000 10000
1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...

output:

73685347

result:

ok 1 number(s): "73685347"

Test #8:

score: -100
Time Limit Exceeded

input:

36000 30000
0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...

output:


result: