結果

問題 No.463 魔法使いのすごろく🎲
ユーザー Hoi_koroHoi_koro
提出日時 2016-12-14 13:23:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 2,754 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 119,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 06:33:35
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define dump(a) cerr<<#a <<' '<< a <<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;
const double eps=1e-12;
typedef vector<vector<double >> Matrix;
void multiply(const Matrix &a, const Matrix &b, Matrix &ret){ //ret=a*b
    int k=a.size(),l=a[0].size(),m=b[0].size();
    if(l!=b.size()) DBG("!size")
    for(int h=0;h<k;++h){
        for(int i=0;i<m;++i){
            ret[h][i]=0.0;
            for(int j=0;j<l;j++){
                ret[h][i]+=a[h][j]*b[j][i];
            }
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<< setprecision(11);
    int n,m;
    cin >> n >> m;
    if(n==2){cout<< 0 <<endl; return 0;}
    Matrix c(2*(n-2),vector<double>(1));
    vector<double> dp(n),lc(n),dp2(n,1e18);
    FOR(i,0,n-2) {
        cin >>c[i+(n-2)][0];
        lc[i+1]=c[i+(n-2)][0];
    }
    Matrix a((n-2)*2,vector<double>((n-2)*2));//p[1]~p[m-2]c[1]~c[n-2]
    Matrix b((n-2)*2,vector<double>((n-2)*2));//p[1]~p[m-2]c[1]~c[n-2]
    REP(i,n-2){
        REP(j,n-2){
            if(i<j && j<i+m+1){
                a[i][j]+=1.0;
                a[i][j+(n-2)]+=1.0;
            }
            if(i+j>=(n-2)*2-m){
                a[i][j]+=1.0;
                a[i][j+(n-2)]+=1.0;
            }
            if(i==j){
                a[i+(n-2)][j+(n-2)]+=1.0;
            }
            a[i][j]/=m;
            a[i][j+(n-2)]/=m;
        }
    }

    REP(i,20){
        multiply(a,a,b);
        swap(a,b);
    }

    Matrix p(2*(n-2),vector<double>(1));
    multiply(a,c,p);
    //REP(i,n-2) cout << i <<' '<< p[i][0]<<endl;
    for(int i=n-2-m;i>=0;--i){
        FOR(j,i+1,i+m+1){
            dp[i]+=dp[j]+lc[j];
            dp2[i]=min(dp2[i],p[j-1][0]+lc[j]);
        }
        dp[i]=min(dp[i]/m,dp2[i]);
    }

    //REP(i,n-2) cout << i <<' '<< dp[i]<<endl;
    cout << dp[0]<<endl;


    return 0;
}
0