結果

問題 No.463 魔法使いのすごろく🎲
ユーザー btkbtk
提出日時 2017-12-22 00:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,226 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 174,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 21:04:38
合計ジャッジ時間 3,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
int n,m;
typedef double D;
constexpr D eps = 1e-10;
inline bool isZero(D x){
    return abs(x)<eps;
}
typedef vector<D> Vec;

void calc(vector<Vec>& mat){
    REP(i,n){
        int p = i;
        FOR(j,i,n){
            if(!isZero(mat[j][i])){
                p=j;
                break;
            }
        }
        swap(mat[i],mat[p]);
        REP(j,n+1)if(i!=j)mat[i][j]/=mat[i][i];
        mat[i][i] = 1;
        REP(j,n)if(i!=j){
            REP(k,n+1)if(i!=k)mat[j][k]-=mat[i][k]*mat[j][i];
            mat[j][i]=0;
        }
    }
}

void solve(int v,Vec& dp,vector<int> &vis,Vec& in,vector<Vec>&mat){
    if(vis[v]==1)return;
    vis[v]=1;
    dp[v]=0;
    if(n-1-v<=m){
        return;
    }
    FOR(i,1,m+1){
        solve(v+i,dp,vis,in,mat);
        dp[v]+=(in[v+i]+dp[v+i])/m;
    }
    FOR(i,1,m+1){
        chmin(dp[v],in[v+i]+mat[v+i].back());
    }
}
int main(){
    cin>>n>>m;
    cout<<fixed;
    cout<<setprecision(10);
    vector<Vec> x;
    vector<double> in(n,0.0);
    Vec dp(n,0.0);
    vector<int> vis(n,0);
    FOR(i,1,n-1)cin>>in[i];
    REP(i,n-1){
        Vec y(n+1);
        FOR(j,1,m+1){
            int nxt= i+j+1;
            if(nxt>n)nxt=2*n-nxt;
            nxt--;
            y[nxt]+=1.0/m;
            y.back()-=in[nxt]/m;
        }
        y[i]-=1.0;
        x.pb(y);
    }
    x.pb(Vec(n+1,0.0));
    x.back()[n-1]=1.0;
    calc(x);
    solve(0,dp,vis,in,x);
    cout<<dp[0]<<endl;
    return 0;
}
0