QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268848#7753. Energy Distributionucup-team134#TL 1ms3692kbC++174.4kb2023-11-28 22:13:352023-11-28 22:13:36

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2023-11-28 22:13:36]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3692kb
  • [2023-11-28 22:13:35]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(13);
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

int main()
{
	const ld scale=1000000;
	int n=ri();
	//n=10;
	vector<vector<int>> w(n,vector<int>(n));
	rd(w);
	/*for(int i=0;i<n;i++)for(int j=0;j<i;j++){
		w[i][j]=w[j][i]=1000-(rng()%100);
	}*/
	vector<ld> val(n,(ld)scale/n);
	ld trval=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			trval+=val[i]*val[j]*w[i][j];
		}
	}
	ld trans=scale/2/n;
	while(trans>1e-4){
		bool improved=0;
		for(int i=0;i<n;i++){
			if(val[i]<trans)continue;
			for(int j=0;j<n;j++){
				if(i==j)continue;
				ld ch=0;
				for(int k=0;k<n;k++){
					if(i!=k&&k!=j){
						ch-=val[i]*val[k]*w[i][k]+val[j]*val[k]*w[j][k];
						ch+=(val[i]-trans)*val[k]*w[i][k]+(val[j]+trans)*val[k]*w[j][k];
					}
				}
				//cout << trans << " " << i << " " << j << " " << ch << endl;
				ch-=val[i]*val[j]*w[i][j];
				ch+=(val[i]-trans)*(val[j]+trans)*w[i][j];
				//cout << trans << " " << i << " " << j << " " << ch << endl;
				if(ch>0){
					improved=1;
					val[i]-=trans;
					val[j]+=trans;
					trval+=ch;
					break;
				}
			}
		}
		/*for(auto p:val){
			printf("%.20Lf\n",p);
		}
		cout << trans << val << improved << endl;*/
		if(!improved)trans/=2;
	}
	printf("%.10Lf\n",trval/scale/scale);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3692kb

input:

2
0 1
1 0

output:

0.2500000000

result:

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

Test #2:

score: -100
Time Limit Exceeded

input:

3
0 2 1
2 0 2
1 2 0

output:


result: