VPEX P3 - Coding Club

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 0.5s
Memory limit: 64M

Problem types

diagram

At coding club, Darcy is watching the bouncing screensaver meme. The screensaver consists of a rectangular DVD logo of width A and height B bouncing around a rectangular screen of width W and height H at a speed of 1 unit/second. When the logo touches a side of the screen, it bounces off such that the angle of incidence equals the angle of reflection. When the logo reaches a corner, its direction is simply reversed.

The logo begins at position (x_0,y_0) (measured from the bottom left corner of the screen and logo) and travels in the direction (x,y). After a while, Darcy noticed that the logo returned to its starting position and velocity. What is the minimum time Darcy had to wait?

Input Specification

The first line contains integers W and H, the width and height of the screen.
The second line contains integers A and B, the width and height of the logo.
The third line contains integers x_0 and y_0, representing the starting position of the logo (measured from the bottom left corner of the screen to the bottom left corner of the logo).
The last line contains integers x and y, meaning the logo has the same initial direction as a vector pointing x units right and y units up.

Output Specification

Let T be the minimum amount of seconds after beginning such that the logo is at position (x_0,y_0) travelling in direction (x,y). Print the 6 digits beginning from the first non-zero digit of T.

If this will never happen, print -1.

Constraints

1 \le A < W \le 1000
1 \le B < H \le 1000
1 \le A+x_0 \le W
1 \le B+y_0 \le H
-10^5 \le x,y \le 10^5
x \ne 0 or y \ne 0

Subtask 1 [20%]

1 \le W,H,x,y \le 15

Sample Input

11 11
1 1
5 5
1 1

Sample Output

282842

Explanation

T = 28.2842712


Comments

There are no comments at the moment.