PurpleCrayon has recently solved P=NP! He refused to share his proof (or his $$$1000000$$$ prize as part of the raffle prize pool) so we cannot use it as our Very Easy 1. Instead, we decided to create our own P=NP, so here it is. Count the number of solutions to the equation
$$$P=N \cdot P$$$
when $$$0 \leq P \leq X$$$ and $$$0 \leq N \leq Y$$$ where $$$X$$$ and $$$Y$$$ are given as input.
One line with two integers, $$$X$$$ and $$$Y$$$. ($$$1 \leq X, Y \leq 1000$$$). Note that despite $$$X$$$ and $$$Y$$$ being greater than $$$0$$$, $$$N$$$ and $$$P$$$ in the equation can be greater than or equal to $$$0$$$.
A single integer denoting the number of pairs $$$(N, P)$$$ such that $$$P=N \cdot P$$$ and $$$(0 \leq N \leq X)$$$ and $$$(0 \leq P \leq Y)$$$.
2 2
5
The valid pairs of $$$(N, P)$$$ are $$$(0, 0)$$$, $$$(1, 0)$$$, $$$(1, 1)$$$, $$$(1, 2)$$$, and $$$(2, 0)$$$.
Problem idea: chessbot
Problem preparation: chessbot
Occurances: Novice 1, Intermediate 1
Elijah has taken some tests and he didn't do as well as he liked. So he decided to use his coding skills to hack into the grading system. The problem is, to be lowkey about it, he only will delete one test score.
What is the maximum average score he can get after deleting one test score (rounded down to the nearest tenth, i.e. $$$3.46$$$ would be rounded down to $$$3.4$$$).
The first line contains $$$N$$$ $$$(2 \leq N \leq 1000)$$$, $$$N$$$ being the number of test scores.
The next line contains $$$N$$$ integers $$$a_1, a_2, \cdots, a_n$$$ where $$$a_i$$$ represents the test score Elijah got on test $$$i$$$ $$$(0 \leq a_i \leq 100)$$$.
Please output the maximum possible average, rounded down to the nearest tenth, of the remaining test scores given that he can remove one test.
*Note, if the answer rounds to an integer please output the tenth place, for example, if the average was $$$5$$$ output $$$5.0$$$.
6 8 2 3 9 10 3
6.6
Problem idea: Bossologist
Problem preparation: Bossologist
Occurances: Novice 2
Goma was busy picking flowers for Peach when he discovered a patch of flowers in the form of an $$$N$$$x$$$M$$$ lattice with one flower per point. Starting from point $$$(1, 1)$$$ of the lattice, Goma will walk in a straight line picking up all flowers in the points he passes through (including $$$(1, 1)$$$). He wants to find a path to maximize the number of flowers he picks, and he also wants to know the number of ways to walk that will maximize the number of flowers he picks up.
You will answer $$$T$$$ testcases $$$(1 \leq T \leq 10)$$$ where each testcase is: two integers $$$N$$$, $$$M$$$ $$$(2 \leq N, M \leq 1000)$$$, the dimensions of the grid.
The first line of the input will be $$$T$$$, followed by $$$T$$$ lines with two integers each $$$N$$$ and $$$M$$$ respectively.
Two integers $$$a$$$ and $$$b$$$ where $$$a$$$ is the maximum amount of flowers that can be picked up by Goma starting from $$$(1, 1)$$$ and $$$b$$$ is the number of unique ways he can walk to pick up flowers starting from point $$$(1, 1)$$$.
2 2 2 3 2
2 3 3 1
In the first testcase, Goma can pick up two flowers at most, and he can walk from $$$(1, 1)$$$ to $$$(2, 1)$$$; $$$(1, 1)$$$ to $$$(2, 2)$$$; and from $$$(1, 1)$$$ to $$$(1, 2)$$$ to pick up his $$$2$$$ flowers
In the second testcase, it can be proven that Goma can only pick up $$$3$$$ flowers at best, walking from $$$(1, 1)$$$ to $$$(3, 1)$$$.
Problem idea: chessbot
Problem preparation: chessbot
Occurances: Novice 3
Elijah is playing against a computer in a game called 'ABCs', where each side takes turns playing the letter $$$A$$$, $$$B$$$, or $$$C$$$, with the computer going first. Every time Elijah plays a letter, he gets a point if and only if it is a card that the computer has played the most of up until that point (ties included). For example if the computer has played $$$AABC$$$, Elijah will only get a point if he plays $$$A$$$, but if the computer has played $$$ACBBC$$$ then Elijah will get a point whether he plays a $$$B$$$ or a $$$C$$$.
Being the trickster that he is, Elijah hacked into the game and found out the exact order the computer will play the letters. Unfortunately for him, the game found out about this trickery, and decided to punish him by only allowing him to play a single letter every turn (i.e. either all $$$A$$$s, all $$$B$$$s or all $$$C$$$s). Elijah wants to make the best of the situation, and wants to compute to maximum possible of points he can achieve.
The first line contains $$$N (1 \leq N \leq 10^5)$$$, denoting the number of turns. The next line contains a string with $$$N$$$ characters describing what letters the computer will play in the game (as obtained by Elijah's nefarious hacking).
Output the maximum points that Elijah can achieve if he is only allowed to play one letter the entire game.
9 ABBCCCBAB
7
If Elijah plays all $$$B$$$'s, he will get a point for each turn except for the 1st and 6th one.
Problem idea: Bossologist
Problem preparation: Bossologist
Occurances: Novice 4
Cameron is a cashier for a store and at the end of the day, Cameron wrote down the money he got from each customer throughout the day. His manager wants the mean, median, and mode of the list of money from each customer. The manager wants all numbers to be rounded down to the nearest integer, and if there are multiple modes, then the manager wants the largest mode. If the number of customers that day was even, then the manager wants the median to be the average of the two middle numbers, rounded down.
The first line has an integer $$$1 \lt N \leq 1000$$$, representing the number of customers throughout the day.
The second line has $$$N$$$ space-separated integers, $$$1 \leq K \leq 1000$$$, where $$$K$$$ represents each space-separated integer.
Print the mean, median, and mode of the list of numbers in that order, each on a separate line, rounding down to the nearest integer.
5 3 7 5 18 7
8 7 7
Problem idea: Spark
Problem preparation: Spark
Occurances: Novice 5
Ryan is a bookworm. He has many books on his shelf, and he wants to sort them alphabetically by their first letter. Furthermore, he wants to sort the books that have the same starting letter by their published years, from oldest to most recent. Note that all the book titles are one word, with all lowercase letters.
The first line has an integer $$$1 \lt N \lt 10000$$$, representing the number of books Ryan has on his shelf.
The next $$$N$$$ lines contain $$$A$$$ and $$$B$$$, where $$$A$$$ is the name of the book (the length of the book title will be $$$3 \leq A \lt 13$$$) and $$$0 \leq B \lt 10000$$$ is the publish year.
Print the final sorted bookshelf, with the name of each book on a separate line.
4 harry 1987 orange 1776 hotels 1973 moon 2018
hotels harry moon orange
Problem idea: Spark
Problem preparation: Spark
Occurances: Novice 6
Cameron the cashier works as a cashier in a beverage store. The store manager wants the menu of the beverages to change weekly, however the sizes of the cups would stay the same as Small, Medium, Large. Over the week, every customer got 1 letter of each word of their order wrong (meaning that the word was the same, including it's length and all other letters of the word except for one letter), and mispronounced their order.
For example, one week the manager decided to sell Lemonade and Punch. A customer asked for a Smell Panch. The actual order the customer was asking for would be the Small Punch. Assuming all the names of the beverages are one word (in the order of size of cup then beverage name "Small Punch"), and assuming that a mispronunciation can't be a mispronunciation of more than one word, help Cameron understand what the customers were asking for.
The first line has an integer $$$1 \lt N \lt 1000$$$, representing the number of orders.
The next $$$N$$$ 3-line chunks represent the details of the order. The first line of the 3-line chunk has one integer, $$$1 \lt A \lt 100$$$ where $$$A$$$ represents the amount of different beverages. The second line of the 3-line chunk contains $$$A$$$ space-separated words representing the names of the beverages. The length of the words will be $$$3 \leq X \leq 13$$$. The third line of the 3-line chunk contains two words, which is the order. The first word represents the cup size and the second word represents the beverage name.
Print the actual order's name of each order, each on different lines.
2 4 water lemonade punch juice melium wader 2 coffee tea mediuf tee
medium water medium tea
Problem idea: Spark
Problem preparation: Spark
Occurances: Novice 7, Intermediate 2
Teamscode has created a problem set for the constants to solve. A problem set consists of $$$N$$$ different problems with each problem having a difficulty $$$d$$$ (not necessarily distinct) and the difficulty is nondecreasing from $$$1$$$ to $$$N$$$. However, the day before the contest, Bossologist messed up and scrambled the problem set into a random order. The rest of the problem writing team is now angry at Bossologist, and would like to compute the number of possible original problem sets to make a case to HR.
The first line contains $$$N$$$ $$$(1 \leq N \leq 10^6)$$$.
The next $$$N$$$ lines contain a unique string $$$s$$$ and an integer $$$d$$$, where $$$s$$$ is the problem name, and $$$d$$$ is the problem difficulty. $$$(1 \leq d \leq 10^6)$$$ The sum of the lengths of all strings is guaranteed less than or equal to $$$10^7$$$.
Output the number of possible different original problem sets, given that a problem set has problem difficulties in a non-decreasing order, and considered distinct if a problem $$$p$$$ appears in a different spot for any $$$p$$$. Due to the large number of possible original problem sets, please output the answer mod $$$10^9 + 7$$$.
9 Average 1 Premins 9 Costs 2 Ordering 3 Books 3 ABCs 2 Mulitples 5 Teleport 2 P=NP 9
24
The answer is not 12... One possible original problem set is:
Average, Costs, ABCs, Teleport, Ordering, Books, Multiples, P=NP, and Premins in that order.
Another one is:
Average, ABCs, Costs, Teleport, Ordering, Books, Multiples, Premins, and P=NP.
Problem idea: Bossologist
Problem preparation: Bossologist
Occurances: Novice 8, Intermediate 5
Chessbot owns a lawn which has $$$N$$$x$$$M$$$ $$$(1 \leq N, M \leq 1000)$$$ patches of grass, represented as a grid of squares, where the top left square is labeled $$$(1, 1)$$$ and the bottom right one is labeled $$$(N, M)$$$. Each patch of grass has a beauty value $$$b_{ij}$$$ associated with it, which denotes the beauty value for the square in the $$$i$$$th row and $$$j$$$th column $$$(1 \leq i \leq N, 1 \leq j \leq M)$$$. Because Chessbot is a negative person, he only cares about the least beauty value. He would like to survey parts of his lawn from the top left square $$$(1, 1)$$$ to a square $$$(x, y)$$$ to see what the minimum beauty value is of that part of his lawn.
The first line contains $$$N$$$, $$$M$$$, and $$$Q$$$ $$$(1 \leq Q \leq 1000)$$$, where $$$Q$$$ denotes the number of queries Chessbot will ask about his lawn.
The next $$$N$$$ lines will contain an $$$N$$$x$$$M$$$ matrix of integers $$$b_{ij}$$$ $$$(1 \leq b_{ij} \leq 10^9)$$$.
The final $$$Q$$$ lines will contain two integers $$$x_q$$$ and $$$y_q$$$.
For each query, output the minimum beauty value of the portion of the grid from $$$(1, 1)$$$ to $$$(x_q, y_q)$$$.
4 5 3 2 3 1 6 2 3 2 1 5 3 5 6 2 3 1 9 6 3 7 2 4 2 1 3 4 3
2 1 1
n the first query, the part of the lawn that Chessbot is interested in is
2 3
3 2
5 6
9 6
The minimum beauty value in this section is $$$2$$$.
Problem idea: Bossologist
Problem preparation: Bossologist
Occurances: Novice 11, Intermediate 4
Alex wants to make stonks so he creates his own company. He slowly hires more people over time as his company grows larger. Each person takes a certain amount of time to earn one dollar for the company, and they are not paid (Alex is a very demanding boss). He wants to buy a new campus for the company which costs $$$X$$$ dollars in order to further expand. Your job is to find how soon he is able to do so.
The first line contains two numbers, $$$N$$$ and $$$X$$$. $$$N$$$ is the amount of people he hires, $$$X$$$ is the target amount of money. $$$(1 \leq N \leq 10^5, 1 \leq X \leq 10^{12})$$$.
Next, N lines follow containing the information of each person he hires. Each line contains two numbers, $$$T$$$ and $$$R$$$, which respectively denotes the time at which the person is hired and how long it takes for them to earn one dollar. $$$(1 \leq T \leq 10^9, 1 \leq R \leq 10^3)$$$.
One number denoting the amount of time it takes for the company to reach at least $$$X$$$ dollars.
3 10 1 1 3 2 3 4
8
The first person is hired at time 1 and makes 1 dollar at every interval, at time 8 he has made 7 dollars. The second person has made 2 dollars, and the third person has made 1 dollar. This is the earliest time that 10 dollars is reached.
Problem idea: Mantlemoose
Problem preparation: Mantlemoose
Occurances: Easy 10, Intermediate 3
Because he was so grateful of the flowers he received, Peach wants to make a necklace for Goma (how sweet!) . He starts off with a straight line of $$$N$$$ beads labeled $$$1$$$ to $$$N$$$ $$$(1 \leq N \leq 4 \cdot 10^5)$$$ all held together with a string. Peach quickly realizes however, that the necklace would be way too long, so he decides to cut it at certain places to shorten the necklace. As he is cutting the necklace, he wants to know how many beads share a single string with a certain bead.
The first line contains $$$N$$$ and $$$M$$$ $$$(1 \leq M \leq 4 \cdot 10^5)$$$.
The next $$$M$$$ lines contain a character and an integer, $$$c$$$ and $$$i$$$ respectively. If $$$c$$$ is 'R', that means Peach cuts the string in between beads $$$i$$$ and $$$i + 1$$$. Otherwise if $$$c$$$ is 'Q', then Peach would like to know how many beads share the same string as bead $$$i$$$, including bead $$$i$$$. $$$(1 \leq i \leq N - 1)$$$
Every time $$$c$$$ is 'Q', output the answer to the query.
6 6 R 2 R 4 Q 1 R 1 Q 6 Q 2
2 2 1
The necklace starts off like this
0-0-0-0-0-0
After the first and second cut it then looks like this
0-0 0-0 0-0
There are two beads on the same string as bead 1
After the third cut out necklace looks like
0 0 0-0 0-0
Two beads share the same string as bead 6, and bead 2 is the only bead on the string.
Problem idea: Bossologist
Problem preparation: Bossologist
Occurances: Novice 9, Intermediate 6, Advanced 1
This is the easy version of the problem. The difference between the easy and hard versions is that for this problem (the easy version) $$$k = 1$$$ and $$$(1 \leq n \leq 10^{9})$$$.
Peach has finally taken Goma out to eat fried fish. There is an infinite amount of fish in the restaurant they are at. They are lined up in a way such that the $$$i$$$th fish from the entrance has flavor $$$i^k$$$. In other words, the fishes have flavor $$$1^k, 2^k, 3^k, 4^k, \cdots, \infty^k$$$. So when eating, Peach will pick a starting point and an ending point and eat all the fishes from the starting point to the ending point (excluding the ending point). The total flavor of those fishes will be the sum of the flavor of each individual fish, so if the starting point is $$$4$$$ and the ending point is $$$6$$$ (with $$$k = 1$$$), the total flavor is $$$9$$$ (excluding endpoint). They will visit the restaurant for the next $$$D$$$ days would like to eat a total flavor of $$$n[i]$$$ on day $$$i$$$ and would like you to find any pair of starting and ending points such that the total flavor is $$$n[i]$$$. Due to the fact they do not want to walk that far before eating, the ending point must be $$$\leq n$$$.
More formally, you will have to answer D queries with each query being two numbers $$$n$$$ and $$$k$$$ $$$(k = 1)$$$, and you have to find and output any two numbers $$$a$$$ and $$$b (1 \leq a \lt b \leq n)$$$ such that $$$\sum_{i=a}^{b-1} i^k $$$ is $$$n$$$. Remember again to exclude the right endpoint.
The first line will be one integer $$$D$$$, the number of days $$$(1 \leq D \leq 10)$$$ followed by $$$D$$$ lines of 2 integers on the $$$i$$$th line, $$$n[i]$$$ $$$(1 \leq n \leq 10^{9})$$$ the total flavor of fish they want to eat on the $$$i$$$th day and $$$k[i]$$$, the $$$k$$$ used to evaluate flavors on the $$$i$$$th day. Remember for this version of the problem, $$$k = 1$$$ for all testcases.
$$$D$$$ lines with two integers the $$$i$$$th line, $$$a[i]$$$ and $$$b[i]$$$ $$$(1 \leq a[i] \lt b[i] \leq n)$$$ where $$$\sum_{i=a}^{b-1} i^k $$$ is equal to $$$n[i]$$$. If there is no $$$a$$$ and $$$b$$$ that satisfy the constraints, output "-1 -1" without the quotes. If there are multiple solutions, output any of them.
If your answer does not satisfy $$$(1 \leq a \lt b \leq n)$$$, the $$$\sum_{i=a}^{b-1} i^k $$$ is not equal to $$$n$$$, or you did not find an answer for a pair the judger determines there is an answer to, you will receive WA as your verdict.
4 1 1 4 1 6 1 54 1
-1 -1 -1 -1 1 4 2 11
Remember $$$k = 1$$$ for all testcases.
There is no solution for $$$n = 1$$$. $$$(1, 2)$$$ is not a valid solution since $$$2$$$, the ending point, is larger than $$$n$$$, or $$$(1 \leq 1 \lt 2 \leq n)$$$ is not satisfied.
There is also no solution for $$$n = 4$$$.
For $$$n = 6$$$, $$$(1, 4)$$$ is the only solution, not $$$(6, 7)$$$ does not work since $$$7$$$ is not $$$\leq 6$$$, or $$$7$$$ is not $$$\leq n$$$. Also just note that $$$(5, 6)$$$ does not work since this sums up to $$$5$$$, not $$$6$$$.
For $$$n = 54$$$, $$$(2, 11)$$$, $$$(12, 16)$$$ and $$$(17, 20)$$$ are all solutions.
Problem idea: chessbot
Problem preparation: chessbot
Occurances: Novice 12, Intermediate 7, Advanced 2
Shion is cooking an amazing feast for you—so amazing that her toxic food sometimes melts through the bowl! She uses $$$N$$$ $$$(1 \leq N \leq 10^5)$$$ ingredients where the quantity of the $$$i$$$th ingredient is $$$A_i$$$ $$$(1 \leq A_i \leq 10^5)$$$. The tastiness of the meal is the maximum of $$$lcm(A_i, A_j)$$$ over all $$$i \lt j$$$. You don't want to acquire the poison resistance skill after eating her food, so you decide to sneak in an extra ingredient with quantity $$$B$$$ $$$(1 \leq B \leq K \cdot max(A_i), \, 2 \leq K \leq 10)$$$ for Shion to also use. Find the value of $$$B$$$ that maximizes the tastiness of your potentially final feast!
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first line of each test case contains two integers, $$$N, K$$$.
The second line of each test case contains $$$N$$$ integers, $$$A_1, A_2, \dots , A_N$$$.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output the value of $$$B$$$ that maximizes the tastiness of your feast.
2 3 2 1 1 1 3 2 1 1 2
2 3
For the first test case, $$$B$$$ can be $$$1$$$ or $$$2$$$. $$$B=2$$$ gives tastiness $$$ = \max(lcm(1,1), \, lcm(1,1), \, lcm(1,1), \, lcm(1,2), \, lcm(1,2), \, lcm(1,2)) = 2$$$, which is the maximum, so $$$2$$$ is the answer.
For the second test case, $$$B$$$ can be $$$1, \, 2, \, 3,$$$ or $$$4$$$. $$$B=3$$$ gives tastiness $$$ = \max(lcm(1,1), lcm(1,2), lcm(1,2), lcm(1,3), lcm(1,3) ,lcm(2,3)) = 6 $$$, which is the maximum, so $$$3$$$ is the answer.
Problem idea: codicon
Problem preparation: codicon
Occurances: Novice 13, Intermediate 8, Advanced 3
Chessbot would like to make it through his $$$N$$$x$$$M$$$ $$$(1 \leq N, M \leq 1000)$$$ yard in as little steps as possible going from the top left corner $$$(1, 1)$$$ to the bottom right $$$(N, M)$$$. A step consists of either going up, down, left, or right, and Chessbot cannot leave his yard. However there are a ton rocks in the way, which might hamper him, or even possibly prevent him from making it!
Fortunately for him, there are $$$K (1 \leq K \leq 3 \cdot 10^5)$$$ one way teleporters which go from $$$(x_1, y_1)$$$ to $$$(x_2, y_2)$$$. If Chessbot steps on $$$(x_1, y_1)$$$ for a teleporter then he automatically will be teleported to $$$(x_2, y_2) $$$(i.e. he must take the teleporter). Note that this means if there is another teleporter that goes from $$$(x_2, y_2)$$$ to another point $$$(x_3, y_3)$$$, he must go through that one as well. Each starting point for a teleporter is unique.
The first line contains $$$N$$$, $$$M$$$, and $$$K$$$.
The next $$$N$$$ lines specify the layout of Chessbot's yard, where a '#' represents a rock and a '.' represents an empty space.
The next $$$K$$$ lines each have 4 integers $$$x_1, y_1, x_2,$$$ and $$$y_2$$$ for a specific teleporter.
*It is guaranteed that it is always possible to go from the top left to the bottom left, and that the teleporters never make a cycle (i.e. one teleporter going from $$$(1, 1)$$$ to $$$(2, 2)$$$ and another going from $$$(2, 2)$$$ to $$$(1, 1)$$$). There will never be a rock or a teleporter starting from $$$(1, 1)$$$ or $$$(N, M)$$$.
Output an integer describing the minimum amount of steps Chessbot needs to go from the top left corner of his yard to the bottom right corner.
5 5 3 ..#.. .#... ...#. .##.. #.... 4 1 5 2 5 2 4 4 1 2 5 2
3
Chessbot can move once right to go into the teleporter at $$$(1, 2)$$$, which will send him to $$$(5, 2)$$$. However there is another teleporter at $$$(5, 2)$$$ which will send him to $$$(4, 4)$$$. From there he can move once right, then once down to reach the bottom left in 3 steps.
Problem idea: Bossologist
Problem preparation: Bossologist/codicon
Occurances: Novice 14, Intermediate 9, Advanced 4
Kanna is playing a game with Saikawa! The game is played on an $$$N$$$ by $$$N$$$ $$$(1 \leq N \leq 2000)$$$ field of flowers. The flower at the $$$i$$$th row and $$$j$$$th column has color $$$C_{i,j}$$$ $$$(1 \leq C_{i,j} \leq 10^6)$$$.
A player can start at any flower and move to the right along the row until they choose to stop or they are at the edge of the field.
Let's say they started at column $$$A$$$ and ended at column $$$B$$$.
Then, they can repeatedly move one down along the column as long as each time they move both conditions are satisfied:
1. They are not at the edge of the field. 2. $$$C_{R+1,i} = C_{R,i}$$$ for all $$$A \leq i \leq B$$$ where $$$R$$$ is their current row (before moving).
The score for the player is the area of the rectangle with top left corner at their starting point and bottom right corner at their ending point. For example, if Ilulu starts at row $$$1$$$ and column $$$1$$$ and ends at row $$$2$$$ and column $$$3$$$, her score is $$$6$$$. After both players finish moving, the winner is the one with the higher score.
If Kanna wins, Saikawa needs to rub her tummy as a "penalty" game. Despite being hundreds of years old, Kanna never decided to do any cp, so she asks you to figure out the maximum score she can achieve.
there's supposed to be an anime image here but due to cf having a limit of 1mb you don't get to see it. go to the git to find it.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^6)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first line of each test case contains an integer $$$N$$$.
The next $$$N$$$ lines describe the field of flowers. The $$$i$$$th of which contains $$$N$$$ integers, $$$C_{i,1}, C_{i,2}, … , C_{i,N}$$$.
It is guaranteed that the sum of $$$N^2$$$ over all test cases does not exceed $$$4 \cdot 10^6$$$.
For each test case, output the maximum score Kanna can achieve.
3 1 1 2 1 2 1 2 3 1 2 5 1 2 5 4 2 5
1 4 6
For the first test case, Kanna can start at $$$(1,1)$$$ and end at $$$(1,1)$$$. The rectangle bounded looks like: $$$ \begin{pmatrix} 1 \end{pmatrix} $$$. The answer is $$$1 \cdot 1 = 1$$$.
——
For the second test case, Kanna can start at $$$(1,1)$$$, move to the right to $$$(1,2)$$$ and then finally move down to $$$(2,2)$$$. The rectangle bounded looks like: $$$ \begin{pmatrix} 1 & 2 \\ 1 & 2 \end{pmatrix} $$$. The answer is $$$ 2 \cdot 2 = 4$$$.
——
For the third test case, one way for Kanna to maximize her score would be to start at $$$(1,2)$$$, move to the right to $$$(1,3)$$$ and then finally move down to $$$(3,3)$$$. The rectangle bounded looks like: $$$ \begin{pmatrix} 2 & 5 \\ 2 & 5 \\ 2 & 5 \end{pmatrix} $$$. The answer is $$$ 3 \cdot 2 = 6$$$.
Problem idea: codicon/PurpleCrayon
Problem preparation: codicon
Occurances: Intermediate 12, Advanced 7
For a second time, Elijah is playing against a computer in a game called 'ABCs', where each side takes turns playing the letter $$$A$$$, $$$B$$$, or $$$C$$$, with the computer going first. Every time Elijah plays a letter, he gets a point if and only if it is a card that the computer has played the most of up until that point (ties included). For example if the computer has played $$$AABC$$$, Elijah will only get a point if he plays $$$A$$$, but if the computer has played $$$ACBBC$$$ then Elijah will get a point whether he plays a $$$B$$$ or a $$$C$$$.
Being the trickster that he is, Elijah hacked into the game and found out the exact order the computer will play the letters. Unfortunately for him, the game found out about this trickery, and this time decided to punish him by only allowing him switch letters after playing the same letter at least $$$K$$$ consecutive times. Elijah wants to make the best of the situation, and wants to compute to maximum possible of points he can achieve.
The first line contains $$$N (1 \leq N \leq 10^5)$$$, denoting the number of turns, and $$$K (1 \leq K \leq N)$$$. The next line contains a string with $$$N$$$ characters describing what letters the computer will play in the game (as obtained by Elijah's nefarious hacking).
Output the maximum points that Elijah can achieve if he is only allowed to switch letters after playing the same letter at least $$$K$$$ consecutive times.
9 3 ABBCCCBAB
8
If Elijah plays $$$BBBBCCCBB$$$, he gets a point on every turn except the first one.
Problem idea: Bossologist/PurpleCrayon
Problem preparation: Bossologist
Occurances: Novice 15, Intermediate 10, Advanced 5
Peach and Goma were playing with trees, and Peach had a new idea. Note, all trees will be $$$0$$$-based, or all nodes of a tree with $$$n$$$ vertices will be [$$$0$$$, $$$n$$$). She defined the width of a rooted tree as the maximum number of nodes that have the same depth from the root. Consider the tree $$$(0, 1)$$$, $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(1, 4)$$$. The width of the tree rooted at node $$$0$$$ is $$$2$$$, (nodes $$$2$$$ and $$$4$$$ having a distance of $$$2$$$ away). However, the width of the same tree rooted at node $$$1$$$ has a width of $$$3$$$, (nodes $$$0$$$, $$$2$$$, and $$$4$$$ having a distance of $$$1$$$ away). Peach asked Goma to find the maximum width of a tree with $$$n$$$ nodes $$$(1 \leq n \leq 5 \cdot 10^{5})$$$ across all possible roots.
However, chessbot (the problemsetter), is lazy and decided to give you trees as input with the following format. A modtree with $$$n$$$ nodes is a tree defined by an integer $$$n$$$. For all nodes $$$i$$$ [$$$1$$$, $$$n$$$) there is an edge between $$$i$$$ and $$$n \mod i$$$. It can be proven that for all $$$n$$$, the modtree size $$$n$$$ will be connected and satisfy all the properties of a tree. Note $$$n \mod i$$$ is not $$$i \mod n$$$ and that the tree is labeled $$$0$$$-based.
A tree with $$$4$$$ nodes will have edges, $$$(1, 0)$$$, $$$(2, 0)$$$, $$$(3, 1)$$$.
You will answer $$$T$$$ testcases $$$(1 \leq T \leq 5 \cdot 10^{5})$$$. There will then be $$$T$$$ lines with one testcase each. The $$$i$$$th testcase consists of a single integer $$$n$$$ $$$(1 \leq n \leq 5 \cdot 10^{5})$$$, the number of nodes on the modtree. It is guaranteed that the sum of $$$n$$$ will not exceed $$$5 \cdot 10^{5}$$$.
You will output $$$T$$$ lines, one line per testcase, the $$$i$$$th line denoting the maximum width of the $$$i$$$th tree across all possible roots.
3 4 5 100
2 3 37
The edges of the first tree (size $$$4$$$) are described in the latter half of the problem statement, and the width cannot be larger than $$$2$$$. Rooting the tree at node $$$1$$$, for instance, will give a width of $$$2$$$ (nodes $$$0$$$ and $$$2$$$ being distance $$$1$$$ away).
The second testcase was also described in the problem statement, rooting the tree at node $$$1$$$ will give a width of $$$3$$$.
Due to the difficulty of drawing a tree with $$$100$$$ nodes, proving the third sample input will remain an exercise to the reader.
Problem idea: chessbot
Problem preparation: chessbot
Occurances: Intermediate 13, Advanced 8
Kakyoin is painting a picture on an $$$N$$$ by $$$N$$$ grid of cells $$$(1 \leq N \leq 10^6)$$$. At first every cell in the grid contains a $$$0$$$. With each stroke of his brush, he can paint a rectangle of $$$1$$$'s where the sides of the rectangle are parallel to the sides of the grid. However, the new rectangle of $$$1$$$'s cannot cover any previously painted $$$1$$$'s and every $$$1$$$ in the rectangle cannot share a row or column with any previously painted $$$1$$$'s. At some point Kakyoin was interesting in painting, but Araki forgot and now he's too busy using his emerald splash. So he asks you to find the sum of the number of strokes in his painting across all possible paintings that he can paint modulo $$$10^9 + 7$$$. Two paintings are considered different if the number in some cell differs between the two.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The only line of each test case contains an integer $$$N$$$.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output the sum of the number of strokes in Kakyoin's painting across all possible paintings that he can paint modulo $$$10^9 + 7$$$.
5 1 2 3 420 696969
1 13 154 513291815 774841820
For the first test case of the sample, there is only $$$1$$$ possible painting that uses at least one stroke:
$$$ \begin{pmatrix} 1 \end{pmatrix} $$$
The total number of strokes is $$$1$$$.
——
For the second test case of the sample, there are $$$11$$$ possible paintings that use at least one stroke:
$$$ \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} $$$
$$$ \begin{pmatrix} 1 & 1 \\ 0 & 0 \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 0 & 0 \\ 1 & 1 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 1 & 0 \end{pmatrix} $$$
$$$ \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} $$$
$$$ \begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix} $$$
The total number of strokes is $$$ 4 \cdot 1 + 4 \cdot 1 + 2 \cdot 2 + 1 \cdot 1 = 13 $$$.
Problem idea: codicon
Problem preparation: codicon
Occurances: Intermediate 15, Advanced 10
This is the revised version since i am too lazy to fix the checker.
This is the hard version of the problem. The difference between the easy and hard versions is that for this problem (the hard version) $$$ (2 \leq k \leq 20 ) $$$ and $$$ (1 \leq n \leq 10^{18}) $$$.
Peach has finally taken Goma out to eat fried fish. There is an infinite amount of fish in the restaurant they are at. They are lined up in a way such that the $$$i$$$th fish from the entrance has flavor $$$i^k$$$. In other words, the fishes have flavor $$$1^k, 2^k, 3^k, 4^k, \cdots, \infty^k$$$. So when eating, Peach will pick a starting point and an ending point and eat all the fishes from the starting point to the ending point (excluding the ending point). The total flavor of those fishes will be the sum of the flavor of each individual fish, so if the starting point is $$$4$$$ and the ending point is $$$6$$$ (with $$$k = 1$$$), the total flavor is 9 (excluding endpoint), if $$$k$$$ was equal to $$$3$$$, it would be $$$4^3 + 5^3$$$ or $$$189$$$. They will visit the restaurant for the next $$$Q$$$ days would like to eat a total flavor of $$$n[i]$$$ on day $$$i$$$ and would like you to find any pair of starting and ending points such that the total flavor is $$$n[i]$$$. Due to the fact they do not want to walk that far before eating, the ending point must be $$$\leq n$$$.
More formally, you will have to answer $$$D$$$ queries with each query being two numbers $$$n$$$ and $$$k$$$ and you have to find and output any two numbers $$$a$$$ and $$$b (1 \leq a \lt b \leq n) $$$ such that $$$\sum_{i=a}^{b-1} i^k $$$. Remember again to exclude the right endpoint.
The first line will be one integer $$$Q$$$, the number of queries $$$(1 \leq Q \leq 10)$$$ followed by $$$Q$$$ lines of $$$2$$$ integers on the $$$i$$$th line, $$$n[i]$$$ $$$(1 \leq n \leq 10^{18})$$$ the total flavor of fish they want to eat on the $$$i$$$th day and $$$k[i]$$$ $$$(2 \leq k \leq 20)$$$, the $$$k$$$ used to evaluate flavors on the $$$i$$$th day.
If your program passes tests 1-9, it would have ac'ed in contest. However, I realized that tests 1-9 are actually cheeseable and have added tests 10-12. If your code ac's tests 10-12, you have properly solved the problem :). Tests 10-12 are in the junk folder of the github as 11.in, 12.in, and 13.in.
$$$D$$$ lines with two integers the i'th line, $$$a[i]$$$ and $$$b[i]$$$ $$$(1 \leq a[i] \lt b[i] \leq n)$$$ where $$$\sum_{i=a}^{b-1} i^k $$$ is equal to $$$n[i]$$$. If there is no $$$a$$$ and $$$b$$$ that satisfy the constraints, output "-1 -1" without the quotes. If there are multiple solutions, output the one that minimizes $$$a$$$.
If your answer does not satisfy $$$(1 \leq a \lt b \leq n)$$$, $$$\sum_{i=a}^{b-1} i^k $$$ is not equal to $$$n$$$, or you did not find an answer for a pair the judger determines there is an answer to, you will receive WA as your verdict.
4 4 2 6 3 189 3 54 2
2 3 -1 -1 4 6 2 6
For $$$n = 4$$$ and $$$k = 2$$$, $$$(2, 3)$$$ is the only solution $$$2^2 = 4$$$.
For $$$n = 6$$$ and $$$k = 3$$$, it can be shown that there is no solution.
The fourth testcase was described in the problem statement.
For $$$n = 54$$$ and $$$k = 2$$$, the solution is $$$(2, 6)$$$, $$$2^2 + 3^2 + 4^4 + 5^2 = 4 + 9 + 16 + 25 = 54$$$.
Problem idea: chessbot/codicon/PurpleCrayon
Problem preparation: chessbot
Occurances: Intermediate 11, Advanced 6
Vivy is carrying out the singularity project! She is currently at the start of everything at event $$$0$$$. Unfortunately, $$$N$$$ $$$(1 \leq N \leq 10^5) $$$ more timeline changing events are about to occur. Luckily, Vivy has picked a special number $$$X$$$ $$$(1 \leq X \leq 10^9)$$$ to assist her project. When the $$$i$$$th event occurs, a random number $$$A$$$ from $$$0$$$ to $$$X-1$$$ is generated. Then, it becomes possible to go from event $$$(A \mod i)$$$ to event $$$i$$$ and event $$$i$$$ is considered a child of event $$$(A \mod i)$$$. If after all events occur, event $$$0$$$ has more than $$$2$$$ children or there exists an event $$$i$$$ such that $$$i \gt 0$$$ and it has more than $$$1$$$ child, the timeline becomes unstable and only a tragic future where AIs are bent on eradicating humanity awaits. If no such event exists, the singularity project is successful and humans and AIs live happily ever after. As Vivy's partner, you want to test the value of $$$X$$$ and determine the probability that the singularity project is successful.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first and only line of each test case contains two integers, $$$N, X$$$.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.
The probability that the singularity project is successful for each test case can be expressed as a fraction $$$\frac{P}{Q}$$$. For each test case, output $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$. $$$Q^{-1}$$$ is the modular inverse of $$$Q$$$, so $$$Q \cdot Q^{-1} \equiv 1 \mod 10^9+7$$$.
5 1 1 2 3 3 5 4 7 42069 123456789
1 1 200000002 250728865 734982873
For the first test case, event $$$1$$$ must be a child of event $$$0$$$ because the random number $$$A$$$ must be $$$0$$$ and $$$0 \mod 1 = 0$$$. We end up with timeline $$$0 \rightarrow 1$$$. Event $$$1$$$ has no children and event $$$0$$$ has $$$1$$$ child, so the singularity project was successful. The probability and answer is $$$1$$$.
For the second test case, again, event $$$1$$$ must be a child of event $$$0$$$. Additionally, event $$$2$$$ must be a child of event $$$0$$$ or event $$$1$$$. We end up with either timeline $$$2 \leftarrow 0 \rightarrow 1$$$ or $$$0 \rightarrow 1 \rightarrow 2$$$. In either case, event $$$0$$$ has at most $$$2$$$ children and no event $$$i$$$ such that $$$i \gt 0$$$ has more than $$$1$$$ child. The probability and answer is $$$1$$$.
For the third test case, again, event $$$1$$$ must be a child of event $$$0$$$. Event $$$2$$$ is a child of event $$$0$$$ when the random number $$$A$$$ is $$$0,2,$$$ or $$$4$$$ and a child of event $$$1$$$ when $$$A$$$ is $$$1$$$ or $$$3$$$. Thus the timeline $$$2 \leftarrow 0 \rightarrow 1$$$ occurs with probability $$$ \frac{3}{5} $$$ and the timeline $$$0 \rightarrow 1 \rightarrow 2$$$ occurs with probability $$$\frac{2}{5}$$$. For the first timeline, event $$$3$$$ is a child of event $$$2$$$ when the random number $$$A$$$ is $$$2$$$, a child of event $$$1$$$ when $$$A$$$ is $$$1$$$ or $$$4$$$, and a child of event $$$0$$$ when $$$A$$$ is $$$0$$$ or $$$3$$$. If event $$$3$$$ is a child of event $$$0$$$, event $$$0$$$ has more than $$$2$$$ children and the timeline becomes unstable. It is fine for event $$$3$$$ to be a child of event $$$1$$$ or $$$2$$$ though. Thus, the timeline $$$3 \leftarrow 2 \leftarrow 0 \rightarrow 1$$$ occurs with probability $$$\frac{3}{25}$$$ and the timeline $$$2 \leftarrow 0 \rightarrow 1 \rightarrow 3$$$ occurs with probability $$$\frac{6}{25}$$$. Similarly, the timeline $$$0 \rightarrow 1 \rightarrow 2 \rightarrow 3$$$ occurs with probability $$$\frac{2}{25}$$$ and the timeline $$$3 \leftarrow 0 \rightarrow 1 \rightarrow 2$$$ occurs with probability $$$\frac{4}{25}$$$. These are all the final timelines where the singularity project is successful. The probability is thus $$$\frac{3 + 6 + 2 + 4}{25} = \frac{3}{5} $$$. Since $$$3 \cdot 5^{-1} \equiv 3 \cdot 400000003 \equiv 200000002 \mod 10^9 + 7$$$, the answer is $$$200000002$$$.
Problem idea: codicon/PurpleCrayon
Problem preparation: codicon
Occurances: Intermediate 14, Advanced 9
Rengoku is battling a powerful demon! This demon has $$$N$$$ $$$(1 \leq N \leq 10^5)$$$ hearts where the $$$i$$$th heart has health $$$H_i$$$ $$$(1 \leq H_i \leq N)$$$. Luckily for Rengoku, he practices Flame Breathing and knows $$$K$$$ $$$(2 \leq K \leq 2 \cdot 10^5)$$$ different forms. In one attack, he picks a random heart $$$i$$$ such that $$$H_i \gt 0$$$ and also picks a random form $$$F$$$ from $$$1$$$ to $$$K$$$. Then he uses the $$$F$$$th form on the $$$i$$$th heart, reducing its health to $$$\lfloor \frac{H_i}{F} \rfloor$$$ (floor division). The demon is slain after the health of all its hearts drops to $$$0$$$. As Rengoku's kouhai, he assigns you the task of finding the expected number of attacks he will use to slay the demon.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first line of each test case contains two integers, $$$N, K$$$.
The second line of each test case contains $$$N$$$ integers, $$$H_1, H_2, … , H_N$$$.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.
The expected number of attacks Rengoku will use to slay the demon for each test case can be expressed as a fraction $$$\frac{P}{Q}$$$. For each test case, output $$$P \cdot Q^{-1}$$$ modulo $$$10^9+7$$$. $$$Q^{-1}$$$ is the modular inverse of $$$Q$$$, so $$$Q \cdot Q^{-1} \equiv 1 \mod 10^9+7$$$.
3 1 2 1 2 2 1 2 3 3 1 2 3
2 6 750000012
For the first test case, the demon has a single heart with health $$$1$$$. There is a $$$ \frac{1}{2} $$$ chance that Rengoku uses his $$$2$$$nd form and reduces the demon's health to $$$ \lfloor \frac{1}{2} \rfloor = 0 $$$. There is also a $$$ \frac{1}{2} $$$ chance that Rengoku uses his $$$1$$$st form and the demon's health is not affected because it changes to $$$\lfloor \frac{1}{1} \rfloor = 1$$$. It may take Rengoku many attacks because he might repeatedly pick the $$$1$$$st form. It turns out that the answer is $$$2$$$.
Problem idea: codicon
Problem preparation: codicon
Occurances: Advanced 11
Thomas has been caught game! The game he is playing is defly, a game of flying a plane to connect dots, (Note this is slightly different from the actual game). In the game, you have a set of $$$N$$$ points $$$(5 \leq N \leq 5 \cdot 10^5)$$$ and you want to draw a convex polygon around the points such that all the points are contained within it. To use less effort, Thomas is using his skills to minimize the area of such a polygon (more formally these things are called convex hulls). Teacher got mad and destroyed two points in Thomas's set of points, but Thomas does not know which points these are. So he would like to ask you $$$Q$$$ queries $$$(1 \leq Q \leq 5 \cdot 10^5)$$$ where each query is defined as two indices $$$a$$$ and $$$b$$$ $$$(1 \leq a, b \leq N, a \neq b)$$$, and Thomas would like to know what the are of the convex hull of the entire array without those two points would be.
Also, note since the problem setter, chessbot, does not like making edge cases, all of the points will be randomly generated using the following code:
The first line will contain two integers $$$N$$$, $$$Q$$$ $$$(5 \leq N \leq 5 \cdot 10^5, 1 \leq Q \leq 5 \cdot 10^5)$$$. The following $$$N$$$ lines will contain two integers each, the $$$x$$$ and $$$y$$$ coordinates of each of the $$$N$$$ points $$$(1 \leq x,y \leq 10^9)$$$. The following $$$Q$$$ lines will contain two integers each, $$$a$$$ and $$$b$$$ representing the query $$$(1 \leq a, b \leq N, a \neq b)$$$.
Note that despite the points being randomly generated, the queries will not be randomly generated but rather made to fit the previously generated points.
$$$Q$$$ lines, one integer per line representing the answers to the queries. The $$$i$$$th line should be the area of the convex hull with the points $$$a$$$ and $$$b$$$ of the $$$i$$$th query removed multiplied by two. Note that with the given constraints the answer will always fit within a $$$64$$$-bit integer.
Again, make sure you find the area of the convex hull multiplied by two.
5 2 1 1 1 5 5 5 5 1 3 3 1 2 3 5
8 16
The input points look something like a $$$4$$$x$$$4$$$ grid with corners at $$$(1, 1)$$$, $$$(1, 5)$$$, $$$(5, 5)$$$, and $$$(5, 1)$$$ with one point at the center, $$$(3, 3)$$$.
In the first query, we are removing points $$$(1, 1)$$$ and $$$(1, 5)$$$. The remaining points, $$$(1, 5)$$$, $$$(3, 3)$$$, and $$$(5, 5)$$$ make up a triangle that is $$$45$$$-$$$45$$$-$$$90$$$ and has side lengths $$$2 \cdot \sqrt{2}, 2 \cdot \sqrt{2}, 4$$$. The area is $$$(2 \cdot \sqrt{2} \cdot 2 \cdot \sqrt{2})/2$$$, which is $$$4$$$ (proof is left as an exercise to the reader). Then multiply the area by $$$2$$$ and the answer is $$$8$$$.
In the second query we are removing points $$$(5, 5)$$$ and $$$(3, 3)$$$, leaving us with $$$(1, 1)$$$, $$$(1, 5)$$$, and $$$(5, 1)$$$. This also gives us a $$$45$$$-$$$45$$$-$$$90$$$ triangle but with side lengths $$$4$$$, $$$4$$$, $$$4 \cdot \sqrt{2}$$$. The area of the figure (or the convex hull of the figure, they are the same in this case) is $$$((4 \cdot 4)/2)$$$ or $$$8$$$. Multiply that by $$$2$$$ to get $$$16$$$.
Problem idea: chessbot/PurpleCrayon
Problem preparation: chessbot
Occurances: Advanced 13
Sol is trying to get home at location $$$N$$$ from his office at location $$$1$$$ in time for the problem writing meeting which is in $$$K$$$ minutes. There are $$$M$$$ bidirectional roads which connect location $$$a$$$ to location $$$b$$$, each taking $$$w$$$ minutes to go through, and each raising his angriness to $$$f$$$ when passing through the road (Sol is very irritated by traffic). But because he is generally quite calm, at each location his angriness resets back to 0. To stop himself from road raging he wants to minimize his maximum angriness at any point in time.
However, this is not Sol's only challenge. The logistics team is trying to sabotage Sol's trip by making him as angry as possible (the problem writing team is their arch enemy). They do this by closing down a single road that will cause him to endure the most angriness on his drive to his home. Please output the minimal maximum angriness that Sol has to endure on his trip home given that he has to make it in $$$K$$$ minutes, and the logistics team has shut down one of the roads.
The first line contains $$$N$$$, $$$M$$$, and $$$K$$$, where $$$N$$$ is the number of intersections $$$(1 \leq N \leq 10000, 1 \leq M \leq 50000, 1 \leq K \leq 10^9)$$$.
The next $$$M$$$ lines have 4 integers which specify that road. The first two integers are the locations it connects, $$$a$$$ and $$$b$$$ $$$(a \neq b)$$$. The next integer is $$$w$$$ or how long it take in minutes to go through that road, and $$$f$$$ or how angry sol gets when crossing that road $$$(1 \leq a, b \leq N, 1 \leq w \leq 10^4, 1 \leq f \leq 10^9)$$$. Each pair of locations will have at most $$$1$$$ road.
A single integer denoting the minimal maximum angriness that Sol has to endure on his trip home given that he has to make it in $$$K$$$ minutes, and the logistics team has shut down one of the roads. If it is not possible for him to make it in K minutes or less, output $$$-1$$$.
4 6 9 1 2 4 2 1 3 8 1 1 4 8 4 2 3 3 2 2 4 7 2 3 4 2 3
4
If the logistics team wasn't in the way, then Sol could go $$$1 \rightarrow 2 \rightarrow 3 \rightarrow 4$$$ which would get him to his house in $$$9$$$ minutes, and give a maximum angriness of $$$3$$$. However, they could have sabotaged one of these roads. So worst case he gets to his house using $$$1 \rightarrow 4$$$ with angriness $$$4$$$ and in $$$8$$$ minutes which is enough time.
Problem idea: Bossologist/PurpleCrayon
Problem preparation: Bossologist/codicon
Occurances: Advanced 14
Endeavor is a great hero and wants to help keep his country, Japan, safe. Japan contains $$$N$$$ $$$(1 \leq N \leq 10^5)$$$ cities numbered from $$$1$$$ to $$$N$$$. There are also $$$M$$$ $$$(0 \leq M \leq 5 \cdot 10^5)$$$ bidirectional roads where the $$$i$$$th connects city $$$M_{i,a}$$$ to city $$$M_{i,b} \, (M_{i,a} \neq M_{i,b})$$$ and makes the two cities neighbors. It is guaranteed that there is at most $$$1$$$ road between any pair of cities. Japan also has a peculiar feature. Consider a path that visits $$$w$$$ cities from city $$$u$$$ to city $$$v$$$, where the $$$i$$$th city on the path is $$$p_i$$$. Then if $$$p_i \lt p_{i+1}$$$ for all $$$i \lt w$$$, city $$$u$$$ and city $$$v$$$ are neighbors.
Endeavor decides to build a hero office in some cities. To ensure safety and efficiency, he wants at least one of the conditions to be satisfied for every city:
The city has no neighbors.
The city contains an office.
All neighbors of the city contain an office.
Japan is considered safe if this requirement is met.
Unfortunately, as great of a hero as Endeavor is, he still hasn't defeated the greatest villain—money! To cut down on costs, Endeavor's agency decides to build the minimal number of offices such that Japan is safe. Currently, Endeavor is busy roasting evildoers (literally), so he wants you to find this out for him.
The first line contains one integer, $$$T$$$ $$$(1 \leq T \leq 10^5)$$$, the number of test cases. Then $$$T$$$ test cases follow.
The first line of each test case contains $$$2$$$ integers, $$$N, M$$$.
The next $$$M$$$ lines of each test case contain $$$2$$$ integers. The $$$i$$$th such line contains $$$M_{i,a}, M_{i,b}$$$.
It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$. It is also guaranteed that the sum of $$$M$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, output the minimal number of offices to build such that Japan is safe.
3 1 0 3 1 2 3 4 3 3 1 4 2 2 3
0 1 2
Here's the country from first test case:
Here's the country from second test case:
In the second test case, there are $$$3$$$ cities and $$$1$$$ road. A road connects city $$$2$$$ to city $$$3$$$. To minimize the offices built, Endeavor can build an office in either city $$$2$$$ or city $$$3$$$. The answer is $$$1$$$.
Here's the country from third test case:
In the third test case, there are $$$4$$$ cities and $$$3$$$ roads. There is a road that connects city $$$3$$$ to city $$$1$$$, a road that connects city $$$4$$$ to city $$$2$$$, and a road that connects city $$$2$$$ to city $$$3$$$. To minimize the offices built, one solution is for Endeavor to build an office in city $$$1$$$ and city $$$2$$$. Of course, building offices in cities $$$(1,2), \, (3,2),$$$ or $$$(3,4)$$$ all work to achieve the minimal number of offices. The answer is $$$2$$$.
Problem idea: codicon
Problem preparation: codicon
Occurances: Advanced 12
Chessbot had a problem of finding the maximum spanning tree, but since he was too lazy to generate graphs, so he proposed to just use an $$$ N $$$ x $$$ M$$$ lattice where the distance between two points was the euclidian distance squared. PurpleCrayon decided this problem wasn't hard enough and decided to make it a d-dimensional lattice grid where the distance between two points $$$ p_{1} $$$ and $$$ p_{2} $$$, where each point is represented as a tuple length $$$ d $$$ , $$$ x_{1}, x_{2}, \cdots, x_{d} $$$ where $$$x_i$$$is the location on the $$$i$$$th dimension, is $$$ \sum_{i=1}^d | p_{1,i} - p_{2,i} |^k $$$, where $$$d$$$ and $$$k$$$ are given as input. So the question is given a d-dimensional lattice grid (with the i'th dimension being D[i]) and k, find the maximum spanning tree of the graph where there is an edge between all pairs of two points from $$$ (1, 1, \cdots, 1)$$$ and $$$(D[1], D[2], \cdots, D[d])$$$ of the lattice equivalent to the distance formula described above.
You will answer $$$ T $$$ testcases $$$ (1 \leq T \leq 10) $$$. Each testcase consists of 2 lines. The first line is two integers $$$ d (2 \leq d \leq 60) $$$ and $$$ k (1 \leq k \leq 500)$$$. The following line consists of $$$d$$$ integers, which describes the dimensions of the $$$d$$$-dimensional lattice $$$ (D[i] \leq 10^9) $$$.
Testcase 2 satisfies, $$$ d = k = 5, (1 \leq D[i] \leq 5) $$$.
The one integer for the $$$i$$$th testcase, $$$ans[i]$$$, which is the maximum spanning tree of the lattice grid inputted. Since this number may be very large, please find it modulus $$$10^9 +7$$$.
3 2 2 2 2 3 2 2 2 2 4 20 6 9 96 66
5 18 742488253
For the first testcase, you could draw edges between: $$$ (1, 1) $$$ and $$$ (2, 2) $$$ with weight $$$ |1 - 2|^2 + |1 - 2|^2 $$$, $$$(1, 2)$$$ and $$$(2, 1)$$$ with weight $$$|1 - 2|^2 + |2 - 1|^2$$$ , $$$(1, 1)$$$ and $$$(2, 1)$$$ with weight $$$|1 - 2|^2 + |1 - 1|^2$$$ or $$$2 + 2 + 1$$$ summing up to $$$5$$$.
For the second testcase, edges are between $$$(1, 1, 1) \rightarrow (2, 2, 2)$$$; $$$(1, 1, 1) \rightarrow (2, 2, 1)$$$, $$$(1, 1, 1) \rightarrow (2, 1, 2)$$$, $$$(1, 1, 1) \rightarrow (1, 2, 2)$$$, $$$(1, 2, 1) \rightarrow (2, 1, 2)$$$, $$$(2, 1, 1) \rightarrow (1, 2, 2)$$$, $$$(1, 1, 2) \rightarrow (2, 2, 1)$$$ with a total sum of $$$4*(1^2 + 1^2 + 1^2)$$$ + $$$3*(1^2 + 1^2 + 0^2)$$$.
Due to the difficulty of drawing a $$$6\times9\times96 \times 66$$$ $$$4$$$-dimension lattice grid on a $$$2$$$d screen, an explanation is omitted.
Problem idea: chessbot/PurpleCrayon
Problem preparation: chessbot
Occurances: Advanced 15