Girls Invitational '19 S2 - Road Trip

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 128M

Author:
Problem type

April is taking a road trip with her friends! April's world can be represented by a coordinate plane, where she starts at (0,0). There are N attractions with coordinate positions she would like to visit. She must visit these coordinates in order, and can travel in a straight line between attractions.

Given a list of attractions to visit in order, can you calculate the total distance traveled?

Input Specification

The first line of input will contain one integer, N (2 \le N \le 10^5), the number of attractions to visit.

The next N lines will each contain two integers X and Y (-10^5 \le X,Y \le 10^5), the coordinates of the attraction.

Output Specification

Output the total distance traveled.

Do not round your output. Outputs with a precision error of 10^{-4} will be accepted.

Subtasks

Subtask 1 [15%]

X = 0, -100 \le Y \le 100

Subtask 2 [25%]

-100 \le X, Y \le 100

Subtask 3 [60%]

No further constraints.

Sample Input 1

3
0 1
2 2
3 3

Sample Output 1

4.6502815399

Sample Explanation

Diagram

This is a diagram of April's trip. Notice how she travels in a straight line between the attractions in the order that they are given.

Remember that the distance between two points on a Cartesian plane is calculated using the Pythagorean Theorem.

Sample Input 2

5
-2 3
4 -5
5 1
0 1
6 -2

Sample Output 2

31.39651773

Comments

There are no comments at the moment.