結果
問題 | No.813 ユキちゃんの冒険 |
ユーザー |
![]() |
提出日時 | 2019-04-12 22:01:14 |
言語 | C (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 932 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 27,392 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-02 03:19:57 |
合計ジャッジ時間 | 1,763 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 1 |
コンパイルメッセージ
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 < 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;}