結果
| 問題 |
No.1590 Random Shopping
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-07-08 22:59:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,033 ms / 5,000 ms |
| コード長 | 1,292 bytes |
| コンパイル時間 | 5,059 ms |
| コンパイル使用メモリ | 256,312 KB |
| 最終ジャッジ日時 | 2025-01-22 19:06:51 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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;
}
沙耶花