QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557022#7753. Energy Distributionprime-idealCompile Error//C++202.4kb2024-09-11 00:11:212024-09-11 00:11:22

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2024-09-11 00:11:22]
  • 评测
  • [2024-09-11 00:11:21]
  • 提交

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=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 select[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)select[i]=(_>>i)&1;
    memcpy(mat,mat0,sizeof(mat0));
    int one=-1;
    forw(i,0,n){
      if(!select[i]){
        memset(mat[i],0,sizeof(mat[i]));
        continue;
      }
      forw(j,0,n)if(!select[j])mat[i][j]=0;
      if(one==-1)mat[i][n]=1,one=i;
      else forw(j,0,n)if(select[j])mat[i][j]-=mat[one][j];
    }
    forw(j,0,n)if(select[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;
}
 

詳細信息

answer.code:21:15: warning: overflow in conversion from ‘long long int’ to ‘int’ changes value from ‘4557430888798830399’ to ‘1061109567’ [-Woverflow]
   21 | const int INF=INFL;
      |               ^~~~
answer.code:44:15: error: ‘bool select [20]’ redeclared as different kind of entity
   44 | bool select[20]={};
      |               ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:394,
                 from /usr/include/c++/13/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/sys/select.h:101:12: note: previous declaration ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’
  101 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
answer.code: In function ‘int main()’:
answer.code:76:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   76 |     forw(i,0,n)select[i]=(_>>i)&1;
      |                        ^
answer.code:76:25: error: assignment of read-only location ‘*(select + ((sizetype)i))’
   76 |     forw(i,0,n)select[i]=(_>>i)&1;
      |                ~~~~~~~~~^~~~~~~~~
answer.code:80:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |       if(!select[i]){
      |                   ^
answer.code:84:30: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   84 |       forw(j,0,n)if(!select[j])mat[i][j]=0;
      |                              ^
answer.code:86:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   86 |       else forw(j,0,n)if(select[j])mat[i][j]-=mat[one][j];
      |                                  ^
answer.code:88:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   88 |     forw(j,0,n)if(select[j])mat[one][j]=1;
      |                           ^