QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#310879#7753. Energy Distribution275307894a#WA 0ms4056kbC++141.6kb2024-01-21 19:21:042024-01-21 19:21:04

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2024-01-21 19:21:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4056kb
  • [2024-01-21 19:21:04]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=10+5,M=1.5e7+5,K=(1<<25)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,B[N][N],id[N],ih;
db ans,A[N][N],w[N];
int add(){
	for(int i=1;i<=ih;i++) if(w[i]){
		if(!A[i][i]) {Mc(A[i],w);return 1;}
		db p=w[i]/A[i][i];
		for(int j=i;j<=ih+1;j++) w[j]-=p*A[i][j];
	}
	return w[ih+1]?-1:0;
}
void calc(){
	int i,j;
	Me(A,0);
	for(i=1;i<=ih;i++) w[i]=1;w[ih+1]=-1;if(add()==-1) return;
	for(i=2;i<=ih;i++){
		Me(w,0);
		for(j=1;j<=ih;j++) w[j]=B[id[1]][id[j]]-B[id[i]][id[j]];
		if(add()==-1) return;
	}
	for(i=ih;i;i--){
		if(!A[i][i]){w[i]=0;continue;}
		w[i]=-A[i][ih+1];
		for(j=i+1;j<=ih;j++) w[i]-=w[j]*A[i][j];
		w[i]/=A[i][i];
	}
	// for(i=1;i<=ih;i++) cerr<<w[i]<<' ';cerr<<'\n';
	db tot=0;for(i=1;i<=ih;i++) for(j=i+1;j<=ih;j++) tot+=B[id[i]][id[j]]*w[i]*w[j];
	ans=max(ans,tot);
}
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&B[i][j]);
	for(i=1;i<(1<<n);i++){
		ih=0;for(j=1;j<=n;j++) if(i>>j-1&1) id[++ih]=j;
		calc();
	}
	printf("%.8lf\n",ans);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 1
1 0

output:

0.25000000

result:

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

Test #2:

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

input:

3
0 2 1
2 0 2
1 2 0

output:

0.57142857

result:

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

Test #3:

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

input:

3
0 1 2
1 0 1
2 1 0

output:

0.50000000

result:

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

Test #4:

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

input:

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

output:

1.00000000

result:

wrong answer 1st numbers differ - expected: '0.7500000', found: '1.0000000', error = '0.2500000'