結果
| 問題 | No.463 魔法使いのすごろく🎲 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-06-20 17:18:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 134 ms / 2,000 ms |
| コード長 | 2,280 bytes |
| 記録 | |
| コンパイル時間 | 1,930 ms |
| コンパイル使用メモリ | 198,044 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-20 17:18:22 |
| 合計ジャッジ時間 | 3,933 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include<bits/stdc++.h>
#define int long long
#define all(v)v.begin(),v.end()
#define rall(v)v.rbegin(),v.rend()
bool st;
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T> v){for(auto i:v)O<<i<<' ';return O;}
string TMP,STR;
stringstream CIN;
void read_all(){
#ifdef debug
cerr<<"----------------------------------- START -----------------------------------\n";
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while(getline(cin,TMP))STR+=TMP,STR+='\n';
CIN.str(STR);
cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
#endif
}
#ifdef debug
#define cin CIN
#endif
namespace AC{
const int T=1001,N=101;
int n,m;
double dp[T][N][2],c[100],P;
double f(int t,int pos,int mag){
double&res=dp[t][pos][mag];
if(res>-1)return res;
if(pos==n-1||t==T-1)return res=0;
double x=0,y=numeric_limits<double>::max();
for(int i=1;i<=m;++i){
int npos=pos+i;
if(npos>=n)npos=2*(n-1)-npos;
x+=P*(c[npos]+f(t+1,npos,mag));
if(!mag)y=min(y,c[npos]+f(t+1,npos,1));
}
return res=min(x,y);
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n-2;++i)cin>>c[i];
for(int i=0;i<T;i++)for(int j=0;j<=n;j++)for(int k=0;k<2;k++)dp[i][j][k]=-2;
P=1.0/m;
double ans=f(0,0,0);
cout<<setprecision(20)<<ans<<endl;
}
}
bool ed;
signed main(){
chrono::steady_clock::time_point St=chrono::steady_clock::now();
read_all();
chrono::steady_clock::time_point ST=chrono::steady_clock::now();
int t=1;
//cin>>t;
while(t--)AC::solve();
chrono::steady_clock::time_point ED=chrono::steady_clock::now();
cerr<<setprecision(3)<<fixed<<"\n\n------------------------------------ END ------------------------------------\n"<<"Total Time : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-St).count()<<" \tms\n"<<"Real Time : "<<left<<setw(10)<<chrono::duration_cast<chrono::milliseconds>(ED-ST).count()<<" \tms\n"<<" : "<<left<<setw(10)<<chrono::duration_cast<chrono::microseconds>(ED-ST).count()<<" \t?s\n\n"<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<" "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<" "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
}
vjudge1