結果

問題 No.463 魔法使いのすごろく🎲
ユーザー rickythetarickytheta
提出日時 2016-12-14 00:15:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,830 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 145,328 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-08-20 02:26:28
合計ジャッジ時間 3,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,620 KB
testcase_01 AC 6 ms
7,836 KB
testcase_02 AC 7 ms
7,684 KB
testcase_03 AC 4 ms
7,508 KB
testcase_04 AC 5 ms
7,636 KB
testcase_05 AC 5 ms
7,696 KB
testcase_06 AC 5 ms
7,456 KB
testcase_07 AC 4 ms
7,372 KB
testcase_08 AC 9 ms
7,636 KB
testcase_09 AC 7 ms
7,520 KB
testcase_10 AC 6 ms
7,608 KB
testcase_11 AC 26 ms
7,660 KB
testcase_12 AC 14 ms
7,696 KB
testcase_13 AC 4 ms
7,428 KB
testcase_14 AC 12 ms
7,612 KB
testcase_15 AC 18 ms
7,660 KB
testcase_16 AC 4 ms
7,516 KB
testcase_17 AC 23 ms
7,556 KB
testcase_18 AC 4 ms
7,724 KB
testcase_19 AC 7 ms
7,712 KB
testcase_20 AC 4 ms
7,684 KB
testcase_21 AC 35 ms
7,876 KB
testcase_22 AC 126 ms
7,632 KB
testcase_23 AC 124 ms
7,644 KB
testcase_24 AC 4 ms
7,444 KB
testcase_25 AC 6 ms
7,880 KB
testcase_26 AC 8 ms
7,620 KB
testcase_27 AC 5 ms
7,520 KB
testcase_28 AC 51 ms
7,556 KB
testcase_29 AC 5 ms
7,660 KB
testcase_30 AC 14 ms
7,632 KB
testcase_31 AC 5 ms
7,644 KB
testcase_32 AC 14 ms
7,764 KB
testcase_33 AC 6 ms
7,644 KB
testcase_34 AC 5 ms
7,640 KB
testcase_35 AC 4 ms
7,448 KB
testcase_36 AC 4 ms
7,684 KB
testcase_37 AC 5 ms
7,880 KB
testcase_38 AC 4 ms
7,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;


const int T = 2000;
int n,m;
Real c[125];
Real dp[2][T][125];

Real indfs(int x,int y,int z);
inline Real dfs(int x,int y,int z){
  if(dp[x][y][z]!=-1)return dp[x][y][z];
  // dp[x][y][z] = indfs(x,y,z);
  // printf("%d %d %d -> %f\n",x,y,z,dp[x][y][z]);
  // return dp[x][y][z];
  return dp[x][y][z] = indfs(x,y,z);
}
Real indfs(int x,int y,int z){
  if(y==T-1)return c[z];
  if(z==n-1)return 0.0;
  if(x==1){
    // can't use
    Real ans = 0.0;
    FOR(i,1,m+1){
      ans += dfs(x,y+1,min(z+i,2*n-2-z-i));
    }
    return ans/(Real)m + c[z];
  }else{
    // can use
    // don't use
    Real a = 0.0;
    FOR(i,1,m+1)a += dfs(x,y+1,min(z+i,2*n-2-z-i));
    a /= (Real)m;
    Real b = 1.0e25;
    FOR(i,1,m+1)CHMIN(b,dfs(1,y+1,min(z+i,2*n-2-z-i)));
    return min(a,b) + c[z];
  }
}

int main(){
  scanf("%d%d",&n,&m);
  c[0] = 0.0;
  c[n-1] = 0.0;
  FOR(i,1,n-1)scanf("%lf",c+i);
  REP(i,2)REP(j,T)REP(k,n)dp[i][j][k] = -1;
  Real ans = dfs(0,0,0);
  printf("%.12f\n",ans);
  return 0;
}
0