結果

問題 No.1590 Random Shopping
ユーザー kenskens
提出日時 2021-07-10 16:17:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 818 ms / 5,000 ms
コード長 1,164 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 217,796 KB
実行使用メモリ 7,164 KB
最終ジャッジ日時 2023-09-14 19:38:23
合計ジャッジ時間 8,504 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 14 ms
4,376 KB
testcase_12 AC 53 ms
4,376 KB
testcase_13 AC 213 ms
4,572 KB
testcase_14 AC 637 ms
6,128 KB
testcase_15 AC 639 ms
6,204 KB
testcase_16 AC 640 ms
6,236 KB
testcase_17 AC 620 ms
6,268 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 817 ms
7,112 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 818 ms
7,164 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n), r(n), b(n+1), id(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> r[i];
  b[0] = 0;
  rep(i,n) b[i+1] = a[i];
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());
  int m = b.size();
  map<int,int> mp;
  rep(i,m) mp[b[i]] = i;
  rep(i,n) id[i] = mp[a[i]];
  vector<vector<double>> dp(m+1,vector<double>(n+1));
  rep(j,id[0]) dp[j][0] = 1.0;
  for(int j = id[0]; j < m; j++) dp[j][1] = 1.0;
  double ans = 0.0;
  rep(i,n) {
    for(int j = 1; j <= m; j++) ans += dp[j-1][0]*r[i]*(b[j]-b[j-1])/2;
    vector<vector<double>> dpn(m+1,vector<double>(n+1));
    if(i == n-1) break;
    rep(j,m+1) {
      int nk = 0;
      if(j >= id[i+1]) nk++;
      dpn[j][nk] += dp[j][0];
    }
    rep(j,m+1) for(int k = 1; k <= n; k++) {
      for(int df = -1; df <= 0; df++) {
        int nk = k+df;
        if(j >= id[i+1]) nk++;
        if(nk >= 0 and nk <= n) dpn[j][nk] += dp[j][k]/2.0;
      }
    }
    swap(dp,dpn);
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}
0