結果

問題 No.1590 Random Shopping
ユーザー milanis48663220milanis48663220
提出日時 2021-07-09 00:43:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 712 ms / 5,000 ms
コード長 2,464 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 124,024 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-09-14 06:13:37
合計ジャッジ時間 8,215 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 42 ms
4,380 KB
testcase_13 AC 193 ms
4,376 KB
testcase_14 AC 668 ms
5,132 KB
testcase_15 AC 670 ms
5,100 KB
testcase_16 AC 676 ms
5,168 KB
testcase_17 AC 678 ms
5,228 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 668 ms
5,160 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 679 ms
5,076 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 712 ms
5,084 KB
testcase_24 AC 699 ms
5,140 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0