結果

問題 No.2222 Respawn
ユーザー stoqstoq
提出日時 2022-05-28 04:01:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,136 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 206,448 KB
実行使用メモリ 814,608 KB
最終ジャッジ日時 2023-09-24 05:10:43
合計ジャッジ時間 5,743 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// f(x) = a + bx
using linear = pair<double, double>;
linear operator+(linear f, linear g) {
  return {f.first + g.first, f.second + g.second};
}
linear operator+(linear f, double a) { return {f.first + a, f.second}; }
linear operator/(linear f, double a) { return {f.first / a, f.second / a}; }
// f(x) = 0
double solve(linear f) { return -f.first / f.second; }
// f(a)
double eval(linear f, double a) { return f.first + f.second * a; }

int main() {
  int n;
  string s;
  cin >> n >> s;
  s.push_back('#');
  vector E(n + 1, vector<double>(n));
  for (int j = n - 2; j >= 0; j--) {
    if (s[j] == '#') continue;
    vector<linear> f(n + 1);
    for (int i = n; i > j; i--) {
      if (i == n - 1) {
        f[i] = {0, 0};
      } else if (s[i] == '.') {
        f[i] = (f[i + 1] + f[i + 2] + E[i][i]) / 3 + 1;
      } else {
        f[i] = {0, 1};
      }
    }
    E[j][j] = solve((f[j + 1] + f[j + 2] + linear{0, -2}) / 3 + 1);
    for (int i = j + 1; i <= n; i++) E[i][j] = eval(f[i], E[j][j]);
  }
  cout << setprecision(20) << setiosflags(ios::fixed);
  cout << E[0][0] << "\n";
}
0