QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557025#7753. Energy Distributionprime-idealWA 0ms4028kbC++202.4kb2024-09-11 00:12:312024-09-11 00:12:32

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2024-09-11 00:12:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4028kb
  • [2024-09-11 00:12:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define RN return
#define forw(_,l,r) for(auto _=(l);_<(r);++_)
#define fors(_,r,l) for(auto _=(r);_>(l);--_)

void read(){}
template<typename T,typename...Types>
void read(T& x, Types&...args){
  x=0; char c=' '; bool sgn=0;
  while(isspace(c))c=getchar();
  if(c=='-')c=getchar(),sgn=1;
  while(isdigit(c))x=10*x+c-'0',c=getchar();
  if(sgn)x=-x;
  read(args...);
}

typedef long double ld;
typedef long long ll;
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=int(INFL);
const ld epsi=1e-9;
inline int sgn(ld x){if(x<-epsi)RN -1;else if(x>epsi)RN 1;else RN 0;}
ld mat0[11][11]={},mat[11][11]={}; int n;//!
int gaussEli(){
  int r=0;
  forw(c,0,n+1){
    int r0=-1;
    forw(i,r,n)if(sgn(mat[i][c])){r0=i;break;}
    if(r0==-1)continue;
    forw(i,0,n+1)swap(mat[r0][i],mat[r][i]);
    fors(i,n,c-1)mat[r][i]/=mat[r][c]; 
    forw(i,r+1,n)if(sgn(mat[i][c]))
      fors(j,n,c-1)
        mat[i][j]-=mat[r][j]*mat[i][c];
    ++r;
  }if(r<n){
    forw(i,r,n)if(sgn(mat[i][n]))RN 0;
    RN INF;
  }fors(i,n-1,-1)forw(j,i+1,n+1)
    mat[i][n]-=mat[j][n]*mat[i][j];
  RN 1;
}
bool sel[20]={};
ld vec[10]={};

void test(){
  n=3; 
  mat[0][0]=mat[0][1]=1;
  mat[1][1]=mat[1][2]=1;
  mat[2][2]=mat[2][0]=1;
  forw(i,0,3)mat[i][n]=2;
  gaussEli();
  forw(i,0,n)cout<<mat[i][n]<<' ';
}
void test1(){
  n=2; 
  mat[0][0]=mat[0][1]=mat[0][2]=1;
  mat[1][0]=1,mat[1][1]=-1;mat[1][2]=0;
  gaussEli();
  forw(i,0,n)cout<<mat[i][n]<<' ';
}
int main()
{
  //test1();
  read(n);
  forw(i,0,n)forw(j,0,n){
    int x; read(x);
    if(i==j)mat0[i][j]=0;
    else if(j<i)mat0[i][j]=mat0[j][i];
    else mat0[i][j]=x;
  }
  ld ans=0;
  forw(_,1,(1<<n)){
    if(__builtin_popcount(_)==1)continue;
    forw(i,0,n)sel[i]=(_>>i)&1;
    memcpy(mat,mat0,sizeof(mat0));
    int one=-1;
    forw(i,0,n){
      if(!sel[i]){
        memset(mat[i],0,sizeof(mat[i]));
        continue;
      }
      forw(j,0,n)if(!sel[j])mat[i][j]=0;
      if(one==-1)mat[i][n]=1,one=i;
      else forw(j,0,n)if(sel[j])mat[i][j]-=mat[one][j];
    }
    forw(j,0,n)if(sel[j])mat[one][j]=1;
    int ret=gaussEli();
    if(ret==1){
      ld res=0;
      forw(i,0,n)vec[i]=0;
      forw(i,0,n)if(sgn(vec[i]=mat[i][n])==-1){res=-2;break;}
      if(res>-1)forw(i,0,n)forw(j,i+1,n)res+=vec[i]*mat0[i][j]*vec[j];
      ans=max(ans,res);
    }
  }
  printf("%.12Lf",ans);
  RN 0;
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 1
1 0

output:

0.250000000000

result:

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

Test #2:

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

input:

3
0 2 1
2 0 2
1 2 0

output:

0.571428571429

result:

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

Test #3:

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

input:

3
0 1 2
1 0 1
2 1 0

output:

0.500000000000

result:

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

Test #4:

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

input:

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

output:

0.428571428571

result:

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