結果

問題 No.463 魔法使いのすごろく🎲
ユーザー vjudge1
提出日時 2025-06-22 11:17:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 162,736 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-22 11:17:55
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:2:25: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    2 | # define FILE(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:11:5: note: in expansion of macro ‘FILE’
   11 |     FILE("turnback");
      |     ^~~~
main.cpp:2:54: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    2 | # define FILE(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:11:5: note: in expansion of macro ‘FILE’
   11 |     FILE("turnback");
      |     ^~~~

ソースコード

diff #

# include <bits/stdc++.h>
# define FILE(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
using namespace std;
const int N = 105;
int n;
double m;
double a[N];
double f[N][2];
int main()
{   
    FILE("turnback");
    cin >> n >> m;
    for (int i = 2; i < n; i ++)
    {
        cin >> a[i];
    }
    for (int i = n - 1; i >= 1; i --)
    {
        double sum = 0;
        for (int k = 1; k <= m; k ++)
        {
            int j = i + k;
            if (j > n) j = 2 * n - j;
            sum += f[j][1];
        }
        f[i][1] = a[i] + sum * 1.0 / m;
        sum = 0;
        for (int k = 1; k <= m; k ++)
        {
            int j = i + k;
            if (j > n) j = 2 * n - j;
            sum += f[j][0];
        }
        double op = a[i] + sum / m;
        double res = 1e18;
        for (int k = 1; k <= m; k ++)
        {
            int j = i + k;
            if (j > n) j = 2 * n - j;
            res = min(res, f[j][1]);
        }
        double op2 = a[i] + res;
        f[i][0] = min(op, op2);
    }
    printf("%.9lf", f[1][0]);
    return 0;
}
0