結果

問題 No.2222 Respawn
ユーザー SSRSSSRS
提出日時 2023-02-17 22:28:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,543 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 169,120 KB
実行使用メモリ 14,504 KB
最終ジャッジ日時 2023-09-26 19:45:16
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 14 ms
10,872 KB
testcase_14 AC 10 ms
8,316 KB
testcase_15 AC 6 ms
5,800 KB
testcase_16 AC 9 ms
7,780 KB
testcase_17 AC 6 ms
5,728 KB
testcase_18 AC 19 ms
14,228 KB
testcase_19 AC 19 ms
14,344 KB
testcase_20 AC 19 ms
14,220 KB
testcase_21 AC 19 ms
14,276 KB
testcase_22 AC 19 ms
14,280 KB
testcase_23 AC 21 ms
14,504 KB
testcase_24 AC 22 ms
14,264 KB
testcase_25 AC 21 ms
14,280 KB
testcase_26 AC 21 ms
14,304 KB
testcase_27 AC 21 ms
14,396 KB
testcase_28 AC 26 ms
14,216 KB
testcase_29 AC 25 ms
14,248 KB
testcase_30 AC 27 ms
14,264 KB
testcase_31 AC 17 ms
14,212 KB
testcase_32 AC 129 ms
14,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  string S;
  cin >> S;
  S += '#';
  vector<double> dp_gameover_p(N, 0);
  vector<double> dp_gameover_pe(N, 0);
  vector<double> dp_goal_p(N, 0);
  vector<double> dp_goal_pe(N, 0);
  dp_goal_p[N - 1] = 1;
  for (int i = N - 2; i >= 0; i--){
    if (S[i] == '.'){
      for (int j = i + 1; j <= i + 2; j++){
        if (S[j] == '#'){
          dp_gameover_p[i] += (double) 1 / 3;
          dp_gameover_pe[i] += (double) 1 / 3;
        } else {
          dp_gameover_p[i] += dp_gameover_p[j] / 3;
          dp_gameover_pe[i] += (dp_gameover_p[j] + dp_gameover_pe[j]) / 3;
          dp_goal_p[i] += dp_goal_p[j] / 3;
          dp_goal_pe[i] += (dp_goal_p[j] + dp_goal_pe[j]) / 3;
        }
      }
    }
  }
  vector<double> dp(N, 0);
  vector<double> dp2_p(N, 0), dp2_pe(N, 0);
  for (int i = N - 2; i >= 0; i--){
    if (S[i] == '.'){
      double gameover_p = dp_gameover_p[i] + (double) 1 / 3;
      double gameover_pe = dp_gameover_pe[i] + (double) 1 / 3;
      dp[i] += (1 / (1 - gameover_p) - 1) * (gameover_pe / gameover_p);
      dp[i] += dp_goal_pe[i] / (1 - gameover_p);
      for (int j = i + 1; j <= i + 2; j++){
        if (S[j] == '.' && j < N - 1){
          dp2_p[i] += (double) 1 / 9;
          dp2_pe[i] += (2 + dp[j]) / 9;
          dp2_p[i] += dp2_p[j] / 3;
          dp2_pe[i] += (dp2_p[j] + dp2_pe[j]) / 3;
        }
      }
      dp[i] += dp2_pe[i] / (1 - gameover_p);
    }
  }
  cout << dp[0] << endl;
}
0