Problem:
Problem F:
Atomic Car Race
In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling
is not a concern of racing teams. Cars can run throughout the course without any refueling.
Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of
their cars.
The race is a road race having n checkpoints in the course. Their distances from the start are
a
1
,
a
2
, ... , and
a
n
(in kilometers). The
n
-th checkpoint is the goal. At the
i
-th checkpoint (
i
<
n
),
tires of a car can be changed. Of course, a team can choose whether to change or not to change
tires at each checkpoint. It takes
b
seconds to change tires (including overhead for braking and
accelerating). There is no time loss at a checkpoint if a team chooses not to change tires.
A car cannot run fast for a while after a tire change, because the temperature of tires is lower
than the designed optimum. After running long without any tire changes, on the other hand,
a car cannot run fast because worn tires cannot grip the road surface well. The time to run
an interval of one kilometer from
x
to
x
+ 1 is given by the following expression (in seconds).
Here
x
is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint
where tires are changed (or the start).
r
,
v
,
e
and
f
are given constants.
1/(
v
-
e
× (
x
-
r
)) (if
x
≥
r
)
1/(
v
-
f
× (
r
-
x
)) (if
x
<
r
)
Your mission is to write a program to determine the best strategy of tire changes which minimizes
the total time to the goal.
Input
The input consists of multiple datasets each corresponding to a race situation. The format of a
dataset is as follows.
n
a
1
a
2
. . .
a
n
b
r v e f
The meaning of each of the input items is given in the problem statement. If an input line
contains two or more input items, they are separated by a space.
n
is a positive integer not exceeding 100. Each of
a
1
,
a
2
, ... , and
a
n
is a positive integer satisfying 0 <
a
1
<
a
2
< . . . <
a
n
≤ 10000.
b
is a positive decimal fraction not exceeding 100.0.
r
is a
nonnegative integer satisfying 0 ≤
r
≤
a
n
- 1. Each of
v
,
e
and
f
is a positive decimal fraction.
You can assume that
v
-
e
× (
a
n
- 1 -
r
) ≥ 0.01 and
v
-
f
×
r
≥ 0.01.
The end of the input is indicated by a line with a single zero.
Output
For each dataset in the input, one line containing a decimal fraction should be output. The
decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is
taken. An output line should not contain extra characters such as spaces.
The answer should not have an error greater than 0.001. You may output any number of digits
after the decimal point, provided that the above accuracy condition is satisfied.
Sample Input
2
2 3
1.0
1 1.0 0.1 0.3
5
5 10 15 20 25
0.15
1 1.0 0.04 0.5
10
1783 3640 3991 4623 5465 5481 6369 6533 6865 8425
4.172
72 59.4705 0.0052834 0.0611224
0
Output for the Sample Input
3.5397
31.9249
168.6682

Submitted solutions:

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

int main() {
  int n;
  while ( cin >> n, n ) {
    vector<int> a(n+1);
    vector<double> d(10001, 100000000.0);
    d[0] = 0;
    vector<int> is(10001, 0);
    a[0] = 0;
    for ( int i = 1; i <= n; i++ ) {
      cin >> a[i];
      is[a[i]] = 1;
    }

    double b;
    cin >> b;
    
    int r;
    double v, e, f;
    cin >> r >> v >> e >> f;

    for ( int i = 0; i < n; i++ ) {
      int x = 0;
      vector<double> dd = d;
      if ( i > 0 ) d[a[i]] += b;      
      for ( int j = a[i]; j < a[n]; j++ ) {
	if ( x >= r ) {
	  d[j+1] = d[j]+(1.0/(v-e*(x-r)));	  
	} else {
	  d[j+1] = d[j]+(1.0/(v-f*(r-x)));	  
	}
	x++;	
      }
      for ( int j = 1; j <= n; j++ ) {
	d[a[j]] = min(d[a[j]], dd[a[j]]);	
      }
    }

    printf("%.12lf\n", d[a[n]]);    
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3248
final_rank: 9

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int check_point[101];
double min_time[101][101];
double B,R,V,E,F;


double calcTime(int x){
	if(x >= R){

		return 1.0/(V-E*((double)x-R));
	}else{

		return 1.0/(V-F*(R-(double)x));
	}
}

void func(){

	check_point[0] = 0.0;
	for(int i = 1; i <= N; i++)scanf("%d",&check_point[i]);
	scanf("%lf",&B);
	scanf("%lf %lf %lf %lf",&R,&V,&E,&F);

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= i; k++)min_time[i][k] = DBL_MAX;
	}

	min_time[0][0] = 0;

	int x;
	double add_time;

	for(int point = 1; point <= N; point++){
		for(int changed_loc = 0; changed_loc <= point-1; changed_loc++){
			add_time = 0.0;
			for(int loc = check_point[point-1]; loc <= check_point[point]-1; loc++){
				x = loc - check_point[changed_loc];
				add_time += calcTime(x);
			}

			min_time[point][changed_loc] = min(min_time[point][changed_loc],min_time[point-1][changed_loc]+add_time);

			min_time[point][point] = min(min_time[point][point],min_time[point-1][changed_loc]+add_time+B);
		}
	}

	double ans = DBL_MAX;
	for(int i = 0; i < N; i++)ans = min(ans,min_time[N][i]);

	printf("%.10lf\n",ans);
}


int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3180
final_rank: 7

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#define N_MAX 105
#define X_MAX 10010
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<double,P > P1;
void dijkstra();
double Cal(int,int);
int n,a[N_MAX],r;
double b,v,e,f,dp[X_MAX][N_MAX];

int main(){
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>b>>r>>v>>e>>f;
    dijkstra();
  }
  return 0;
}

void dijkstra(){
  for(int i=0;i<X_MAX;i++)
    for(int j=0;j<n;j++) dp[i][j]=INF;
  priority_queue<P1,vector<P1>,greater<P1> > Q;
  dp[0][0]=Cal(0,a[0]);
  if(n!=1) Q.push(make_pair(dp[0][0],make_pair(a[0],1)));
  while(!Q.empty()){
    P1 v=Q.top();
    Q.pop();
    double t=v.first;
    int uy=v.second.first,ux=v.second.second;
    int ncny=uy+a[ux]-a[ux-1];
    double nccal=Cal(uy,ncny);
    if(dp[ncny][ux]>t+nccal){
      dp[ncny][ux]=t+nccal;
      if(ux!=n-1) Q.push(make_pair(dp[ncny][ux],make_pair(ncny,ux+1)));
    }
    int cny=a[ux]-a[ux-1];
    double ccal=Cal(0,cny)+b;
    if(dp[cny][ux]>t+ccal){
      dp[cny][ux]=t+ccal;
      if(ux!=n-1) Q.push(make_pair(dp[cny][ux],make_pair(cny,ux+1)));
    }
  }
  double mincost=INF;
  for(int i=0;i<=a[n-1];i++) mincost=min(mincost,dp[i][n-1]);
  printf("%.4f\n",mincost);
}

double Cal(int begin,int end){
  double ret=0;
  for(int i=begin;i<end;i++){
    if(i>=r) ret+=1.0/(1.0*v-1.0*e*(1.0*i-1.0*r));
    else ret+=1.0/(1.0*v-1.0*f*(1.0*r-1.0*i));
  }
  return ret;
}
accuracy: 1
time_ms: 70
memory_kb: 9468
final_rank: 10

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#define N_MAX 105
#define X_MAX 10010
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<double,P > P1;
void dijkstra();
double Cal(int,int);
int n,a[N_MAX],r;
double b,v,e,f,dp[X_MAX][N_MAX];

int main(){
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>b>>r>>v>>e>>f;
    dijkstra();
  }
  return 0;
}

void dijkstra(){
  for(int i=0;i<X_MAX;i++)
    for(int j=0;j<n;j++) dp[i][j]=INF;
  priority_queue<P1,vector<P1>,greater<P1> > Q;
  dp[0][0]=Cal(0,a[0]);
  Q.push(make_pair(dp[0][0],make_pair(a[0],1)));
  while(!Q.empty()){
    P1 v=Q.top();
    Q.pop();
    double t=v.first;
    int uy=v.second.first,ux=v.second.second;
    int ncny=uy+a[ux]-a[ux-1];
    double nccal=Cal(uy,ncny);
    if(ncny<0) continue;
    if(dp[ncny][ux]>t+nccal){
      dp[ncny][ux]=t+nccal;
      if(ux!=n-1) Q.push(make_pair(dp[ncny][ux],make_pair(ncny,ux+1)));
    }
    int cny=a[ux]-a[ux-1];
    if(cny<0) continue;
    double ccal=Cal(0,cny)+b;
    if(dp[cny][ux]>t+ccal){
      dp[cny][ux]=t+ccal;
      if(ux!=n-1) Q.push(make_pair(dp[cny][ux],make_pair(cny,ux+1)));
    }
  }
  double mincost=INF;
  for(int i=0;i<=a[n-1];i++) mincost=min(mincost,dp[i][n-1]);
  printf("%.4f\n",mincost);
}

double Cal(int begin,int end){
  double ret=0;
  for(int i=begin;i<end;i++){
    if(i>=r) ret+=1.0/(1.0*v-1.0*e*(1.0*i-1.0*r));
    else ret+=1.0/(1.0*v-1.0*f*(1.0*r-1.0*i));
  }
  return ret;
}
accuracy: 1
time_ms: 70
memory_kb: 9468
final_rank: 10

code_snippet: #include <iostream>
#include <algorithm>
#include <cstdio>
#define INF 100000000
#define t first
#define x second
using namespace std;
typedef pair <double,int> P;
double b,v,e,f;
int r;
double mk(int x) {
  if(x >= r) return 1.0/(v-e*(x-r));
  return  1.0/(v-f*(r-x));
}

int main() {
  while(1) {
    int n,a[102]={};
    cin >> n;
    if(n==0) break;
    for(int i=1;i<=n;i++) cin >> a[i];
    cin >> b >> r >> v >> e >> f;
    P dp[10010]={};
    for(int i=1;i<=a[n];i++) dp[i] = make_pair(INF,0);
    
    for(int i=0;i<n;i++) {
      int nx=dp[a[i]].x,cx= 0;
      double nt=dp[a[i]].t,ct=dp[a[i]].t+b;

      for(int j=a[i]+1;j<=a[n];j++){
	nt += mk(nx),ct += mk(cx);
	dp[j] = min(dp[j],min((P){nt,++nx},(P){ct,++cx}));
      }
    }
    printf("%.4f\n",dp[a[n]].t);
  }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 1400
final_rank: 8

code_snippet: #include <iostream>
#include <algorithm>
#include <cstdio>
#define INF 2000000
#define t first
#define x second
using namespace std;
typedef pair <double,int> P;
double b,v,e,f;
int r;

double mk(int x) {
  if(x >= r) return 1.0/(v-e*(x-r));
  return  1.0/(v-f*(r-x));
}

int main() {
  while(1) {
    int n,a[110]={};
    cin >> n;
    if(n==0) break;
    for(int i=1;i<=n;i++) cin >> a[i];
    cin >> b;
    cin >> r >> v >> e >> f;
    P dp[10100]={};
    for(int i=1;i<=a[n];i++) dp[i] = make_pair(INF,0);

    for(int i=0;i<n;i++) {
      int tx;
      double tt;
      //No Change
      tx=dp[a[i]].x,  tt=dp[a[i]].t;
      for(int j=a[i]+1;j<=a[n];j++){
	double k = mk(tx);
	tt += k , tx++;
	dp[j] = min(dp[j],make_pair(tt,tx));
      }

      //Change
      tx= 0, tt=dp[a[i]].t+b;
      for(int j=a[i]+1;j<=a[n];j++){
	double k = mk(tx);
	tt +=k; tx++;
	dp[j] = min(dp[j],make_pair(tt,tx));
      }
      
    }
    printf("%.4f\n",dp[a[n]].t);
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 1400
final_rank: 6

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

double compute_next_x_duration(double x, double r, double v, double e, double f){
  if(x >= r){
    return 1.0 / (v - e * (x - r));
  }
  else{
    return 1.0 / (v - f * (r - x));
  }
}

double compute_duration(double from, double to, double r, double v, double e, double f){
  double sum = 0;
  
  for(int pos = 0; pos < to - from; pos++){
    sum += compute_next_x_duration(pos,r,v,e,f);
  }
  return sum;
}


double dp[101][101]; // dp[current_i][last_change_pos]

int main(){
  int num_of_checkpoints;
  while(~scanf("%d",&num_of_checkpoints)){
    if(num_of_checkpoints == 0) break;

    vector<int> checkpoints;
    checkpoints.push_back(0);
    for(int checkpoint_i = 0; checkpoint_i < num_of_checkpoints; checkpoint_i++){
      int pos;
      scanf("%d",&pos);
      checkpoints.push_back(pos);
    }
    double tire_change_time;
    scanf("%lf",&tire_change_time);
    double r,v,e,f;
    scanf("%lf %lf %lf %lf",&r,&v,&e,&f);

    fill((double*)dp,(double*)dp + 101 * 101,1000000000000.0);
    dp[0][0] = 0;
    for(int current_i = 0; current_i < checkpoints.size(); current_i++){
      for(int prev_i = 0; prev_i < current_i; prev_i++){
        // x is a nonnegative integer denoting the distance (in kilometers) 
        // from the latest checkpoint where tires are changed
        
        dp[current_i][prev_i]
          = min(dp[prev_i][prev_i]
                + compute_duration(checkpoints[prev_i],checkpoints[current_i],r,v,e,f),
                dp[current_i][prev_i]);

        dp[current_i][current_i]
          = min(dp[prev_i][prev_i]
                + compute_duration(checkpoints[prev_i],checkpoints[current_i],r,v,e,f)
                + tire_change_time,
                dp[current_i][current_i]);
      }
    }

    double res = numeric_limits<double>::max();
    for(int i = 0; i < checkpoints.size(); i++){
      res = min(res,dp[checkpoints.size()-1][i]);
    }
    printf("%lf\n",res);
  }
}
accuracy: 1
time_ms: 830
memory_kb: 1336
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
int n;
int a[200],r;
double b,v,e,f;
double dp[200];
int main(){
  while(cin>>n&&n){
    for(int i=1;i<=n;i++)cin>>a[i];
    cin>>b;
    cin>>r>>v>>e>>f;
    for(int i=0;i<=n;i++)dp[i]=INF;
    dp[0]=0;
    a[0]=0;
    for(int i=0;i<n;i++){
      int x=0;
      double sum=0;
      for(int j=i+1;j<=n;j++){
    while(a[i]+x<a[j]){
      double d;
      if(x>=r){
        d=x-r;
        sum += 1.0/(v-e*d);
      }else{
        d=r-x;
        sum += 1.0/(v-f*d);
      }
      x++;
    }
    if(i!=0)dp[j]=min(dp[j],dp[i]+b+sum);
    else dp[j]=min(dp[j],sum);
      }
    }
 
    printf("%.6f\n",dp[n]);
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1244
final_rank: 4

code_snippet: #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
 
inline double calc(int x, int r, double v, double e, double f) {
	if(x >= r) return 1.0 / (v - e * (x - r));
	return 1.0 / (v - f * (r - x));
}
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);
 
	for(int n; cin >> n && n;) {
		vector<int> a(n + 1, 0);
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
 
		double b;
		cin >> b;
 
		int r;
		double v, e, f;
		cin >> r >> v >> e >> f;
 
		vector<vector<double>> dp(n + 1, vector<double>(n + 1, INT_MAX));
		dp[0][0] = 0.0;
 
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j <= i; ++j) {
				chmin(dp[i][i], dp[i][j] + b);
 
				double next_cost = 0.0;
				for(int x = a[i]; x < a[i + 1]; ++x) {
					next_cost += calc(x - a[j], r, v, e, f);
				}

				chmin(dp[i + 1][j], dp[i][j] + next_cost);
			}
		}
 
		cout << *min_element(dp[n].begin(), dp[n].end()) << endl;
	}
 
	return EXIT_SUCCESS;
}
accuracy: 1
time_ms: 20
memory_kb: 1408
final_rank: 3

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

#define dump(a) (cerr << #a << " = " << (a) << endl)

#define REP(i,a,b) for(int i=(a);i < (int)(b); i++)
#define rep(i,n) REP(i,0,n)
#define ALL(v) begin(v), end(v)

double calc(int x, int r, double v, double e, double f) {
  if(x >= r) return 1.0 / (v - e * (x - r));
  return 1.0 / (v - f * (r - x));
}

int main(){
  cout.setf(ios::fixed);
  cout.precision(10);

  for(int n; cin >> n && n;) {
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; ++i) {
      cin >> a[i];
    }

    double b;
    cin >> b;

    int r;
    double v, e, f;
    cin >> r >> v >> e >> f;

    vector<vector<double>> dp(n + 1, vector<double>(n + 1, INT_MAX));
    dp[0][0] = 0;

    for(int i = 0; i < n; ++i) {
      for(int j = 0; j <= i; ++j) {
	if(dp[i][j] == INT_MAX) continue;

	dp[i][i] = min(dp[i][i], dp[i][j] + b);

	double next_cost = 0.0;
	for(int x = a[i]; x < a[i + 1]; ++x) {
	  next_cost += calc(x - a[j], r, v, e, f);
	}

	dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + next_cost);
      }
    }

    double ans = INT_MAX;
    for(int i = 0; i <= n; ++i) {
      ans = min(ans, dp[n][i]);
    }

    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1396
final_rank: 2

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<cassert>
#include<queue>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 101
#define inf (1<<29)
using namespace std;
int a[MAX];
int A[10001];
int n;
double b,r,v,e,f;
double mincost[MAX][10001];
 
struct P
{
  int last;
  double x,cost,now;
  P(double now=-1,double x=-1,double cost=-1,int last=-1):now(now),x(x),cost(cost),last(last){}
  bool operator < (const P &a)const
  {
    return cost >= a.cost;
  }
};
 
double getCost(double x)
{
  if(x >= r)return 1.0/(v - e * (x - r));
            return 1.0/(v - f * (r - x));    
}
 
void dijkstra()
{
  double ans = inf;
  rep(i,n)rep(j,10001)mincost[i][j] = inf;
  mincost[0][0] = 0;
 
  priority_queue<P> Q;
  Q.push(P(0,0,0,0));
 
  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      if(p.now >= a[n-1])
    {
      ans = min(ans,p.cost);
      continue;
    }    
 
      if(ans <= p.cost)continue;
 
      assert(0 <= p.cost);
      double ncost = p.cost + getCost(p.x);
      assert(0 <= ncost);
 
      if(mincost[p.last][(int)p.now+1] > ncost)
    {
      mincost[p.last][(int)p.now+1] = ncost;
      Q.push(P(p.now+1,p.x+1,ncost,p.last));
    }
 
      if(A[(int)p.now+1] != -1)
    {
      double change_cost = (A[(int)p.now+1]==n?0:b);
      ncost += change_cost;
      Q.push(P(p.now+1,0,ncost,A[(int)p.now+1]));
    }
 
    }
 
  cout << setiosflags(ios::fixed) << setprecision(4) << ans << endl;
}
 
int main()
{
  while(cin >> n,n)
    {
      rep(i,10001)A[i] = -1;
      rep(i,n)
    {
      cin >> a[i];     
      A[a[i]] = i+1; 
    }
      cin >> b >> r >> v >> e >> f;
    
 
      dijkstra();
 
    }
  return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 9536
final_rank: 15

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<cassert>
#include<queue>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 101
#define inf (1<<29)
using namespace std;
int a[MAX];
int A[10001];
int n;
double b,r,v,e,f;
double mincost[MAX][10001];

struct P
{
  int last;
  double x,cost,now;
  P(double now=-1,double x=-1,double cost=-1,int last=-1):now(now),x(x),cost(cost),last(last){}
  bool operator < (const P &a)const
  {
    return cost >= a.cost;
  }
};

double getCost(double x)
{
  if(x >= r)return 1.0/(v - e * (x - r));
            return 1.0/(v - f * (r - x));    
}

void dijkstra()
{
  double ans = inf;
  rep(i,n)rep(j,10001)mincost[i][j] = inf;
  mincost[0][0] = 0;

  priority_queue<P> Q;
  Q.push(P(0,0,0,0));

  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      if(p.now >= a[n-1])
	{
	  ans = min(ans,p.cost);
	  continue;
	}    

      if(ans <= p.cost)continue;

      assert(0 <= p.cost);
      double ncost = p.cost + getCost(p.x);
      assert(0 <= ncost);

      if(mincost[p.last][(int)p.now+1] > ncost)
	{
	  mincost[p.last][(int)p.now+1] = ncost;
	  Q.push(P(p.now+1,p.x+1,ncost,p.last));
	}

      if(A[(int)p.now+1] != -1)
	{
	  double change_cost = (A[(int)p.now+1]==n?0:b);
	  ncost += change_cost;
	  Q.push(P(p.now+1,0,ncost,A[(int)p.now+1]));
	}

    }

  cout << setiosflags(ios::fixed) << setprecision(4) << ans << endl;
}

int main()
{
  while(cin >> n,n)
    {
      rep(i,10001)A[i] = -1;
      rep(i,n)
	{
	  cin >> a[i];	 
	  A[a[i]] = i+1; 
	}
      cin >> b >> r >> v >> e >> f;
   

      dijkstra();

    }
  return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 9540
final_rank: 16

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstdio>

using namespace std;

typedef long double ld;

const int TYRE = 10001;
const int NODE = 101;
const int INF = (1<<25);

struct State{
  int x, pos;
  ld t;
  bool operator < (const State& s) const {
    return t > s.t;
  }
};

vector<int> V;

ld T[TYRE][NODE];
int n;
ld b,r,v,e,f;


void solve(){
  fill(T[0],T[0]+TYRE*NODE,(ld)INF);

  priority_queue<State> Q;
  Q.push((State){0,0,0});

  while(!Q.empty()){

    State now = Q.top(); Q.pop();
    if(now.pos == n) continue;

    if(T[now.x][now.pos] < now.t) continue;

    //change tyre
    
    State nex = now;
    nex.x = 0;
    nex.t += b;
    int diff = V[now.pos+1]-V[now.pos];
    
    for(int i = 0; i < diff; i++){
      if(nex.x >= r) nex.t += 1.0/(v-e*(nex.x-r));
      else nex.t += 1.0/(v-f*(r-nex.x));
      nex.x++;
    }
    nex.pos++;
    
    if(T[nex.x][nex.pos] > nex.t) {
      T[nex.x][nex.pos] = nex.t;
      Q.push(nex);
    }

    //not change tyre
    nex = now;

    for(int i = 0; i < diff; i++){
      if(nex.x >= r) nex.t += 1.0/(v-e*(nex.x-r));
      else nex.t += 1.0/(v-f*(r-nex.x));
      nex.x++;
    }

    nex.pos++;
    
    if(T[nex.x][nex.pos] > nex.t) {
      T[nex.x][nex.pos] = nex.t;
      Q.push(nex);
    }
  }
  ld ans = (ld)INF;
  
  for(int i = 0; i < TYRE; i++) ans = min(ans,T[i][n]);

  printf("%.4Lf\n",ans);
}


void input(){
  V.resize(n+1); V[0] = 0;
  for(int i = 1; i <= n; i++) cin >> V[i];
  cin >> b >> r >> v >> e >> f;
}

int main(){
  
  while(cin >> n && n){
    input();
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 17056
final_rank: 17

code_snippet: #include<cstdio>
using namespace std;
  
typedef double D;
  
int n,a[110],r;
D b,v,e,f;
D dp[10100][110];
const D EPS = 1e-8;
  
int main(){
  while(scanf("%d",&n),n){
    a[0] = 0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    scanf("%lf%d%lf%lf%lf",&b,&r,&v,&e,&f);
  
    for(int i=0;i<=a[n];i++)
      for(int j=0;j<=n;j++)dp[i][j] = 1e15;
    dp[0][0] = 0;
  
    int pos = 1;
    for(int i=0;i<a[n];i++){
      if(i==a[pos]){
    for(int j=0;j<pos;j++){
      if(dp[i][pos] > dp[i][j] + b + EPS){
        dp[i][pos] = dp[i][j] + b;
      }
    }
    pos++;
      }
  
      for(int j=0;j<=n;j++){
      if(dp[i][j] +EPS > 1e15)continue;
    int x = i-a[j];
    D cost = (x<r)?(1.0/(v-f*(r-x))):(1.0/(v-e*(x-r)));
    if(dp[i+1][j] > dp[i][j] + cost + EPS){
      dp[i+1][j] = dp[i][j] + cost;
    }
      }
    }
      
    D res = 1e15;
    for(int i=0;i<=n;i++){
      if(res > dp[a[n]][i] + EPS)res = dp[a[n]][i];
    }
    printf("%.10lf\n",res);
  }
}
accuracy: 1
time_ms: 70
memory_kb: 9688
final_rank: 12

code_snippet: #include<cstdio>
using namespace std;
 
typedef double D;
 
int n,a[110],r;
D b,v,e,f;
D dp[10100][110];
const D EPS = 1e-8;
 
int main(){
  while(scanf("%d",&n),n){
    a[0] = 0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    scanf("%lf%d%lf%lf%lf",&b,&r,&v,&e,&f);
 
    for(int i=0;i<=a[n];i++)
      for(int j=0;j<=n;j++)dp[i][j] = 1e15;
    dp[0][0] = 0;
 
    int pos = 1;
    for(int i=0;i<a[n];i++){
      if(i==a[pos]){
    for(int j=0;j<pos;j++){
      if(dp[i][pos] > dp[i][j] + b + EPS){
        dp[i][pos] = dp[i][j] + b;
      }
    }
    pos++;
      }
 
      for(int j=0;j<=n;j++){
    int x = i-a[j];
    D cost = (x<r)?(1.0/(v-f*(r-x))):(1.0/(v-e*(x-r)));
    if(dp[i+1][j] > dp[i][j] + cost + EPS){
      dp[i+1][j] = dp[i][j] + cost;
    }
      }
    }
     
    D res = 1e15;
    for(int i=0;i<=n;i++){
      if(res > dp[a[n]][i] + EPS)res = dp[a[n]][i];
    }
    printf("%.10lf\n",res);
  }
}
accuracy: 1
time_ms: 110
memory_kb: 9688
final_rank: 13

code_snippet: #include<cstdio>
using namespace std;

typedef double D;

int n,a[110],r;
D b,v,e,f;
D dp[10100][110];
const D EPS = 1e-8;

int main(){
  while(scanf("%d",&n),n){
    a[0] = 0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    scanf("%lf%d%lf%lf%lf",&b,&r,&v,&e,&f);

    for(int i=0;i<=a[n];i++)
      for(int j=0;j<=n;j++)dp[i][j] = 1e15;
    dp[0][0] = 0;

    int pos = 1;
    for(int i=0;i<a[n];i++){
      if(i==a[pos]){
	for(int j=0;j<pos;j++){
	  if(dp[i][pos] > dp[i][j] + b + EPS){
	    dp[i][pos] = dp[i][j] + b;
	  }
	}
	pos++;
      }

      for(int j=0;j<=n;j++){
	int x = i-a[j];
	D cost = (x<r)?(1.0/(v-f*(r-x))):(1.0/(v-e*(x-r)));
	if(dp[i+1][j] > dp[i][j] + cost + EPS){
	  dp[i+1][j] = dp[i][j] + cost;
	}
      }
    }
    
    D res = 1e15;
    for(int i=0;i<=n;i++){
      if(res > dp[a[n]][i] + EPS)res = dp[a[n]][i];
    }
    printf("%.10lf\n",res);
  }
}
accuracy: 1
time_ms: 110
memory_kb: 9688
final_rank: 13

code_snippet: //21
#include<iostream>
#include<queue>

using namespace std;

struct S{
  int a;
  double t;
  bool operator<(S a)const{
    return t>a.t;
  }
};

int main(){
  for(int n;cin>>n,n;){
    int a[101]={};
    for(int i=1;i<=n;i++){
      cin>>a[i];
    }
    int r;
    double b,v,e,f;
    cin>>b>>r>>v>>e>>f;
    S is={0,0};
    priority_queue<S> que;
    que.push(is);
    bool p[101]={};
    for(;;){
      S c=que.top();
      if(c.a==n)break;
      que.pop();
      if(p[c.a]++)continue;
      int cp=a[c.a];
      double t=c.t;
      for(int np=c.a+1;np<=n;np++){
	while(cp!=a[np]){
	  int x=cp-a[c.a];
	  t+=(x>=r)?1/(v-e*(x-r)):1/(v-f*(r-x));
	  cp++;
	}
	S n={np,t+b};
	que.push(n);
      }
    }
    cout<<fixed<<que.top().t-b<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1420
final_rank: 5

code_snippet: #include <cmath>
#include <ctime>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <map>
#define maxn 110
#define maxl 1000000000
#define mod 1000000007
using namespace std;

typedef unsigned long long ull;

int a[maxn];
double ans[maxn];

bool solve(){
	int n,i,j,r,k;
	double b,v,e,f,temp2,temp;
	scanf("%d",&n);
	if(n==0)return false;
	for(i=1;i<=n;++i){
		scanf("%d",&a[i]);
		ans[i]=1e30;
	}
	scanf("%lf%d%lf%lf%lf",&b,&r,&v,&e,&f);
	ans[0]=-b;
	for(i=0;i<n;++i){
		temp=ans[i]+b;
		for(j=i+1;j<=n;++j){
			for(k=a[j-1];k<a[j];++k){
				if(k-a[i]>=r)temp2=1/(v-e*(k-a[i]-r));
				else temp2=1/(v-f*(r-(k-a[i])));
				temp+=temp2;
			}
			ans[j]=min(temp,ans[j]);
		}
	}
	printf("%.4f\n",ans[n]);
	return true;
}

int main(){
	while(solve());
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 936
final_rank: 1

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

const double INF = 1000000000.0;
const int N = 100;

int n;
int a[N + 1];
double b;
int r;
double v, e, f;
double dp[N + 1];

double t(int x)
{
	double ans = 0.0;
	for (int i = 0; i < x; i++) {
		if (i >= r) {
			ans += 1.0 / (v - e * (i - r));
		}
		else {
			ans += 1.0 / (v - f * (r - i));
		}
	}
	return ans;
}

void solve()
{
	a[0] = 0;
	dp[0] = 0.0;
	for (int i = 1; i <= n; i++) {
		dp[i] = INF;
		for (int j = 0; j < i; j++) {
			dp[i] = min(dp[i], dp[j] + t(a[i] - a[j]));
		}
		dp[i] += b;
	}
	double ans = dp[n] - b;
	cout << setprecision(4);
	cout << setiosflags(ios::fixed);
	cout << ans << endl;
}

int main()
{
	while (cin >> n, n) {
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		cin >> b;
		cin >> r >> v >> e >> f;
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 1040
memory_kb: 1000
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

int n;
double dp[101][30001];
double b,e,v,f;
int r;
int a[1001];
double mem[30000];
const int INF=1000000000;


double dfs(int idx,int runDist){
    if(!EQ(dp[idx][runDist],INF))return dp[idx][runDist];
    if(idx==n)
        return 0;
    double res=INF;
    double cost=0;
    int ndist=a[idx+1]-a[idx];
    res=min(res,dfs(idx+1,ndist)+mem[ndist-1]+b);
    // no change
    if(runDist>=1)
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]-mem[runDist-1]);
    else
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]);
    return dp[idx][runDist]=res;
}

int main(){
    while(cin>>n&&n!=0){
        a[0]=0;
        for(int i = 0; i < n; i++)cin>>a[i+1];
        cin>>b;
        cin>>r>>v>>e>>f;
        for(int i = 0; i < 101; i++)for(int j = 0; j < 30001; j++)dp[i][j]=INF;
        memset(mem,0,sizeof(mem));
        mem[0]=1.0/(v-f*(r));
        for(int i = 1; i < 10001; i++){
            if(i>=r)
                mem[i]=mem[i-1]+1.0/(v-e*(i-r));
            else
                mem[i]=mem[i-1]+1.0/(v-f*(r-i));
        }
        for(int i = 0; i < 30000; i++)
            dp[n][i]=0;
        for(int i = n-1; i >= 0; i--){
            for(int j = 10001; j >= 0; j--){
                int ndist=a[i+1]-a[i];
                dp[i][j]=min(dp[i][j],dp[i+1][ndist]+mem[ndist-1]+b);
                if(j>=1)
                    dp[i][j]=min(dp[i][j],dp[i+1][ndist+j]+mem[ndist+j-1]-mem[j-1]);
                else
                    dp[i][j]=min(dp[i][j],dp[i+1][ndist+j]+mem[ndist+j-1]);
            }
        }
        printf("%.10f\n",dp[0][0]);
    }
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 24000
final_rank: 20