QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593681#5054. City BrainDaiRuiChen007WA 4ms101876kbC++171.6kb2024-09-27 15:28:522024-09-27 15:28:53

Judging History

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

  • [2024-09-27 15:28:53]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:101876kb
  • [2024-09-27 15:28:52]
  • 提交

answer

#include<bits/stdc++.h>
#define ld long double
#define ll long long
using namespace std;
const int MAXN=5005;
const ll inf=2e18;
int n,m; ll k;
vector <int> G[MAXN];
int d[MAXN][MAXN],f[MAXN];
ll q1(ll x) {
	ll z=sqrt(x)+10;
	while(z*(z-1)>x) --z;
	return z;
}
ll q2(ll x) {
	ll z=sqrt(2*x)+10;
	while(z*(z-1)/2>x) --z;
	return z;
}
ld qry(ll x,ll z) {
	if(!x&&!z) return 0;
	ll l=1,r=inf,p=0;
	while(l<=r) {
		ll mid=(l+r)>>1;
		if((q2(mid)-1)*z+(q1(mid)-1)*x<=k) l=mid+1,p=mid;
		else r=mid-1;
	}
	ll s1=q1(p),s2=q2(p),q=k-(s2-1)*z-(s1-1)*x;
	ll c1=(s1+1)*s1,c2=(s2+1)*s2/2;
	if(c1<c2) {
		return (ld)q/(s1+1)+(ld)(x-q)/s1+(ld)z/s2*2;
	} else if(c2<c1||q<=z) {
		return (ld)x/s1+((ld)(z-q)/s2+(ld)q/(s2+1))*2;
	} else {
		q-=z;
		return (ld)q/(s1+1)+(ld)(x-q)/s1+(ld)z/(s2+1)*2;
	}
}
signed main() {
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1,u,v;i<=m;++i) scanf("%d%d",&u,&v),G[u].push_back(v),G[v].push_back(u);
	memset(d,0x0f,sizeof(d));
	int s1,t1,s2,t2;
	scanf("%d%d%d%d",&s1,&t1,&s2,&t2);
	for(int s=1;s<=n;++s) {
		queue <int> q;
		q.push(s),d[s][s]=0;
		while(q.size()) {
			int u=q.front(); q.pop();
			for(int v:G[u]) if(d[s][v]>d[s][u]+1) d[s][v]=d[s][u]+1,q.push(v);
		}
	}
	memset(f,0x3f,sizeof(f));
	for(int u=1;u<=n;++u) for(int v=1;v<=n;++v) if(d[u][v]<n) {
		f[d[u][v]]=min(f[d[u][v]],d[s1][u]+d[v][t1]+d[s2][u]+d[v][t2]);
		f[d[u][v]]=min(f[d[u][v]],d[s1][u]+d[v][t1]+d[s2][v]+d[u][t2]);
	}
	ld ans=inf;
	for(int i=0;i<n;++i) if(f[i]<=4*n) {
		ans=min(ans,qry(f[i],i));
	}
	printf("%.16Lf\n",ans);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 101872kb

input:

6 5 1
1 2
3 2
2 4
4 5
4 6
1 5 3 6

output:

5.0000000000000000

result:

ok found '5.000000000', expected '5.000000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 4ms
memory: 101876kb

input:

1 0 100
1 1 1 1

output:

0.0000000000000000

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 101856kb

input:

4 2 3
1 2
3 4
1 2 3 4

output:

2000000000000000000.0000000000000000

result:

wrong answer 1st numbers differ - expected: '0.8333333', found: '2000000000000000000.0000000', error = '2000000000000000000.0000000'