結果
| 問題 |
No.813 ユキちゃんの冒険
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2019-04-13 07:42:35 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 947 bytes |
| コンパイル時間 | 301 ms |
| コンパイル使用メモリ | 27,264 KB |
| 実行使用メモリ | 13,764 KB |
| 最終ジャッジ日時 | 2025-01-02 06:27:19 |
| 合計ジャッジ時間 | 14,292 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 WA * 1 TLE * 3 |
コンパイルメッセージ
main.c: In function ‘run’:
main.c:13:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf ("%" SCNi32, &n);
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:15:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf ("%lf%lf", &p, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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 < 50000; 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;
}
akakimidori