QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711257#7753. Energy DistributionFreeTimeLoveTL 485ms3952kbC++141.5kb2024-11-05 08:19:452024-11-05 08:19:47

Judging History

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

  • [2024-11-05 08:19:47]
  • 评测
  • 测评结果:TL
  • 用时:485ms
  • 内存:3952kb
  • [2024-11-05 08:19:45]
  • 提交

answer

/*FreeTimeLove's code.
Love has a nasty habit of disappearing over night.*/
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1e5+5;
inline int rd(){
	int ans=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	re f?-ans:ans;
}
int n,w[11][11];
LD e[11],eps=1e-15;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
LD calc(){
	LD ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)ans+=e[i]*e[j]*w[i][j];
	re ans;
}
int main(){
	n=rd();
	ll Sum=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)w[i][j]=rd(),Sum+=w[i][j];
	if(!Sum){
		puts("0");re 0;
	}
	LD mxans=0;
	for(int T=1;T<=1;T++){
		for(int i=1;i<=n;i++)e[i]=1.0/n;
		LD ans=calc();
		for(int i=1;i<=5000000;i++){
			int u=rnd()%n+1,v=rnd()%n+1;
			while(u==v)v=rnd()%n+1;
			LD W1=0,W2=0,k=e[u]+e[v];
			for(int j=1;j<=n;j++)
				if(j!=u&&j!=v)W1+=e[j]*w[u][j],W2+=e[j]*w[v][j];
			LD nk=(k*w[u][v]+W1-W2)/2/w[u][v];
			if(nk<0)nk=0;
			if(nk>k)nk=k;
			e[u]=nk,e[v]=k-nk;
			LD newnew=calc();
			if(ans>newnew+eps){
				puts("Fuck");
			}
			ckmax(ans,newnew);
		}
		ckmax(mxans,ans);
	}
	printf("%.15Lf\n",mxans);
	re 0;
}
/*
2
0 1
1 0
*/
}int main(){re FRTMLV::main();}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 243ms
memory: 3812kb

input:

2
0 1
1 0

output:

0.250000000000000

result:

ok found '0.2500000', expected '0.2500000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 251ms
memory: 3916kb

input:

3
0 2 1
2 0 2
1 2 0

output:

0.571428571428571

result:

ok found '0.5714286', expected '0.5714290', error '0.0000004'

Test #3:

score: 0
Accepted
time: 251ms
memory: 3952kb

input:

3
0 1 2
1 0 1
2 1 0

output:

0.500000000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #4:

score: 0
Accepted
time: 485ms
memory: 3880kb

input:

4
0 3 1 0
3 0 1 0
1 1 0 2
0 0 2 0

output:

0.750000000000000

result:

ok found '0.7500000', expected '0.7500000', error '0.0000000'

Test #5:

score: -100
Time Limit Exceeded

input:

5
0 0 0 4 4
0 0 2 0 4
0 2 0 2 0
4 0 2 0 0
4 4 0 0 0

output:


result: