QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338513 | #7221. The Road Network | Kevin5307 | WA | 2ms | 21132kb | C++20 | 961b | 2024-02-25 23:30:25 | 2024-02-25 23:30:25 |
Judging History
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'