After a long day at the arena fighting (and defeating!) Bowser, Isabelle comes home to get some rest. She looks around her house and notices her plain wooden floors and decides that they need some pizzazz. Isabelle decided she wanted to swap the wooden floors for fun colored tiles. After much internal debate, she decided on L-shaped tiles (3 across, 1 down) because they reminded her of both the Tetris piece and the move a knight makes in chess. Given the dimensions of Isabelle's rectangular room, determine whether or not these tiles will fully cover her floor.
There will be one line of input that contains 2 space-separated integers $$$N$$$ and $$$M$$$ which represent the length and width of Isabelle's room.
$$$ 1 \leq N, M \leq 1000 $$$
Output YES if L-shaped tiles will completely fill Isabelle's room and NO if they do not.
6 4
YES
9 6
NO
Sally has had some downtime recently and so to keep from boredom, she's been playing a lot of Super Smash Bros Ultimate. She has made it her goal to be the best player in the world and while watching some of the current best players, she found a special type of move combo called a kill-confirm which guarantees that you will be able to take one of your opponent's stock. In order for a combo to be a kill-confirm, she realized that the combo must be $$$n$$$ moves long and every 'sub-combo' of $$$p$$$ moves must be a palindrome. A 'sub-combo' of size $$$p$$$ is $$$p$$$ consecutive moves in the original combo and for a 'sub-combo' to be a palindrome, the list of moves must be the same when read forward and backward. For example, if the list of $$$p$$$ moves is 'Up, Down, Down, Up' this is a palindrome.
Armed with this information, Sally wants to figure out the number of distinct kill-confirm combos for a specific character in the game that has $$$m$$$ distinct moves. This number can be quite large so return the quantity modulo $$$10^9 + 7$$$.
There will be one line of input which contains $$$3$$$ space-separated integers: $$$n$$$, $$$p$$$, and $$$m$$$ ($$$1 \leq n,p,m \leq 2500$$$ and $$$p \leq n$$$).
Output a single integer, the number of possible combos that fit the desired scheme modulo $$$10^9 + 7$$$.
1 1 1
1
5 4 2
2
In the first example, there is only one move and the length of the combo is one so the only combo possible is that move itself. In the second example, there are two moves (call them $$$w$$$ and $$$s$$$ for example), and the only way for a combo to be of length $$$5$$$ with all 'sub-combos' of length $$$4$$$ being palindromes is if the combo is $$$wwwww$$$ or $$$sssss$$$.
Sidra enjoys playing her friends in the new hottest racing game, Kario Mart, where little characters race around in shopping carts inside of a grocery store. Whoever makes it around the track and back to the cash register first wins! Sidra has gotten pretty good at Kario Mart but would really like to take her strategy to the next level by optimizing the speed and maneuverability of her shopping cart selection prior to the race.
Before beginning a race in Kario Mart, players select a grocery store map that they will all race in. All grocery stores are rectangular, so the players will select some map with dimensions $$$w\times h$$$. Once this choice is made, Sidra knows that the game logic then randomly generates a rectangular racetrack for the players to race on, which will fit within the $$$w\times h$$$ grocery store map and rest on its unit grid-lines, including possibly the outer-most grid-lines.
Once the selected grocery store map and randomly generated racetrack are fixed, then players choose their shopping carts. Sidra knows the importance of a well-tuned shopping cart to winning the race, so she would like to know how much of the race will consist of making sharp turns versus speeding down straightaways. Help Sidra make the best choice she can without knowing the exact location and dimensions of the generated racetrack.
Given the dimensions $$$w$$$ and $$$h$$$ of the selected grocery store map and the fact that all unique rectangles in the grocery store are equally likely to be generated as a racetrack for the game, determine the expected value of the perimeter of the racetrack! Note that a rectangular racetrack is uniquely defined by two ordered pairs $$$(x_1,y_1)$$$ and $$$(x_2, y_2)$$$ where $$$x_1 \lt x_2$$$ and $$$y_1 \lt y_2$$$ and $$$0\leq x_1,x_2 \leq w$$$ and $$$0\leq y_1,y_2\leq h$$$.
The input consists of two space-separated integers, $$$w$$$ and $$$h$$$, representing the width and height of the selected grocery store map where $$$1\leq w,h \leq 1000$$$.
Output the expected value of the perimeter of a rectangular race track, randomly generated within the grocery store. Round your answer to the nearest integer.
2 2
5
Mateo has built a beautiful farm in Stardew Valley and now he wants to spend the rest of his days as a farmer buying salads from the villagers. Fortunately for him, Gus has introduced a bunch of new salads. There are $$$10^8$$$ different types of salads and they are creatively named 'Salad x' where $$$x$$$ is the type of the salad. Now, Gus is a little eccentric, his lucky numbers are any number which consists solely of the digits $$$3$$$ or $$$8$$$ (so $$$3$$$, $$$38$$$, $$$83$$$, and $$$88$$$ are lucky but $$$138$$$ is not). So, Gus has decided that the price of 'Salad x' is the first lucky number greater than or equal to $$$x$$$. Now, Mateo has been able to collect a lot of the salad types from other villagers but unfortunately, there is an interval of salad types that he has not been able to collect. Given the interval of salad types that Mateo is trying to buy, help calculate how much gold it will cost him to buy one of each of those types from Gus.
The first line of input will contain two integers, $$$l$$$ and $$$r$$$ (the interval of types which Mateo does not have - inclusive of the ends) where $$$1 \leq l \leq r \leq 10^8$$$.
Print a single integer (note this number may be large, so be sure to use appropriate types during your calculations) representing the amount of gold it will cost Mateo to buy one of each type of salad in the interval from Gus.
3 9
76
7 7
8
2 34
909
In the first sample, the interval is [3,9] and the cost of 'Salad 3' is $$$3$$$, 'Salad 4' is $$$8$$$, 'Salad 5' is $$$8$$$, 'Salad 6' is $$$8$$$, 'Salad 7' is $$$8$$$, 'Salad 8' is $$$8$$$, 'Salad 9' is $$$33$$$ so the total cost is $$$3 + 8 + 8 + 8 + 8 + 8 + 33 = 76$$$.
Toast is currently a crewmate on the Skeld, and unfortunately, unbeknownst to him, there has been a new task added! He's struggling a lot with this new task, so much so that Toast is a bit suspicious that the imposters might have already claimed a few crewmates. Just as he wants to give up on the task to check out his fellow crewmates, he sees Abe walk up behind him. Obviously, he does not want to fake a task. Help Toast finish his task so he can win the game!
The new task has a grid of $$$n \times m$$$ consisting of lower case English letters. Toast is allowed to remove any column of letters. The goal here is to remove the smallest number of columns required such that after all the removals, the rows are ordered from top to bottom lexicographically. Specifically, any row cannot be lexicographically smaller than a previous one, but it can be equal. Determine the minimum number of columns required to be removed to make this the case. Note that it may be the case that every column needs to be removed.
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 10^2)$$$.
The next $$$n$$$ lines each contain $$$m$$$ lowercase English letters, which are the characters in the grid.
A single integer detailing the minimum number of columns that need to be removed.
2 3 med bay
2
To help Luigi get rid of the spooky scary ghosts in the mansion, E. Gadd has created a new gadget, the Ghost Zapper '85. This gadget is able to automatically zap any ghost any distance away from it. The only catch is that zapping a ghost $$$x$$$ meters of distance away from the zapper consumes $$$x^{2}$$$ Watt-hours of energy. In addition, a zapper can zap as many ghost as necessary, but the energy requirements add up; zapping two ghosts, one distance $$$x$$$ away from the zapper and the other distance $$$z$$$ away, will consume $$$x^{2} + z^{2}$$$ Watt-hours of energy in total.
To test this out, E. Gadd will mount a Zapper unit on top of every light fixture in a very long hallway. Using another gadget, he has also determined the location of every ghost along the hallway. Calculate the amount of energy needed to zap every ghost in the hallway, mod $$$10^9 + 7$$$.
Two integers, $$$1 \leq n \le 10^5$$$, and $$$1 \leq m \le 10^5$$$, separated by spaces on the first line.
$$$n$$$ denotes the number of zappers mounted, and $$$m$$$ denotes the number of ghosts in the hallway.
$$$n$$$ lines each containing an integer $$$0 \leq z_{i} \le 10^7$$$ where $$$z_{i}$$$ represents the location of the $$$i$$$th zapper, and location is defined as meters away from the start of the hallway.
$$$m$$$ lines each containing an integer $$$0 \leq x_{j} \le 10^7$$$ where $$$x_{j}$$$ represents the location of the $$$j$$$th ghost.
The total energy required to zap every ghost in the hallway, mod $$$10^9 + 7$$$.
4 4 4 1 11 7 2 9 6 15
22
2 4 10 5 7 0 5 100
8129
In example 1, there are four zappers, at locations 4, 1, 11, and 7. The first ghost at location 2 can be zapped by the zapper at location 1, costing 1 Wh. The second ghost at location 9 can be zapped by the zapper at location 7 or the one at location 11, either costing 4 Wh. The third ghost at 6 can be zapped by the zapper at 7, costing 1 Wh. The fourth ghost at 15 can be zapped by the zapper at 11, costing 16 Wh. This yields a total of 22 Wh for all ghosts.
In example 2, The first ghost can be zapped by zapper 2 yielding a cost of $$$(7 - 5)^2 = 4$$$. The second ghost can be zapped by zapper 2 yielding a cost of $$$(5 - 0)^2 = 25$$$. The third ghost can be zapped by zapper 2 with a cost of $$$(5 - 5)^2 = 0$$$. The fourth ghost can be zapped by zapper 1, yielding a cost of $$$(100 - 10)^2 = 8100$$$. The total adds up to $$$8129$$$ Wh of energy.
Michael and Trevor have just pulled off the biggest heist Los Santos has ever seen! However, they must now escape the cops. In order to evade quickly, they decide to split up and drive dirt bikes across the map. The map is a hilly terrain laid out as a grid. Michael is traveling from the top row of the map to the bottom row, while Trevor is driving from the leftmost column to the rightmost column.
Every minute Michael must move downwards and Trevor must move rightwards. Specifically, Michael can move from position $$$(i, j)$$$ at time $$$t$$$ to either $$$(i+1, j-1)$$$, $$$(i+1, j)$$$ or $$$(i+1, j+1)$$$ at time $$$t+1$$$. Trevor can move from position $$$(i, j)$$$ at time $$$t$$$ to $$$(i-1, j+1)$$$, $$$(i, j+1)$$$ or $$$(i+1, j+1)$$$ at time $$$t+1$$$
To further confuse the cops and help them escape, they decide to meet somewhere along the way and swap vehicles quickly. This means that they must be in the same position at the same time at least once.
Both love pulling off stunts, and for each hill that they drive over, they will get points equal to the height of that hill. Help them maximize their total style points from this journey!
The first line contains 2 space-separated integers $$$n$$$ (the number of rows) and $$$m$$$ (the number of columns). The following $$$n$$$ lines contain $$$m$$$ integers each, denoting the heights of each hill in the grid.
$$$ 1 \le n \le 10^3$$$
$$$ 1 \le m \le 10^3$$$
$$$ 1 \le height(i,j) \le 10^5$$$
A single integer, the maximum style points that can be obtained by the pair.
2 2 1 1 2 2
7
3 3 1 2 3 4 5 6 7 8 9
42
If the starting position is the same, this counts as a 'meeting' and they need not meet again. Also, if they drive over the same hill they both get style points from that hill.
Jarvis is developing a new gaming platform where users can purchase games and play online together called Vapor. On Vapor, users can become friends with other users to increase the size of their friend groups. Two users are in the same friend group if and only if they are friends or one user is friends with someone in the same friend group as the other user.
Jarvis wants to add new functionality to Vapor to help organize e-sports tournaments with teams of fixed size to attract more users to the site, but he isn't sure how big he can make the tournaments. A team is valid if and only if all of the users in the team belong to the same friend group because users refuse to play with people they aren't acquainted with. Furthermore, each friend group will only send one team at maximum to each tournament to avoid infighting within the group.
You need to program a system that given the current state of the Vapor friend network will be able to find out how many valid teams can participate in a tournament with a given team size. You will need to process two types of queries. For query type $$$1$$$, you will be given two integers $$$x$$$ and $$$y$$$, which indicates that users $$$x$$$ and $$$y$$$ are now friends. For query type $$$2$$$, you will be given an integer $$$s$$$, and you must output the maximum number of valid teams of size $$$s$$$ that can compete in the tournament. Initially, all users do not have any friends.
The first line of the input consists of two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n,q \leq 10^5$$$) — the number of Vapor users and the number of queries to process. The next $$$q$$$ lines of the input are one of two query types. If the line begins with a $$$1$$$, there will be two more integers on the line $$$x$$$ and $$$y$$$ ($$$1 \leq x, y \leq n$$$) indicating that $$$x$$$ and $$$y$$$ are now friends. If the line begins with a $$$2$$$, there will be one more integer on the line $$$s$$$ ($$$1 \leq s \leq n$$$), indicating that you must find the number of teams that can participate in a tournament with team size $$$s$$$.
For each query of type $$$2$$$, output a single integer and new line representing the maximum number of valid teams that can participate in a tournament with team size $$$s$$$.
5 6 2 2 1 1 2 2 2 2 3 1 1 3 2 3
0 1 0 1
7 9 2 1 2 2 1 1 2 1 2 3 1 4 5 1 5 6 1 6 7 2 3 2 4
7 0 2 1
MC Matthew and Demolition Dan are playing their favorite Lego style adventure game! To spice up their vanilla crafting experience, they decided to add a mod enabling the creation of custom TNT. Matthew has placed $$$N$$$ pieces of modded TNT, which we will consider as singular points $$$(x_i, y_i, z_i)$$$, in his world. Each piece of TNT has a volatility constant of $$$v_i$$$ (not necessarily an integer), which is proportional to how powerful of a blast it can produce and how sensitive it is to disturbances in its surroundings (namely other TNT exploding). Demolition Dan has been challenged by MC Matthew to place a single piece of TNT to trigger all of the pre-placed TNT at the same time (this means that Dan cannot use chain reactions to trigger some subset of Matthew's TNT, which will then subsequently trigger the rest of the already placed TNT). Note that Dan does not necessarily need to choose a lattice point as his location for placement, and multiple pieces of TNT can be placed at the same coordinates.
If Dan places TNT at $$$(x, y, z)$$$, and one of Matthew's TNT pieces is at $$$(x_i, y_i, z_i)$$$, then the volatility of Dan's TNT must be at least
The higher the volatility constant of TNT, the more expensive it is to craft it. Can you help Dan find the position for his TNT that minimizes the volatility required, and output that volatility constant?
The first line of input will contain a single integer $$$N$$$ ($$$1 \leq N \leq 20000$$$), the number of pieces of TNT that MC Matthew has placed down. The next $$$N$$$ lines of input will contain four space separated integers $$$x_i$$$, $$$y_i$$$, $$$z_i$$$, and $$$v_i$$$ ($$$0 \leq x_i, y_i, z_i \leq 10^6$$$, $$$1 \leq v_i \leq 10^6$$$) representing the coordinates of a TNT piece and its volatility.
Output the minimum volatility constant necessary to complete the detonation. Answers with a relative or absolute error of at most $$$10^{−6}$$$ will be considered correct.
4 0 0 0 1 1 2 0 1 3 4 0 1 2 1 0 1
3.50000000
1 1 1 1 1
0.00000000
3 1 0 0 1 2 1 1 4 3 2 3 2
2.33333333