QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691038 | #7753. Energy Distribution | sunnygreen | WA | 214ms | 3928kb | C++14 | 2.0kb | 2024-10-31 09:31:19 | 2024-10-31 09:33:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define se second
#define mk make_pair
#define eb emplace_back
#define rep(i,l,r) for(int i=(l); i<=(r); ++i)
#define rep_(i,l,r) for(int i=(l); i>=(r); --i)
typedef long long lr;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr db pi=3.141592653589793,eps=1e-9;
constexpr int inf32=0x3f3f3f3f,Inf32=0xc0c0c0c0;
constexpr lr inf64=0x3f3f3f3f3f3f3f3f,Inf64=0xc0c0c0c0c0c0c0c0;
template<typename T>il T Max(T x,T y) { return (x>y)? x:y; }
template<typename T>il T Min(T x,T y) { return (x<y)? x:y; }
template<typename T>il T gcd(T x,T y) { return (!y)? x:gcd(y,x%y); }
template<typename T>il T Abs(T x) { return (x>0)? x:(-x); }
template<typename T>il T Rnd(T l,T r,mt19937_64 &eng)
{
uniform_int_distribution<T> uid(l,r);
return uid(eng);
}
mt19937_64 eng(chrono::high_resolution_clock::now().time_since_epoch().count());
constexpr int N=15;
int n,val[N],w[N][N];
db p[N];
il void chk(int x,int y)
{
db X=0,Y=0;
rep(i,1,n)
if(i!=x&&i!=y)
X+=p[i]*w[x][i],Y+=p[i]*w[y][i];
db xx=0.5*(X-Y+w[x][y]*(p[x]+p[y]))/w[x][y],yy=0.5*(Y-X+w[x][y]*(p[x]+p[y]))/w[x][y];
p[x]=xx,p[y]=yy;
}
il void Solve()
{
cin>>n;
rep(i,1,n)
rep(j,1,n)
cin>>w[i][j];
db bp=0;
int Q=150;
while(Q--)
{
int sum=0;
rep(i,1,n)
val[i]=Rnd(20210416,80000000,eng),sum+=val[i];
rep(i,1,n)
p[i]=1.0*val[i]/sum;
rep(i,1,40000)
{
int x=Rnd(1,n,eng),y=Rnd(1,n,eng);
while(x==y)
x=Rnd(1,n,eng),y=Rnd(1,n,eng);
chk(x,y);
}
db ans=0;
rep(i,1,n)
rep(j,i+1,n)
ans+=p[i]*p[j]*w[i][j];
bp=Max(bp,ans);
}
cout<<setiosflags(ios::fixed)<<setprecision(9)<<bp<<'\n';
}
int main()
{
#ifdef LOCAL
string fpre="test",isuf="in",osuf="out";
assert(freopen((fpre+"."+isuf).c_str(),"r",stdin));
assert(freopen((fpre+"."+osuf).c_str(),"w",stdout));
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
while(T--)
Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 214ms
memory: 3924kb
input:
2 0 1 1 0
output:
0.250000000
result:
ok found '0.2500000', expected '0.2500000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 202ms
memory: 3928kb
input:
3 0 2 1 2 0 2 1 2 0
output:
0.571428571
result:
ok found '0.5714286', expected '0.5714290', error '0.0000004'
Test #3:
score: 0
Accepted
time: 201ms
memory: 3912kb
input:
3 0 1 2 1 0 1 2 1 0
output:
0.500000000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #4:
score: -100
Wrong Answer
time: 195ms
memory: 3864kb
input:
4 0 3 1 0 3 0 1 0 1 1 0 2 0 0 2 0
output:
-nan
result:
wrong output format Expected double, but "-nan" found