[Solution] Pizza Delivery Solution Round E 2022 | Kick Start 2022
Problem
Ada delivers pizzas in a city consisting of a grid of horizontal and vertical streets, heading from North to South and from West to East, respectively, and numbered from to . The top left street crossing of the grid is .
Today, Ada has to deliver pizzas, one for each of customers. Each customer lives at a different street crossing; the -th customer lives at street crossing and will pay Ada coins after the pizza is delivered to their location.
Ada starts at her pizza restaurant at with coins and carrying pizzas. Her goal is to deliver all of the pizzas within minutes. She is free to take any path she likes around the city and finish deliveries anywhere, as long as she manages to drop off all pizzas to their respective customers within minutes. It takes one minute to walk between two adjacent street crossings, and takes no additional time to drop off a pizza at a customer's location. There are some additional rules and constraints to note:
- Ada is not allowed to go outside the grid.
- No customer lives at the same street crossing as the pizza restaurant Ada starts her trip.
- At any point in time Ada can choose to stay in her current location and not move.
- Ada can also choose not to deliver a pizza when at a customer's location.
Formally, if Ada is currently at street crossing , where is -th row from the top, and is -th column from the left, she can decide to do any of the following as long as she does not go outside the grid:
- Go north, she reaches street crossing .
- Go east, she reaches street crossing .
- Go west, she reaches street crossing .
- Go south, she reaches street crossing .
- Stay at street crossing .
The city has a unique toll system in place for using the streets. There is a toll for using each street and the toll depends on Ada's current number of coins and the direction in which she is travelling to. The toll function is defined for every cardinal direction (North, East, West, South) separately. The toll function for returns the amount of coins Ada will have after moving in the direction and is defined as follows:
=
where is the current number of coins that Ada has and is an operator and is a fixed positive integer. The allowed operators are:
+
(addition),-
(subtraction),*
(multiplication),/
(integer division).
For example, we can have = +
, = *
, = -
, = /
. That means that if Ada moves North one street then she will have more coins; if Ada moves East then Ada's coins will quadruple; if Ada moves West then she loses coins; and if Ada moves South then her coins are halved.
All divisions are integer divisions and are computed by using floor function. For example, . Notice that Ada is allowed to have a negative number of coins. Note that the tolls might actually give Ada coins.
Find out if Ada can deliver all the pizzas in minutes and, if so, the maximum number of coins Ada could have after minutes.
Input
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains , , , , denoting the grid size, the number of pizzas to deliver, the minutes in which all pizzas should be delivered, and the coordinates of the street crossing at which Ada starts respectively.
The next four lines denote the toll functions for North, East, West, South respectively. Each of these lines contains , denoting the operator (one of +
, -
, *
, /
), and , the positive integer used in toll function.
The following lines describe the customers. Each of these lines consists of three integers , , denoting the row number of the -th customer from the top of the grid, the column number of the -th customer from the left of the grid, and the amount of coins they pay on delivery, respectively.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is IMPOSSIBLE
if all pizzas cannot be delivered within minutes; otherwise, the output should be the maximum number of coins Ada can have after minutes (which could be negative).
Limits
Time limit: 20 seconds.
Memory limit: 1 GB.
.
.
.
.
, for all .
, for all .
, for all .
is one of (+
, -
, *
, /
), for all .
It is guaranteed that no customer lives at the same street crossing as the pizza restaurant Ada starts her trip, i.e. , for all .
It is guaranteed that every customer lives at a different street crossing, i.e. , for all and .
Test Set 1
.
Test Set 2
.
Sample
Note: there are additional samples that are not run on submissions down below.
In Additional Sample Case #1, Ada started at street crossing with coins. Ada can receive maximum coins by following the steps below:
- Go west to . Using the toll function for moving west
= *
, Ada now has coins. - Do not deliver the pizza at yet, and go south to . Using the toll function for moving south
= /
, Ada now has coins. - Go north to . Using the toll function for moving north
= +
, Ada now has coins. - Deliver the pizza at . Ada receives additional coins for delivering the pizza. Ada has a total of coins in the end.
In Additional Sample Case #2, Ada cannot deliver two pizzas in one minute, so the output is IMPOSSIBLE
.
In Additional Sample Case #3, Ada started at street crossing with coins. Ada can receive maximum coins by following the steps below:
- Go west to . Using the toll function for moving west
= -
, Ada now has coins. - Go south to . Using the toll function for moving south
= /
, Ada now has coins. - Deliver the pizza at . Ada receives additional coins for delivering the pizza. Ada has a total of coins in the end.
No comments:
Post a Comment