結果
| 問題 |
No.1590 Random Shopping
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-07-09 00:34:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,465 bytes |
| コンパイル時間 | 1,501 ms |
| コンパイル使用メモリ | 121,860 KB |
| 最終ジャッジ日時 | 2025-01-22 19:54:06 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 5 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
using P = pair<int, int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
vector<int> a(n), r(n);
vector<P> p(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
p[i] = P(a[i], -i);
}
for(int i = 0; i < n; i++) cin >> r[i];
double ans = 0.0;
for(int i = 0; i < n; i++){
vector<vector<double>> dp(n+1, vector<double>(n+1));
dp[0][0] = 1.0;
for(int j = 0; j <= n; j++){
// cout << accumulate(dp[j].begin(), dp[j].end(), 0.0) << endl;
if(j > i && a[j] > a[i]){
ans += dp[j][1]*r[j]*a[i]*0.5;
}
if(j == i){
// cout << i << ' ' << j << ' ' << dp[j][0] << ' ' << accumulate(dp[j].begin(), dp[j].end(), 0.0) << endl;
ans += dp[j][0]*r[i]*a[i]*0.5;
}
if(j == n) break;
// 買わない
if(j < i){
if(a[j] < a[i]) dp[j+1][1] += dp[j][0]*0.5;
else dp[j+1][0] += dp[j][0]*0.5;
}else if(i == j){
dp[j+1][1] += dp[j][0]*0.5;
}else{
dp[j+1][0] += dp[j][0]*0.5;
}
// 買う
dp[j+1][0] += dp[j][0]*0.5;
for(int k = 1; k <= j; k++){
// 買う
if(p[j] <= p[i]){
dp[j+1][k] += dp[j][k]*0.5;
}else{
dp[j+1][k-1] += dp[j][k]*0.5;
}
// 買わない
if(p[j] <= p[i]){
dp[j+1][k+1] += dp[j][k]*0.5;
}else{
dp[j+1][k] += dp[j][k]*0.5;
}
}
}
}
cout << ans << endl;
}
milanis48663220