結果

問題 No.1590 Random Shopping
ユーザー 沙耶花沙耶花
提出日時 2021-07-08 22:59:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 828 ms / 5,000 ms
コード長 1,292 bytes
コンパイル時間 4,387 ms
コンパイル使用メモリ 265,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 05:27:04
合計ジャッジ時間 10,158 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 59 ms
4,376 KB
testcase_13 AC 228 ms
4,376 KB
testcase_14 AC 650 ms
4,380 KB
testcase_15 AC 658 ms
4,376 KB
testcase_16 AC 655 ms
4,380 KB
testcase_17 AC 642 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 828 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 825 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 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