QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536090#7753. Energy Distributionkkkgjyismine4WA 0ms3920kbC++231.3kb2024-08-28 18:27:532024-08-28 18:27:53

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2024-08-28 18:27:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3920kb
  • [2024-08-28 18:27:53]
  • 提交

answer

#include<bits/stdc++.h>
#define db double
#define N 20
using namespace std;
const db eps=1e-15;
int n,m;
db w[N][N],w1[N<<2][N],x[N];
db calc(){
	if(m<n)return 0;
	for(int i=1;i<=n;++i){
		int id=-1;
		for(int k=i;k<=m;++k)if(fabs(w1[k][i])>eps)id=k;
		if(id==-1)return 0;
		if(id!=i)swap(w1[i],w1[id]);
		for(int k=i+1;k<=m;++k){
			db v=w1[k][i]/w1[i][i];
			for(int j=i;j<=n+1;++j)w1[k][j]-=v*w1[i][j];
		}
	}
	for(int i=n;i>=1;--i){
		x[i]=w1[i][n+1]/w1[i][i];
		for(int j=i-1;j>=1;--j)w1[j][n+1]-=w1[j][i]*x[i],w1[j][i]=0;
	}
	for(int i=1;i<=m;++i){
		db s=0;
		for(int j=1;j<=n;++j)s+=w1[i][j]*x[j];
		if(fabs(s-w1[i][n+1])>eps)return 0;
	}
	db ret=0;
	for(int i=1;i<=n;++i)
	  for(int j=i+1;j<=n;++j)ret+=w[i][j]*x[i]*x[j];
	return ret;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)cin>>w[i][j];
	db ret=0;
	for(int Mask=0;Mask<(1<<n);++Mask){
		for(int i=1;i<=m;++i)
			for(int j=1;j<=n+1;++j)w1[i][j]=0;
		m=0;
		for(int i=1;i<n;++i){
			++m;
			for(int k=1;k<=n;++k)w1[m][k]=w[k][i]-w[k][i+1];
			w1[m][n+1]=0;
		}
		++m;
		for(int i=1;i<=n+1;++i)w1[m][i]=1;
		for(int i=1;i<=n;++i)
			if((Mask>>i-1)&1){
				++m;
				memset(w1[m],0,sizeof(w1[m]));
				w1[m][i]=0;
			}
		ret=max(ret,calc());
	}printf("%.10lf\n",ret);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 1
1 0

output:

0.2500000000

result:

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

Test #2:

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

input:

3
0 2 1
2 0 2
1 2 0

output:

0.5714285714

result:

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

Test #3:

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

input:

3
0 1 2
1 0 1
2 1 0

output:

0.5000000000

result:

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

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

input:

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

output:

0.4285714286

result:

wrong answer 1st numbers differ - expected: '0.7500000', found: '0.4285714', error = '0.3214286'