QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#338513#7221. The Road NetworkKevin5307WA 2ms21132kbC++20961b2024-02-25 23:30:252024-02-25 23:30:25

Judging History

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

  • [2024-02-25 23:30:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:21132kb
  • [2024-02-25 23:30:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int f[2002][2002];
ll g[2002][2002];
int main()
{
	int n,d;
	cin>>n>>d;
	vector<int> w;
	vector<int> seq;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		w.push_back(x);
	}
	sort(w.begin(),w.end());
	int l=0,r=n-1;
	while(l<=r)
	{
		if(w[l]+w[r]>=d)
			seq.push_back(w[r--]);
		else
			seq.push_back(w[l++]);
	}
	memset(f,-0x3f,sizeof(f));
	f[0][0]=0;
	g[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++)
			for(int k=0;k<2;k++)
			{
				int nval=f[i][j];
				if(i&&seq[i]+seq[i-1]>=d)
					nval+=k?i-j:j;
				if(f[i+1][j+k]<nval)
				{
					f[i+1][j+k]=nval;
					g[i+1][j+k]=g[i][j];
				}
				else if(f[i+1][j+k]==nval)
					g[i+1][j+k]+=g[i][j];
			}
	ll ans=0;
	int mx=-1;
	for(int i=0;i<=n;i++)
		if(f[n][i]>mx)
		{
			mx=f[n][i];
			ans=g[n][i];
		}
		else if(f[n][i]==mx)
			ans+=g[n][i];
	cout<<mx<<" "<<ans<<endl;
	return 0;
}

详细

Test #1:

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

input:

4 7
1 4 6 3

output:

3 6

result:

ok 2 number(s): "3 6"

Test #2:

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

input:

4 11
1 4 6 3

output:

0 16

result:

ok 2 number(s): "0 16"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 20916kb

input:

4 5
1 4 6 3

output:

2 12

result:

wrong answer 1st numbers differ - expected: '4', found: '2'