Problem:
Problem F:
Exciting Bicycle
You happened to get a special bicycle. You can run with it incredibly fast because it has a turbo engine. You can't wait to try it off road to enjoy the power.
You planned to go straight. The ground is very rough with ups and downs, and can be seen as a series of slopes (line segments) when seen from a lateral view. The bicycle runs on the ground at a constant speed of
V
. Since running very fast, the bicycle jumps off the ground every time it comes to the beginning point of a slope slanting more downward than the previous, as illustrated below. It then goes along a parabola until reaching the ground, affected by the gravity with the acceleration of 9.8m/s
2
.
It is somewhat scary to ride the bicycle without any preparations - you might crash into rocks or fall into pitfalls. So you decided to perform a computer simulation of the ride.
Given a description of the ground, calculate the trace you will run on the ground by the bicycle. For simplicity, it is sufficient to output its length.
Input
The first line of the input has two integers
N
(2 ≤
N
≤ 10000) and
V
(1 ≤
V
≤ 10000), separated by a space. It is followed by
N
lines. The
i
-th line has two integers
X
i
and
Y
i
(0 ≤
X
i
,
Y
i
≤ 10000).
V
[m/s] is the ground speed of the bicycle. The (
i
- 1) line segments (
X
i
,
Y
i
)-(
X
i
+1
,
Y
i
+1
) form the slopes on the ground, with the sky in the positive direction of the
Y
axis. Each coordinate value is measured in meters.
The start is at (
X
1
,
Y
1
), and the goal is at (
X
N
,
Y
N
). It is guaranteed that
X
i
<
X
i
+1
for 1 ≤
i
≤
N
- 1.
You may assume that the distance of
x
-coordinate between the falling point and any endpoint (except for the jumping point) is not less than 10
-5
m.
Output
Output the length you will run on the ground with the bicycle, in meters. The value may be printed with any number of digits after the decimal point, should have the absolute or relative error not greater than 10
-8
.
Sample Input 1
5 10
0 0
10 10
20 0
30 10
40 0
Output for the Sample Input 1
22.22335598
Sample Input 2
2 10
0 0
10000 0
Output for the Sample Input 2
10000.00000000
Sample Input 3
4 10000
0 0
1 1
9999 0
10000 10000
Output for the Sample Input 3
11.21323169
Sample Input 4
4 50
0 10000
1 10000
2 0
10000 0
Output for the Sample Input 4
7741.23024274

Submitted solutions:

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



const double eps = 1e-9;

void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double cosO = dx / hypot(dx, dy);
        double sinO = dy / hypot(dx, dy);
        double Vx = v * cosO, Vy = v * sinO;
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1) < p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 500;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3668
final_rank: 5

code_snippet: #include <bits/stdc++.h>

#define print(A) cerr << #A << " = " << (A) << endl;

using namespace std;

#define double long double
#define int  double

const double eps = 1e-9;

void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double cosO = dx / hypot(dx, dy);
        double sinO = dy / hypot(dx, dy);
        double Vx = v * cosO, Vy = v * sinO;
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1) < p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 500;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 3628
final_rank: 6

code_snippet: #include <bits/stdc++.h>

#define print(A) cerr << #A << " = " << (A) << endl;

using namespace std;

#define double long double
#define int  double

const double eps = 1e-9;
void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double ang = acos(dx / hypot(dx, dy));
        double Vx = v * cos(ang), Vy = v * sin(ang);
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1)  < p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 500;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 0.35714285714285715
time_ms: 500
memory_kb: 4032
final_rank: 10

code_snippet: #include <bits/stdc++.h>

#define print(A) cerr << #A << " = " << (A) << endl;

using namespace std;

#define double long double

const double eps = 1e-9;
void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double ang = acos(dx / hypot(dx, dy));
        double Vx = v * cos(ang), Vy = v * sin(ang);
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1)  < p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 500;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 0.35714285714285715
time_ms: 500
memory_kb: 3976
final_rank: 9

code_snippet: #include <bits/stdc++.h>

#define print(A) cerr << #A << " = " << (A) << endl;

using namespace std;

#define double long double

const double eps = 1e-9;
void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double ang = acos(dx / hypot(dx, dy));
        double Vx = v * cos(ang), Vy = v * sin(ang);
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1) + eps <= p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 500;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 0.35714285714285715
time_ms: 500
memory_kb: 3960
final_rank: 8

code_snippet: #include <bits/stdc++.h>

#define print(A) cerr << #A << " = " << (A) << endl;

using namespace std;

#define double long double

const double eps = 1e-9;
void solve() {
    int n, v;
    cin >> n >> v;

    vector<pair<int, int>> p(n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        if (i)
            ans += hypot(p[i].first - p[i - 1].first, p[i].second - p[i - 1].second);
    }

    auto y_at = [&](double x0, double x, double y0, double dy, double dx) -> double {
        double ang = acos(dx / hypot(dx, dy));
        double Vx = v * cos(ang), Vy = v * sin(ang);
        double t = (x - x0) / Vx;
        return y0 + Vy * t - 4.9 * t * t;
    };

    for (int i = 0; i + 2 < n; i++) {
        auto [x1, y1] = p[i];
        auto [x2, y2] = p[i + 1];
        auto [x3, y3] = p[i + 2];
        int dx1 = x2 - x1, dy1 = y2 - y1;
        int dx2 = x3 - x2, dy2 = y3 - y2;
        if (1LL * dx1 * dy2 < 1LL * dy1 * dx2) {
            double tot = 0;
            int j = i + 2;
            for (; j < n; j++) {
                if (y_at(x2, p[j].first, y2, dy1, dx1) + eps <= p[j].second) {
                    double l = p[j - 1].first, r = p[j].first;
                    pair<double, double> g;
                    int it = 100;
                    while (it--) {
                        double x_m = (l + r) / 2;
                        double s = (1.0 * p[j].second - p[j - 1].second) / (p[j].first - p[j - 1].first);
                        double y_m = s * (x_m - p[j - 1].first) + p[j - 1].second;
                        if (y_at(x2, x_m, y2, dy1, dx1) > y_m) {
                            g = {x_m, y_m};
                            l = x_m;
                        } else {
                            g = {x_m, y_m};
                            r = x_m;
                        }
                    }
                    tot += hypot(g.first - p[j - 1].first, g.second - p[j - 1].second);
                    break;
                }
                tot += hypot(p[j].first - p[j - 1].first, p[j].second - p[j - 1].second);
            }
            ans -= tot;
            i = j - 2;
        }
    }

    cout << fixed << setprecision(10) << ans;
}

int32_t main() {
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    int t = 1;

    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
accuracy: 0.35714285714285715
time_ms: 100
memory_kb: 4028
final_rank: 7

code_snippet: #include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
using namespace std;

#define EPS 1e-6

typedef long double ldouble;
typedef complex<ldouble> P;

ldouble cross(const P &a, const P &b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int n;
P z[10001];
ldouble Vabs;

const ldouble g = 9.8;

P jump(int &i){
	P dir = z[i] - z[i-1];
	P v = Vabs / abs(dir) * dir;
	const P &base = z[i];
	ldouble a = g / (real(v) * real(v) * 2.0);
	ldouble b = imag(v) / real(v);

	for(int j = i; j < n - 1; ++j){
		P z1 = z[j] - base;
		P z2 = z[j+1] - base;
		ldouble c = imag(z2 - z1) / real(z2 - z1);
		ldouble d = imag(z1) - c * real(z1);
		ldouble e = sqrt((b-c) * (b-c) - 4.0 * a * d);

		ldouble x = (b - c + e) / (2.0 * a);
		if(x > real(z1) && x < real(z2)){
			ldouble y = -a * x * x + b * x;
			i = j;
			return P(x, y) + base;
		}
	}

	i = n;
	return z[n-1];
}

int main(){
	ldouble x, y;
	cin >> n >> Vabs;
	for(int i = 0; i < n; ++i){
		cin >> x >> y;
		z[i] = P(x, y);
	}

	ldouble ans = 0.0;
	P prev = z[0];
	for(int i = 1; i < n; ++i){
		P dif = z[i] - prev;
		ans += abs(dif);
		if(i == n - 1) break;

		if(cross(dif, z[i+1] - z[i]) < -EPS){
			prev = jump(i);
		}
		else{
			prev = z[i];
		}
	}
	
	printf("%.20f\n", (double)ans);
}
accuracy: 1
time_ms: 10
memory_kb: 1576
final_rank: 1

code_snippet: #include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
using namespace std;

#define EPS 1e-6

typedef long double ldouble;
typedef complex<ldouble> P;

ldouble cross(const P &a, const P &b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int n;
P z[10001];
ldouble Vabs;

const ldouble g = 9.8;

P jump(int &i){
	P dir = z[i] - z[i-1];
	P v = Vabs / abs(dir) * dir;
	const P &base = z[i];
	ldouble a = g / (real(v) * real(v) * 2.0);
	ldouble b = imag(v) / real(v);

	for(int j = i; j < n - 1; ++j){
		P z1 = z[j] - base;
		P z2 = z[j+1] - base;
		ldouble c = imag(z2 - z1) / real(z2 - z1);
		ldouble d = imag(z1) - c * real(z1);
		ldouble e = sqrt((b-c) * (b-c) - 4.0 * a * d);

		for(ldouble sgn = -1.0; sgn < 2.0; sgn += 2.0){
			ldouble x = (b - c + sgn * e) / (2.0 * a);
			if(x > real(z1) && x < real(z2)){
				ldouble y = -a * x * x + b * x;
				i = j;
				return P(x, y) + base;
			}
		}
	}

	i = n;
	return z[n-1];
}

int main(){
	ldouble x, y;
	cin >> n >> Vabs;
	for(int i = 0; i < n; ++i){
		cin >> x >> y;
		z[i] = P(x, y);
	}

	ldouble ans = 0.0;
	P prev = z[0];
	for(int i = 1; i < n; ++i){
		P dif = z[i] - prev;
		ans += abs(dif);
		if(i == n - 1) break;

		if(cross(dif, z[i+1] - z[i]) < -EPS){
			prev = jump(i);
		}
		else{
			prev = z[i];
		}
	}
	
	printf("%.20f\n", (double)ans);
}
accuracy: 1
time_ms: 10
memory_kb: 1576
final_rank: 1

code_snippet: #include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
#include <ctime>
using namespace std;

typedef long double ldouble;
typedef complex<ldouble> P;

ldouble cross(const P &a, const P &b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int n;
P z[10001];
ldouble Vabs;

const ldouble g = 9.8;

P jump(int &i){
	P dir = z[i] - z[i-1];
	P v = Vabs / abs(dir) * dir;
	const P &base = z[i];
	ldouble a = g / (real(v) * real(v) * 2.0);
	ldouble b = imag(v) / real(v);

	for(int j = i; j < n - 1; ++j){
		P z1 = z[j] - base;
		P z2 = z[j+1] - base;
		ldouble c = imag(z2 - z1) / real(z2 - z1);
		ldouble d = imag(z1) - c * real(z1);
		ldouble e = sqrt((b-c) * (b-c) - 4.0 * a * d);

		for(ldouble sgn = -1.0; sgn < 2.0; sgn += 2.0){
			ldouble x = (b - c + sgn * e) / (2.0 * a);
			if(x > 0.0 && x < real(z2) + 1e-6){
				ldouble y = -a * x * x + b * x;
				i = j;
				return P(x, y) + base;
			}
		}
	}

	i = n;
	return z[n-1];
}

int main(){
	ldouble x, y;
	cin >> n >> Vabs;
	for(int i = 0; i < n; ++i){
		cin >> x >> y;
		z[i] = P(x, y);
	}

	ldouble ans = 0.0;
	P prev = z[0];
	for(int i = 1; i < n; ++i){
		P dif = z[i] - prev;
		ans += abs(dif);
		if(i == n - 1) break;

		if(cross(dif, z[i+1] - z[i]) < 0.0){
			prev = jump(i);
		}
		else{
			prev = z[i];
		}
	}
	
	if(abs(ans - 1.0) < 1e-8){
		clock_t c = clock() + CLOCKS_PER_SEC;
		while(c > clock());
	}
	
	printf("%.20f\n", (double)ans);
}
accuracy: 0.23809523809523808
time_ms: 1000
memory_kb: 1576
final_rank: 14

code_snippet: #include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
using namespace std;

typedef long double ldouble;
typedef complex<ldouble> P;

ldouble cross(const P &a, const P &b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int n;
P z[10001];
ldouble Vabs;

const ldouble g = 9.8;

P jump(int &i){
	P dir = z[i] - z[i-1];
	P v = Vabs / abs(dir) * dir;
	const P &base = z[i];
	ldouble a = g / (real(v) * real(v) * 2.0);
	ldouble b = imag(v) / real(v);

	for(int j = i; j < n - 1; ++j){
		P z1 = z[j] - base;
		P z2 = z[j+1] - base;
		ldouble c = imag(z2 - z1) / real(z2 - z1);
		ldouble d = imag(z1) - c * real(z1);
		ldouble e = sqrt((b-c) * (b-c) - 4.0 * a * d);

		for(ldouble sgn = -1.0; sgn < 2.0; sgn += 2.0){
			ldouble x = (b - c + sgn * e) / (2.0 * a);
			if(x > 0.0 && x < real(z2) + 1e-6){
				ldouble y = -a * x * x + b * x;
				i = j;
				return P(x, y) + base;
			}
		}
	}

	i = n;
	return z[n-1];
}

int main(){
	ldouble x, y;
	cin >> n >> Vabs;
	for(int i = 0; i < n; ++i){
		cin >> x >> y;
		z[i] = P(x, y);
	}

	ldouble ans = 0.0;
	P prev = z[0];
	for(int i = 1; i < n; ++i){
		P dif = z[i] - prev;
		ans += abs(dif);
		if(i == n - 1) break;

		if(cross(dif, z[i+1] - z[i]) < 0.0){
			prev = jump(i);
		}
		else{
			prev = z[i];
		}
	}
	
	printf("%.20f\n", (double)ans);
}
accuracy: 0.23809523809523808
time_ms: 10
memory_kb: 1576
final_rank: 11

code_snippet: #include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
#include <iostream>
using namespace std;

typedef long double ldouble;
typedef complex<ldouble> P;

ldouble cross(const P &a, const P &b){
	return real(a) * imag(b) - imag(a) * real(b);
}

int n;
P z[10001];
ldouble Vabs;

const ldouble g = 9.8;

P jump(int &i){
	P dir = z[i] - z[i-1];
	P v = Vabs / abs(dir) * dir;
	const P &base = z[i];
	ldouble a = g / (real(v) * real(v) * 2.0);
	ldouble b = imag(v) / real(v);

	for(int j = i; j < n - 1; ++j){
		P z1 = z[j] - base;
		P z2 = z[j+1] - base;
		ldouble c = imag(z2 - z1) / real(z2 - z1);
		ldouble d = imag(z1) - c * real(z1);
		ldouble e = sqrt((b-c) * (b-c) - 4.0 * a * d);

		for(ldouble sgn = -1.0; sgn < 2.0; sgn += 2.0){
			ldouble x = (b - c + sgn * e) / (2.0 * a);
			if(x > 0.0 && x < real(z2) + 1e-6){
				ldouble y = -a * x * x + b * x;
				i = j;
				return P(x, y) + base;
			}
		}
	}

	i = n;
	return z[n-1];
}

int main(){
	ldouble x, y;
	cin >> n >> Vabs;
	for(int i = 0; i < n; ++i){
		cin >> x >> y;
		z[i] = P(x, y);
	}

	ldouble ans = 0.0;
	P prev = z[0];
	for(int i = 1; i < n; ++i){
		P dif = z[i] - prev;
		ans += abs(dif);
		if(i == n - 1) break;

		if(cross(dif, z[i+1] - z[i]) < 0.0){
			prev = jump(i);
		}
		else{
			prev = z[i];
		}
	}
	
	printf("%.10f\n", (double)ans);
}
accuracy: 0.23809523809523808
time_ms: 10
memory_kb: 1576
final_rank: 11

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <complex>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

typedef long double D;
typedef complex<long double> P;
typedef pair<P, P> L;

#define X real()
#define Y imag()

P vect(L l) {return l.second - l.first;}

const D gravity = 9.8;
D get_y(P velocity, P initial, D x){
  assert(x - initial.X >= 0);
  D t = (x - initial.X) / velocity.X;
  return initial.Y + velocity.Y * t - 0.5 * gravity * t * t;
}
D fun(P v, D t){
  return sqrt(v.X * v.X + (v.Y - gravity * t) * (v.Y - gravity * t));
}
D get_length(P initial, P cross, P velocity){
  D t = (cross.X - initial.X) / velocity.X;
  return t / 6.0 * (fun(velocity, 0) + 4 * fun(velocity, t / 2) + fun(velocity, t));
}

int main(){
  int N;
  D V;
  while(cin>>N>>V){
    vector<P> endpoints(N);
    REP(i, N){
      scanf("%Lf %Lf", &endpoints[i].X, &endpoints[i].Y);
    }
    vector<L> lines(N - 1);
    REP(i, N - 1){
      lines[i] = L(endpoints[i], endpoints[i + 1]);
    }
    bool inair = false;
    P jump_point;
    P velocity;
    D ans = 0;
    REP(i, lines.size()){
#ifdef DEBUG
      printf("line %d: ", i);
      cout<<lines[i].first<<" "<<lines[i].second<<endl;
#endif
      if(inair){
        if(get_y(velocity, jump_point, lines[i].second.X) > lines[i].second.Y){
        }else{
          D lb = 0.0, ub = 1.0;
          P u = lines[i].first;
          P v = vect(lines[i]);
          // u + x * v (0 < x < 1)
          REP(iter, 100){
            D mid = (lb + ub) / 2;
            P mid_p = u + mid * v;
            if(get_y(velocity, jump_point, mid_p.X) < mid_p.Y){
              ub = mid;
            }else{
              lb = mid;
            }
          }
          P cross = u + lb * v;
          //ans += get_length(jump_point, cross, velocity);
#ifdef DEBUG
          printf("get on ");
          cout<<cross;
          printf("(k = %LF) and run on ground %Lf m\n", lb, abs((1 - lb) * v));
#endif
          ans += abs((1 - lb) * v);
          inair = false;
        }
      }else{
#ifdef DEBUG
        printf("run on ground %Lf m\n", abs(vect(lines[i])));
#endif
        ans += abs(vect(lines[i]));
      }
      if(!inair && i + 1 < lines.size() && arg(vect(lines[i])) > arg(vect(lines[i + 1]))){
        inair = true;
        jump_point = lines[i].second;
        velocity = polar(V, arg(vect(lines[i])));
#ifdef DEBUG
        printf("jump from "); cout<<jump_point<<" (v = "<<velocity<<")"<<endl;
#endif
      }
    }
    printf("%.8Lf\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2060
final_rank: 4

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <complex>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

typedef long double D;
typedef complex<long double> P;
typedef pair<P, P> L;

#define X real()
#define Y imag()

P vect(L l) {return l.second - l.first;}

const D gravity = 9.8;
D get_y(P velocity, P initial, D x){
  assert(x - initial.X >= 0);
  D t = (x - initial.X) / velocity.X;
  return initial.Y + velocity.Y * t - 0.5 * gravity * t * t;
}
D fun(P v, D t){
  return sqrt(v.X * v.X + (v.Y - gravity * t) * (v.Y - gravity * t));
}
D get_length(P initial, P cross, P velocity){
  D t = (cross.X - initial.X) / velocity.X;
  return t / 6.0 * (fun(velocity, 0) + 4 * fun(velocity, t / 2) + fun(velocity, t));
}

int main(){
  int N;
  D V;
  while(cin>>N>>V){
    vector<P> endpoints(N);
    REP(i, N){
      scanf("%Lf %Lf", &endpoints[i].X, &endpoints[i].Y);
    }
    vector<L> lines(N - 1);
    REP(i, N - 1){
      lines[i] = L(endpoints[i], endpoints[i + 1]);
    }
    bool inair = false;
    P jump_point;
    P velocity;
    D ans = 0;
    REP(i, lines.size()){
      //printf("line %d: ", i);
      //cout<<lines[i].first<<" "<<lines[i].second<<endl;
      if(inair){
        if(get_y(velocity, jump_point, lines[i].second.X) > lines[i].second.Y){
        }else{
          D lb = 0.0, ub = 1.0;
          P u = lines[i].first;
          P v = vect(lines[i]);
          // u + x * v (0 < x < 1)
          REP(iter, 100){
            D mid = (lb + ub) / 2;
            P mid_p = u + mid * v;
            if(get_y(velocity, jump_point, mid_p.X) < mid_p.Y){
              ub = mid;
            }else{
              lb = mid;
            }
          }
          P cross = u + lb * v;
          //ans += get_length(jump_point, cross, velocity);
          /*
          printf("get on ");
          cout<<cross;
          printf("(k = %LF) and run on ground %Lf m\n", lb, abs((1 - lb) * v));
          */
          ans += abs((1 - lb) * v);
          inair = false;
        }
      }else{
        //printf("run on ground %Lf m\n", abs(vect(lines[i])));
        ans += abs(vect(lines[i]));
      }
      if(i + 1 < lines.size() && arg(vect(lines[i])) > arg(vect(lines[i + 1]))){
        inair = true;
        jump_point = lines[i].second;
        velocity = polar(V, arg(vect(lines[i])));
      }
    }
    printf("%.8Lf\n", ans);
  }
  return 0;
}
accuracy: 0.23809523809523808
time_ms: 10
memory_kb: 2060
final_rank: 13

code_snippet: #include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> Pol;

const D INF = 1e40;
const D EPS = 1e-8;
const D PI = acos(-1);

int sig(D r) {return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0;}
bool eq(D a, D b) {return abs(a - b) < EPS;}
bool near(P a, P b) {return abs(a - b) < EPS;}

// テ・ツ??ァツゥツ?
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// テ・ツ、ツ姪ァツゥツ?
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// テァツキツ堙・ツ按?」ツ?ョテ」ツδ凖」ツつッテ」ツδ暗」ツδォ
P vec(L a) {return a.second - a.first;}

// テァツキツ堙・ツ按?bテ」ツ?ォテ・ツッツセテ」ツ?凖」ツつ凝ァツつケxテ」ツ?ョテ、ツスツ催ァツスツョ
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(L s, P p) {
  P a = vec(s);
  p -= s.first;
  D cr = det(a, p);
  if (eq(cr, 0)) {
    if (sig(dot(a, p)) < 0) return BACK;
    if (sig(norm(a) - norm(p)) < 0) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}

struct Par{
  P p, v, a;
  Par() {}
  Par(P p, P v, P a) : p(p), v(v), a(a) {}
};

bool iParL(Par par, L l) {
  par.p = (par.p - l.first) / vec(l);
  par.v /= vec(l);
  par.a /= vec(l);
  if (eq(par.a.Y, 0)) return !eq(par.v.Y, 0);
  D t = par.v.Y / par.a.Y;
  return sig((par.p + par.v * t + par.a * t * t / (D)2).Y) * sig(par.a.Y) <= 0;
}

pair<D, D> tParL(Par par, L l) {
  par.p = (par.p - l.first) / vec(l);
  par.v /= vec(l);
  par.a /= vec(l);
  D t1 = (-par.v.Y + sqrt(pow(par.v.Y, 2) - 2 * par.p.Y * par.a.Y)) / par.a.Y;
  D t2 = (-par.v.Y - sqrt(pow(par.v.Y, 2) - 2 * par.p.Y * par.a.Y)) / par.a.Y;
  return make_pair(t1, t2);
}

pair<P, P> pParL(Par par, L l) {
  pair<D, D> t = tParL(par, l);
  P p1 = par.p + par.v * t.first + par.a * t.first * t.first / (D)2;
  P p2 = par.p + par.v * t.second + par.a * t.second * t.second / (D)2;
  return make_pair(p1, p2);
}

int main() {
  int n;
  D v;
  cin >> n >> v;
  Pol pol;
  rep (i, n) {
    P p;
    cin >> p.X >> p.Y;
    pol.push_back(p);
  }
  P now = pol[0];
  D res = 0;
  rep (i, n - 1) {
    res += abs(now - pol[i + 1]);
    if (i < n - 2 && ccw(L(pol[i], pol[i + 1]), pol[i + 2]) == RIGHT) {
      Par par;
      par.p = pol[i + 1];
      par.v = polar(v, arg(pol[i + 1] - pol[i]));
      par.a = P(0, -9.8);
      for (; i < n - 2; ++i) {
	pair<P, P> pp = pParL(par, L(pol[i + 1], pol[i + 2]));
	if (pp.first.X > pp.second.X) swap(pp.first, pp.second);
	if (sig(pol[i + 1].X - pp.first.X) < 0 && sig(pp.first.X - pol[i + 2].X) < 0) {
	  now = pp.first;
	  break;
	}
	if (sig(pol[i + 1].X - pp.second.X) < 0 && sig(pp.second.X - pol[i + 2].X) < 0) {
	  now = pp.second;
	  break;
	}
      }
    } else {
      now = pol[i + 1];
    }
  }
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1696
final_rank: 3