QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338514#7221. The Road NetworkKevin5307WA 0ms21020kbC++20996b2024-02-25 23:31:412024-02-25 23:31:42

Judging History

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

  • [2024-02-25 23:31:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:21020kb
  • [2024-02-25 23:31:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
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])%=mod;
			}
	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])%=mod;
	cout<<mx<<" "<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 21020kb

input:

4 7
1 4 6 3

output:

-1 0

result:

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