結果
| 問題 | 
                            No.1590 Random Shopping
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chocorusk
                         | 
                    
| 提出日時 | 2021-07-08 23:00:52 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,380 ms / 5,000 ms | 
| コード長 | 1,696 bytes | 
| コンパイル時間 | 5,356 ms | 
| コンパイル使用メモリ | 180,972 KB | 
| 最終ジャッジ日時 | 2025-01-22 19:08:02 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
double dp[505][505];
int main()
{
    int n; cin>>n;
    int a[505], r[505];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        cin>>r[i];
    }
    double p[505][1010]={};
    for(int i=1; i<=1001; i++){
        for(int j=0; j<=n; j++) for(int k=0; k<=j; k++) dp[j][k]=0;
        dp[0][0]=1;
        for(int j=0; j<n; j++){
            for(int k=0; k<=j; k++){
                if(a[j]>=i){
                    if(k>0){
                        dp[j+1][k-1]+=dp[j][k]*0.5;
                        dp[j+1][k]+=dp[j][k]*0.5;
                        p[j][i]+=dp[j][k]*0.5;
                    }else{
                        dp[j+1][k]+=dp[j][k];
                    }
                }else{
                    dp[j+1][k]+=dp[j][k]*0.5;
                    dp[j+1][k+1]+=dp[j][k]*0.5;
                    p[j][i]+=dp[j][k]*0.5;
                }
            }
        }
    }
    double ans=0;
    for(int i=1; i<=1000; i++){
        for(int j=0; j<n; j++){
            ans+=r[j]*i*(p[j][i+1]-p[j][i]);
        }
    }
    printf("%.8lf\n", ans);
    return 0;
}
            
            
            
        
            
chocorusk