結果

問題 No.463 魔法使いのすごろく🎲
ユーザー pekempeypekempey
提出日時 2016-12-14 01:20:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,723 bytes
コンパイル時間 2,537 ms
コンパイル使用メモリ 173,880 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 13:41:16
合計ジャッジ時間 43,510 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 982 ms
5,248 KB
testcase_01 AC 966 ms
5,376 KB
testcase_02 AC 983 ms
5,376 KB
testcase_03 AC 986 ms
5,376 KB
testcase_04 AC 999 ms
5,376 KB
testcase_05 AC 986 ms
5,376 KB
testcase_06 AC 924 ms
5,376 KB
testcase_07 AC 929 ms
5,376 KB
testcase_08 AC 976 ms
5,376 KB
testcase_09 AC 1,073 ms
5,376 KB
testcase_10 AC 971 ms
5,376 KB
testcase_11 AC 1,034 ms
5,376 KB
testcase_12 AC 977 ms
5,376 KB
testcase_13 AC 904 ms
5,376 KB
testcase_14 AC 1,033 ms
5,376 KB
testcase_15 AC 1,020 ms
5,376 KB
testcase_16 AC 1,071 ms
5,376 KB
testcase_17 AC 989 ms
5,376 KB
testcase_18 AC 966 ms
5,376 KB
testcase_19 AC 970 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 991 ms
5,376 KB
testcase_22 AC 1,025 ms
5,376 KB
testcase_23 AC 1,022 ms
5,376 KB
testcase_24 AC 957 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,011 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 923 ms
5,376 KB
testcase_36 AC 972 ms
5,376 KB
testcase_37 AC 973 ms
5,376 KB
testcase_38 AC 893 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct SlideMin {
    deque<pair<long double, int>> q;
    int width;
    int t = 0;

    SlideMin(int width) : width(width) {}

    void add(long double x) {
        t++;
        while (!q.empty() && t - q.front().second >= width) {
            q.pop_front();
        }
        while (!q.empty() && q.back().first > x) {
            q.pop_back();
        }
        q.emplace_back(x, t);
    }

    long double minimum() {
        return q.front().first;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    const int M = n * 2 - 2;

    vector<long double> c(M * 2);
    for (int i = 1; i < n - 1; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < n - 2; i++) {
        c[n + i] = c[n - 2 - i];
    }
    for (int i = 0; i < M; i++) {
        c[i + M] = c[i];
    }

    const int T = 30000000 / M;

    double mm = 1.0 / m;

    vector<long double> E(M * 2), EE(M * 2);
    SlideMin q(m);
    q.add(0);
    long double sumE = 0;
    long double sumEE = 0;
    for (int i = 0; i < m; i++) {
        sumE += c[i];
        sumEE += c[i];
    }
    for (int ii = 0; ii < T; ii++) {
        for (int i = 0; i < M; i++) {
            E[i + M] = E[i];
            EE[i + M] = EE[i];
        }
        for (int i = M - 1; i >= 0; i--) {
            E[i] = 0;
            EE[i] = 0;
            if (i != n - 1) {
                E[i] = min(sumE * mm, q.minimum());
                EE[i] += sumEE * mm;
            }
            q.add(EE[i] + c[i]);
            sumE += E[i] + c[i];
            sumEE += EE[i] + c[i];
            sumE -= E[i + m] + c[i + m];
            sumEE -= EE[i + m] + c[i + m];
        }
    }

    printf("%.20f\n", (double)min(E[0], EE[0]));
}
0