結果

問題 No.1590 Random Shopping
ユーザー 沙耶花沙耶花
提出日時 2021-07-08 22:59:31
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 749 ms / 5,000 ms
コード長 1,292 bytes
コンパイル時間 4,181 ms
使用メモリ 3,820 KB
最終ジャッジ日時 2023-02-01 19:05:10
合計ジャッジ時間 9,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,652 KB
testcase_01 AC 2 ms
3,740 KB
testcase_02 AC 1 ms
3,704 KB
testcase_03 AC 1 ms
3,620 KB
testcase_04 AC 1 ms
3,768 KB
testcase_05 AC 2 ms
3,620 KB
testcase_06 AC 2 ms
3,620 KB
testcase_07 AC 1 ms
3,744 KB
testcase_08 AC 1 ms
3,744 KB
testcase_09 AC 2 ms
3,624 KB
testcase_10 AC 4 ms
3,724 KB
testcase_11 AC 15 ms
3,656 KB
testcase_12 AC 53 ms
3,800 KB
testcase_13 AC 205 ms
3,740 KB
testcase_14 AC 589 ms
3,820 KB
testcase_15 AC 599 ms
3,752 KB
testcase_16 AC 595 ms
3,768 KB
testcase_17 AC 580 ms
3,640 KB
testcase_18 AC 1 ms
3,740 KB
testcase_19 AC 748 ms
3,640 KB
testcase_20 AC 1 ms
3,624 KB
testcase_21 AC 749 ms
3,748 KB
testcase_22 AC 1 ms
3,616 KB
testcase_23 AC 9 ms
3,756 KB
testcase_24 AC 9 ms
3,820 KB
testcase_25 AC 2 ms
3,616 KB
testcase_26 AC 1 ms
3,620 KB
testcase_27 AC 1 ms
3,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int N;
vector<int> A,R;

vector<double> get(int n){
	vector<double> dp(N+1,0.0);
	dp[0]  = 1.0;
	vector<double> ret(N,0.0);
	
	rep(i,N){
		vector<double> ndp(N+1,0.0);
		rep(j,N+1){
			if(A[i]<=n){
				if(i!=N){
					ndp[j+1] += dp[j];
				}
			}
			else{
				ndp[j] += dp[j];
			}
		}
		
		swap(dp,ndp);
		ndp.assign(N+1,0.0);
		rep(j,N+1){
			if(j==0)continue;
			ret[i] += dp[j]/2.0;
		}
		rep(j,N+1){
			if(j==0){
				ndp[j] += dp[j];
			}
			else{
				ndp[j] += dp[j]/2.0;
				ndp[j-1] += dp[j]/2.0;
			}
		}
		swap(dp,ndp);		
	}
	return ret;
}
	
int main(){
	
	cin>>N;
	
	A.resize(N),R.resize(N);
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>R[i];
	
	vector<int> t = A;
	t.push_back(0);
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	
	vector<double> x = get(t[0]);
	double ans = 0.0;
	for(int i=1;i<t.size();i++){
		vector<double> y = get(t[i]);
		/*
		cout<<t[i]<<endl;
		rep(j,N){
			cout<<y[j]<<',';
		}
		cout<<endl;
		*/
		rep(j,N){
			ans += (y[j]-x[j]) * t[i] * R[j];
		}
		
		swap(x,y);
	}
	
	cout<<fixed<<setprecision(10)<<ans<<endl;
	
	return 0;
}
0