結果

問題 No.813 ユキちゃんの冒険
コンテスト
ユーザー akakimidori
提出日時 2019-04-12 22:01:14
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 932 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 203 ms
コンパイル使用メモリ 39,876 KB
最終ジャッジ日時 2026-02-22 02:55:15
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

#define POS(dir,j) ((dir) * (n + 2) + (j))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  double p, q;
  scanf ("%lf%lf", &p, &q);
  double *now = (double *) calloc (2 * (n + 2), sizeof (double));
  double *next = (double *) calloc (2 * (n + 2), sizeof (double));
  now[POS(0, 1)] = 1;
  double ans = 0;
  for (i32 iter = 0; iter < 5000; iter++) {
    memset (next, 0, sizeof (double) * 2 * (n + 2));
    for (i32 dir = 0; dir < 2; dir++) {
      i32 dx = dir == 0 ? 1 : -1;
      for (i32 i = 1; i <= n; ++i) {
	next[POS(dir, i + dx)] += q * now[POS(dir, i)];
	next[POS(dir ^ 1, i - dx)] += p * now[POS(dir, i)];
      }
    }
    memcpy (now, next, sizeof (double) * 2 * (n + 2));
    ans += next[POS(0, 0)] + next[POS(1, 0)];
  }
  printf ("%.6f\n", ans);
}

int main (void) {
  run ();
  return 0;
}
0