結果

問題 No.463 魔法使いのすごろく🎲
ユーザー r_dream0r_dream0
提出日時 2017-02-20 22:03:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,783 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 86,016 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-28 21:50:56
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

int n, m;
vector<double> c;

int main() {
  cin >> n >> m;
  c = vector<double>(n);
  for(int i = 1; i < n - 1; i++) {
    cin >> c[i];
  }
  // 後ろからの期待値
  // x_i マス iに居る時の期待値
  vector<vector<double>> M(n, vector<double>(n + 1));
  // x_n = 0
  M[n-1][n-1] = 1;
  M[n-1][n] = 0;
  for(int i = 0; i < n - 1; i++) {
    for(int j = 1; j <= m; j++) {
      int to = i + j;
      if(to >= n) to = n - (to - n) - 1;
      M[i][to] = -1.0 / m;
    }
    M[i][i] = 1;
    M[i][n] = c[i];
  }
  // for(int i = 0; i < n; i++) {
  //   for(int j = 0; j <= n; j++) {
  //     cout 
  //       << M[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  for(int i = 0; i < n; i++) {
    int pivot = i;
    for(int j = i; j < n; j++) {
      if(fabs(M[j][i]) > fabs(M[pivot][i])) pivot = j;
    }
    swap(M[pivot], M[i]);
    for(int j = i + 1; j <= n; j++) {
      M[i][j] /= M[i][i];
    }
    M[i][i] = 1;
    for(int j = 0; j < n; j++) {
      if(i == j) continue;
      double div = M[j][i] / M[i][i];
      for(int k = 0; k <= n; k++) {
        M[j][k] -= div * M[i][k];
      }
    }
  }
  vector<double> de(n), dp(n);
  for(int i = 0; i < n; i++) de[i] = M[i][n];
  for(int i = n - 1; i >= 0; i--) {
    if(i + m >= n - 1) dp[i] = min(de[i], c[i]);
    else {
      double t1 = 0;
      for(int j = 1; j <= m; j++) {
        t1 += dp[j + i];
      }
      dp[i] = min(de[i], t1 / m + c[i]);
      for(int j = 1; j <= m; j++) {
        // dp[i] = min(dp[i], c[i] + de[i + j]);
      }
    }
  }
  cout << fixed << setprecision(10) << dp[0] << endl;
  // for(int i = 0; i < n; i++) {
  //   cout << dp[i] << "," << de[i] << endl;
  // }
}
0