結果

問題 No.813 ユキちゃんの冒険
ユーザー 👑 emthrmemthrm
提出日時 2019-04-12 23:13:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,756 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 120,416 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-30 13:35:53
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 707 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int n;
double ans = 0, p, q;

double border[10001];
void border_init() {
  border[1] = 1;
  FOR(i, 2, 10001) {
    border[i] = border[i - 1] * q;
  }
}

void calc(int pos, bool right, double now) {
  if (now * border[pos] < 1e-11) return;
  if (right) {
    if (pos == 1) {
      ans += now * p;
      calc(pos + 1, true, now * q);
    } else if (pos == n) {
      calc(pos - 1, false, now * p);
    } else {
      calc(pos - 1, false, now * p);
      calc(pos + 1, true, now * q);
    }
  } else {
    if (pos == 1) {
      ans += now * q;
      calc(pos + 1, true, now * p);
    } else if (pos == n) {
      calc(pos - 1, false, now * q);
    } else {
      calc(pos - 1, false, now * q);
      calc(pos + 1, true, now * p);
    }
  }
}

int main() {
  // freopen("input.txt", "r", stdin);

  cin >> n >> p >> q;
  border_init();
  calc(1, true, 1);
  printf("%.5f\n", ans);
  return 0;
}
0