結果

問題 No.1590 Random Shopping
ユーザー 👑 potato167potato167
提出日時 2021-07-08 23:55:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 829 ms / 5,000 ms
コード長 2,336 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 215,944 KB
実行使用メモリ 11,432 KB
最終ジャッジ日時 2023-09-14 05:45:27
合計ジャッジ時間 10,234 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 66 ms
4,664 KB
testcase_13 AC 263 ms
7,096 KB
testcase_14 AC 826 ms
11,356 KB
testcase_15 AC 822 ms
11,316 KB
testcase_16 AC 823 ms
11,320 KB
testcase_17 AC 828 ms
11,336 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 829 ms
11,432 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 823 ms
11,348 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 826 ms
11,252 KB
testcase_24 AC 827 ms
11,368 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}



//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N;
	cin>>N;
	vector<pair<ld,int>> A(N);
	vector<ld> R(N);
	rep(i,N){
		ld a;
		cin>>a;
		A[i]={a,i};
	}
	rep(i,N) cin>>R[i];
	So(A);
	ll M=N+10;
	vector<int> order(N);
	rep(i,N) order[A[i].second]=i;
	vector<vector<ld>> dp1(M,vector<ld>(M,0));
	auto dp2=dp1;
	rep(i,M) dp2[i][0]=1;
	ld ans=0;
	rep(i,N){
		int rank=order[i];
		rep(j,N){
			if(j<rank) continue;
			else if(j==rank){
				rep(k,M-1) dp1[j][k+1]=dp2[j][k];
			}
			else{
				for(int k=M-1;k>0;k--){
					dp1[j][k]=dp1[j][k-1];
				}
				dp1[j][1]=0;
				dp1[j][0]=0;
			}
		}
		for(int j=rank;j<M;j++){
			for(int k=M-1;k>0;k--) dp2[j][k]=dp2[j][k-1];
			dp2[j][0]=0;
		}
		ld X=0;
		rep(j,N){
			X+=A[j].first*dp1[j][1];
			//cout<<dp1[j][1]<<endl;
		}
		ans+=R[i]*(X/2);
		//cout<<ans<<endl;
		ld Y=0;
		rep(j,N){
			//Y+=dp1[j][1]/2;
			Y=0.5;
			//cout<<Y<<endl;
			//ld Z=Y/(1-dp2[j][0]);
			rep(k,M-1){
				if(k!=0) dp2[j][k]*=(1-Y);
				dp2[j][k]+=Y*dp2[j][k+1];
			}
			/*rep(k,M-1){
				dp1[j][k]*=(1-Y);
				dp1[j][k]+=Y*dp1[j][k+1];
				
			}
			dp1[j][0]=0;*/
		}
		//cout<<endl;
		rep(j,N){
			rep(k,M-1){
				dp1[j][k]+=dp1[j][k+1];
				dp1[j][k]/=2;
			}
			dp1[j][0]=0;
		}
		
	}
	cout<<setprecision(18)<<ans<<endl;
}

0