## CCC '17 J3 - Exactly Electrical

View as PDF

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type
##### Canadian Computing Competition: 2017 Stage 1, Junior #3

You live in Grid City, which is composed of integer-numbered streets which run east-west (parallel to the -axis) and integer-numbered avenues which run north-south (parallel to the -axis). The streets and avenues have infinite length, and there is a street for every integer -coordinate and an avenue for every -coordinate. All intersections are labelled by their integer coordinates: for example, avenue and street intersect at .

You drive a special electric car which uses up one unit of electrical charge moving between adjacent intersections: that is, moving either north or south to the next street, or moving east or west to the next avenue). Until your battery runs out, at each intersection, your car can turn left, turn right, go straight through, or make a U-turn. You may visit the same intersection multiple times on the same trip.

Suppose you know your starting intersection, your destination intersection and the number of units of electrical charge in your battery. Determine whether you can travel from the starting intersection to the destination intersection using the charge available to you in such a way that your battery is empty when you reach your destination.

#### Input Specification

The input consists of three lines. The first line contains followed by , indicating the starting coordinate .

The second line contains followed by , indicating the destination coordinate .

The third line contains an integer indicating the initial number of units of electrical charge of your battery.

For 3 of the 15 available marks, .

For an additional 3 of the 15 marks available, .

#### Output Specification

Output Y if it is possible to move from the starting coordinate to the destination coordinate using exactly units of electrical charge. Otherwise output N.

#### Sample Input 1

3 4
3 3
3

#### Sample Output 1

Y

#### Explanation for Sample Output 1

One possibility is to travel from to to to .

#### Sample Input 2

10 2
10 4
5

#### Sample Output 2

N

#### Explanation for Sample Output 2

It is possible to get from to using exactly units of electricity, by going north units.

It is also possible to travel using units of electricity as in the following sequence:

It is also possible to travel using units of electricity from to by the following sequence:

It is not possible to move via any path of length from to , however.

• commented on Nov. 27, 2023, 4:22 a.m.

This question sure wants to stop climate change!

• commented on April 16, 2021, 2:18 a.m.
• commented on Feb. 1, 2022, 6:51 p.m.

What? Why Edmonton?

• commented on April 16, 2021, 9:08 p.m.

why do i have a fan account???

• commented on April 16, 2021, 9:11 p.m.

famous :O

• commented on Nov. 13, 2020, 4:56 p.m.

Yes, finally, future is here.

• commented on Feb. 16, 2021, 2:50 a.m.

Not the future lol. If the future is like this (i.e. they have to use the entire battery to arrive at their destination) then I would be very concerned.

• commented on Feb. 16, 2021, 7:06 p.m.

You must be fun at parties