LCC '25 Contest 1 S5 - Moonlight's Box Challenge

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 0.6s
Java 8 1.5s
Python 2.0s
Memory limit: 512M

Author:
Problem types

Moonlight is a devious person, and hates seeing people happy. The one thing he hates more than people being happy is AndyMan68 specifically being happy. After plotting for a year, Moonlight has created a machine that allows him to teleport anything into a box he's created. The box isn't your typical box, either. It comprises of N dimensions, specifically to trap devious little creatures from escaping from his grasp. To add insult to injury, Moonlight has chosen the perfect time to strike, Halloween, so AndyMan68 will miss out on candy. On the day of Halloween, instead of letting him go trick-or-treating, Moonlight has decided to put AndyMan68 into an N-dimensional box. The box has one vertex at (0, 0, ... , 0), and the i^{\text{th}} dimension of the box has side length L_i. However, AndyMan68 isn't pleased with being stuck in this box, and still wants to go trick-or-treating. There are houses located at each vertex of the box, more formally where the ith coordinate is either 0 or L_i, and AndyMan68 wants to eventually end up at one of these vertices, so he can fulfill his lifelong dreams of collecting candy.

Unfortunately, AndyMan68 isn't the sharpest tool in the shed. Once he starts moving in a direction, he's unwilling to change directions unless he reaches a face of the box. When he reaches the face of the box, AndyMan68 will change directions such that his new direction is his old direction reflected along the normal to this plane. Below is an example of AndyMan68 bouncing in a 2-dimensional space.

reflection diagram

AndyMan68 is given a direction vector (v_1, v_2, ..., v_N) to start with, and an initial position (p_1, p_2, ..., p_N). Please help him determine whether or not it is possible for him to reach a corner of the box.

Input Specification

The first line of input will contain one integer N, the number of dimensions of the box.

The next line of input will contain N space-separated integers, representing L_i, the dimensions of the box.

The following line of input will contain another N space-separated integers, representing p_i, the starting position of AndyMan68

The final line of input will contain N space-separated integers, representing v_i, the initial direction vector that AndyMan68 moves in.

Output Specification

On one line, output YES if he can reach a house, and NO if AndyMan68 cannot.

Constraints

2 \leq N \leq 1000

1 \leq L_i \leq 10^4

0 \leq p_i \leq L_i

0 \leq v_i \leq 10^4

Subtask 1 [20%]

N = 2

Subtask 2 [30%]

N = 3

Subtask 2 [50%]

No additional constraints

Sample Input 1

2
4 4
1 3
3 1

Output for Sample Input 1

YES

Explanation of Output for Sample Input 1

After one unit of time, he will have travelled to the point (4, 4), which is a corner.

Sample Input 2

2
4 4
1 3
3 0

Output for Sample Input 2

NO

Explanation of Output for Sample Input 2

Note that no matter how AndyMan68 moves, he will always have a y-coordinate of 3, and no corners have a y-coordinate of 3. This means he will never reach a corner.


Comments

There are no comments at the moment.