Alice, Bob, and Cindy are spending their summer abroad together! Not for a vacation though—they all found internship opportunities at a cluster of schools that are located conveniently close together. Thus, the three of them have decided to room together at a shared apartment for the duration of their stay.
They have been staying at this apartment for $$$n$$$ days so far. During each day, exactly one of Alice or Bob or Cindy is responsible for doing the cooking for that day. They don't particularly care about who handles cooking duty on each day, with whoever was in the mood for it usually being the one to take over. But their parents called and expressed their concern about whether the work was being split fairly.
Specifically, the parents want the following property to hold:
Find the minimum $$$k$$$ number of extra days of cooking duty needed in order for it to be possible for the parents' condition to be satisfied.
The first line of input contains a single integer $$$n$$$.
The second line of input contains a string $$$s$$$ of length $$$n$$$, with each character being A or B or C. The $$$i$$$th letter of $$$s$$$ is A if Alice cooked on the $$$i$$$th day; resp. B for Bob and C for Cindy.
Output a single integer, the minimum number of extra days needed until the parents' condition can be fulfilled.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline \text{The string $s$ contains only }\mathtt{A}\text{ or }\mathtt{B}\text{ or }\mathtt{C}\text{ characters.} \\ 1 \leq n \leq 2 \times 10^5 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{20} & n \leq 3 \\ \hline 2 & \mathbf{20} & n \leq 6 \\ \hline 3 & \mathbf{20} & n \leq 500 \\ \hline 4 & \mathbf{20} & \text{There is no }\mathtt{C}\text{ character in $s$.} \\ \hline 5 & \mathbf{20} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
5 BAABB
2
4 ACBA
0
In the first sample input, we can satisfy the condition after $$$k=2$$$ extra days; for example, we could have Alice cook tomorrow, and then Cindy cook the day after that.
In the second sample input, the condition already holds, so we don't need to use any extra days.
Here is a well-known trick question about Tagalog:
The answer is, of course, four, because in Tagalog, "ng" is considered to be a single "letter" (albeit written with two symbols)—that is, the letters are b-u-ng-a. So, for example, the word "pangngalan" has 8 letters.
Since Tagalog is so good, Alice wants to create a Tagalog 2. In Tagalog 2, she will choose two distinct consonants—let's write them as $$$xy$$$—such that this substring of two characters is counted as a single "letter" (each other character, as normal, counts as one letter). Given a string $$$s$$$, she must choose these consonants $$$x$$$ and $$$y$$$ such that the string $$$s$$$ is counted as having $$$k$$$ letters in Tagalog 2. If there are multiple possible answers, Alice wants the lexicographically smallest one (i.e. the one that would come earliest in the dictionary).
Please help Alice answer this question for all integers $$$k$$$ from $$$1$$$ to $$$|s|$$$ (the length of $$$s$$$). Good luck!
For the sake of this problem, y is always considered as a consonant.
Input consists of a single line containing the string $$$s$$$.
Output $$$|s|$$$ space-separated strings, the $$$k$$$th of which is the answer to the problem for that value of $$$k$$$:
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline \text{The string $s$ contains only lowercase letters.} \\ 1 \leq |s| \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{40} & |s| \leq 5 \\ \hline 2 & \mathbf{30} & |s| \leq 500 \\ \hline 3 & \mathbf{30} & |s| \leq 5\times 10^4 \\ \hline \end{array}\\
\end{align*}$$$$$$
bunga
NO NO NO ng bc
thwth
NO NO th hw bc
(Unimportant historical footnote): This quirk was decided on as a carryover from the fact that the velar nasal sound (represented in IPA notation as ŋ) is represented by its own standalone symbol ᜅ in the Baybayin script used in the pre-colonial Philippines, mostly in Luzon. The switch to the "ng" digraph happened during the time of Spanish colonization, when the Philippines adopted the Latin alphabet. And in fact, even then, there are records of Spanish documents representing the ŋ sound with the single symbol g̃ in their writings (think of ñ being used for the "ny-" sound) before the use of "ng" superseded it.
Here is a well-known joke among Jesuits:
A: At the Battle of Pamplona
A formation is an $$$r \times c$$$ grid with $$$m$$$ of its squares containing a soldier. The enemy can spend one cannonball to do the following:
You are given $$$r, c, m, k$$$. Construct any formation such that its resiliency is exactly equal to $$$k$$$ (or say if the task is impossible). Also, please answer $$$T$$$ different test cases per file.
The first line of input contains a single integer $$$T$$$. Then, the descriptions of each of the $$$T$$$ test cases follows.
Each test case is described by a single line containing the four space-separated integers $$$r, c, m, k$$$.
For each test case, if the task is possible, output a line containing the word YES. Otherwise, output NO.
If YES, also output an $$$r \times c$$$ grid—that is, output $$$r$$$ lines, each containing a string of $$$c$$$ characters. The grid should consist only of . and # characters, representing empty space and squares with soldiers, respectively—you are reminded that exactly $$$m$$$ of these characters should be #
If there are multiple possible solutions, any will be accepted.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 0 \leq T \leq 1500 \\ 1 \leq r, c \leq 25 \\ 1 \leq m \leq rc \\ 1 \leq k \leq 10^9 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{40} & m=k \\ \hline 2 & \mathbf{30} & m=2k \\ \hline 3 & \mathbf{20} & m=3 \\ \hline 4 & \mathbf{10} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
2 7 8 11 4 9 6 2 10
YES ........ ...#.... #..#...# #....#.# ...##.#. ........ ...#.... NO
In the first test case, you can verify that the soldiers can all be cleared with $$$4$$$ moves—select the third, fourth, and fifth rows from the top, and also select the fourth column from the left. Since you can't do it in $$$3$$$ moves, we conclude that the resiliency is $$$k=4$$$.
In the second test case, the task is impossible.
Cindy has been playing the new Pokemon game, and she's having a great time! Her team consists of five Dragon-type Pokemon (because she thinks they look awesome!), as well as her favorite Pokemon Magumaggu (the Lava Pokemon), the pre-evolution of Magcargo.
The latest entry in the Pokemon franchise contains several cooking minigames, where Cindy can prepare meals for her Pokemon to eat. In one cooking minigame, there are $$$n$$$ almonds, labeled $$$1$$$ to $$$n$$$, which her Magumaggu must roast. The $$$i$$$th almond must be roasted at least $$$a_i$$$ times. At the start of the minigame, the almonds are placed in a row in some random order. In one breath, Magumaggu can do the following:
The first line of input contains a the two space-separated integers $$$n$$$ and $$$k$$$.
The second line of input contains $$$n$$$ space-separated integers $$$a_1, a_2, a_3, \dots, a_n$$$.
Output a single line containing a permutation of the integers from $$$1$$$ to $$$n$$$ (separated by spaces), corresponding to a worst-case order in which the almonds should be placed (from left to right). If there are multiple possible solutions, any will be accepted.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \leq k \leq n \leq 2 \times 10^5 \\ \text{$1 \leq a_i \leq 10^9$ for each $i$.} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{40} & n \leq 5 \\ \hline 2 & \mathbf{40} & \text{$a_i \leq 2$ for each $i$} \\ \hline 3 & \mathbf{5} & \text{$a_i \leq 2023$ for each $i$} \\ \hline 4 & \mathbf{15} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
5 3 7 77 2 22 222
5 4 3 2 1
For the sample test case, the proposed solution would have the almonds' values in the order $$$[222, 22, 2, 77, 7]$$$.
(Translator's Note): Magumaggu is only a transliteration of the Japanese name of the pre-evolution of Magcargo.
It is the end of the year 2023. Alice still shouts AMOGUS at the top of her lungs. She believes it to be the funniest joke ever created in all of human history. She has even purchased an inflatable Amogus costume, which she will treasure for years to come. Truly, Amogus is eternal.
The Earth's greatest scientists have designed a new mod of the game, which introduces an interesting twist to the mechanics. Alice has been hired as one of their playtesters, and her job is to determine whether or not this mod is actually fun.
The judge first outputs a single integer $$$k$$$, the number of emergency meetings. For this problem, $$$k=18$$$ always.
Next, you should output a single integer $$$n$$$, the number of players you wish to invite to your lobby; this $$$n$$$ should be at least $$$2$$$ and at most $$$5 \times 10^4$$$. In general, the higher this $$$n$$$, the better your score will be. The players are indexed from $$$1$$$ to $$$n$$$.
The following interaction then plays out up to $$$k$$$ times:
In this problem, the judge is adaptive! Basically, the judge is designed so that it is impossible for your program to "get lucky" and succeed by sheer coincidence. The judge will always trigger the "unluckiest" worst case scenario for your algorithm, and will only Accept your solution if your algorithm works 100% of the time, no matter what. You may refer to the Notes section for a bit more detail.
If your solution is incorrect, you get $$$0$$$ points. If correct, you are awarded points based on the size of $$$n$$$ outputted in the successful attempt. $$$$$$\begin{align*}
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{35} & n \geq 18 \\ \hline 2 & \mathbf{15} & n \geq 30 \\ \hline 3 & \mathbf{10} & n \geq 80 \\ \hline 4 & \mathbf{26} & n \geq 500 \\ \hline 5 & \mathbf{6} & n \geq 700 \\ \hline 6 & \mathbf{8} & n \geq 48000 \\ \hline \end{array}\\
\end{align*}$$$$$$
Here is how the adaptive judge decides on how to act. Basically, the judge does not actually select the witness and imposter in advance. The adaptive judge will try to respond with SILENCE... whenever possible, so long as it "maintains plausible deniability", i.e. so long as there still exists any selection of witness and imposter that is consistent with all its responses so far. Informally, the judge is a cheater, but will never let itself get caught (and will give you the win if you manage to checkmate it).
Here is a sample interaction:
Here, the solution claims to be able to find the witness and imposter among a lobby with $$$4$$$ players. Note that once the game has been won, the rest of the rounds don't play out any more.
Judge Contestant
18
4
2
1 2
SILENCE...
3
1 3 4
SILENCE...
2
2 3
SILENCE...
1
4
4 REPORTS 1
For a Media Studies presentation on the history of telecommunication, Alice is going to use her skill in electronics to re-create the five-needle telegraph design. Unlike other communication systems, like the famous Morse telegraph system that succeeded it, the five-needle telegraph had the advantage of not requiring specialist training in order for its operators to send and receive messages.
Alice wants to create a generalized version, so we will actually describe the construction of an $$$n$$$-needle telegraph. Consider a square with $$$n$$$ rows and $$$n$$$ columns which has been rotated $$$45^\circ$$$, such that it now has $$$2n-1$$$ rows—so its first row contains $$$1$$$ entry, its second row contains $$$2$$$ entries, and so on, up until its $$$n$$$th row which contains $$$n$$$ entries; then, the $$$(n+1)$$$th row contains $$$n-1$$$ entries, the $$$(n+2)$$$th row contains $$$n-2$$$ entries, and so on, up until its final row has $$$1$$$ entry again.
The $$$n$$$th row contains a needle in each entry; each other square contains a single letter in each entry. You may refer to this diagram, taken from the Wikipedia page, for an $$$n$$$-needle telegraph with $$$n=5$$$.
Credits to user Dder Each needle can be in one of $$$3$$$ states: it can be pointed vertically (its default state), it may be rotated $$$45^\circ$$$ counterclockwise (west of north), or it may be rotated $$$45^\circ$$$ clockwise (east of north). A valid message consists of choosing exactly two needles and rotating them in opposite directions (all other needles remain in the default state). The value of this message is equal to the letter that both rotated needles are pointing at. In the above diagram, the third needle has rotated $$$45^\circ$$$ clockwise, and the fifth needle has rotated $$$45^\circ$$$ counterclockwise, and so they point at the letter G
For this problem, you will be given the $$$n(n-1)$$$ letters on Alice's design of her telegraph, as well as $$$m$$$ needle configurations that correspond to valid messages. Please decode Alice's message!
Input begins with a single line containing the integers and $$$n$$$ and $$$m$$$.
Then, $$$n-1$$$ lines of input follow, containing strings with $$$1, 2, 3, \dots, n-1$$$ letters each, respectively, corresponding to the letters in the first $$$n-1$$$ rows of the telegraph.
Then, $$$n-1$$$ lines of input follow, containing strings with $$$n-1, n-2, n-3, \dots, 1$$$ letters each, respectively, corresponding to the letters in the final $$$n-1$$$ rows of the telegraph.
Note that in general, the same letter may appear in multiple places in the telegraph.
Finally, $$$m$$$ lines of input follow, each containing a string of length $$$n$$$, describing Alice's messages in order. Exactly one character will be \ to represent the needle rotated $$$45^\circ$$$ counterclockwise, and exactly one other character will be / to represent the needle rotated $$$45^\circ$$$ clockwise; all other characters in each string are | to represent needles in their default state.
Output a single line containing a string of length $$$m$$$, where the $$$i$$$th character of this string corresponds to the letter pointed at by the needles in the $$$i$$$th of Alice's messages.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 2 \leq n \leq 20 \\ 1 \leq m \leq 400 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{50} & n \leq 5 \\ \hline 2 & \mathbf{30} & \text{All needle configurations point to a letter in the top half.} \\ \hline 3 & \mathbf{20} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
5 16 A BD EFG HIKL MNOP RST VW Y |\/|| ||\/| |/\|| |||\/ /\||| /|||\ /||\| /|||\ ||/\| ||\/| |/||\ /|||\ |||/\ ||\/| |\/|| ||/|\
NOIPHABAKODALONG
The code ||/|\ corresponds to the needle configuration from the diagram in the problem statement.
This is an interactive problem.
Cindy is playing a so-called "Kaizo" ROMHack of Pokémon Crystal, meaning that fans had modified the game to massively increase the difficulty to infuriating (unfair?) levels. For some modders, this can include not just the Pokémon battles, but also the overworld puzzles.
The Ghost Gym in Ecruteak city has a puzzle which goes as follows (slightly modified for simplicity).
Of course, the "maze" in the base game is very simple, but the Kaizo modders have gone out of their way to make their maze as painful as possible. Cindy has been attempting this for hours and is starting to get tilted. She asks you if it's possible to develop a program that can solve this problem for her.
The judge first outputs two space-separated integers $$$r$$$ and $$$c$$$, the dimensions of the grid.
Then, you can now move around the grid. You can make statements to the judge:
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 2 \leq r, c \leq 20 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{35} & r = c = 2 \\ \hline 2 & \mathbf{20} & r, c \leq 5 \\ \hline 3 & \mathbf{20} & \text{It is possible, and all }\mathtt{OKAY}\text{ squares lie on \\ the unique shortest path from start to finish.} \\ \hline 2 & \mathbf{25} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
Here is a sample interaction. We also provide the map, with safe squares colored lilac, and traps colored a deep indigo. The interaction corresponds to the following steps on the map—stepping on a trap (and being sent back to the start) is represented by the red exclamation point. We remind you that the contestant does not have access to this map—it's only provided to you here to help understand the sample.
Here is another sample interaction. Here, the map is not solvable, so the contestant is correct for saying the game is RIGGED
Judge Contestant
4 6
S
SAFE
S
TRAP
S
SAFE
E
SAFE
E
SAFE
E
TRAP
S
SAFE
E
SAFE
E
SAFE
N
SAFE
E
SAFE
E
SAFE
E
SAFE
S
SAFE
S
SAFE
S
YAY
Judge Contestant
3 3
S
TRAP
E
TRAP
RIGGED
Puno ang langit ng bituin
At kay lamig pa ng hangin
Sa 'yong tingin ako'y nababaliw giliw
At sa awitin kong ito
Sana'y maibigan mo
Ibubuhos ko ang buong puso ko...
Tonight, Bob has decided that he is going to serenade Cindy with a traditional harana outside her bedroom. Let's ignore the fact that Cindy lives on the 12th floor of a condo—he'll figure out the logistics later. For now, he needs to focus on his singing!
We can massively simplify and describe each note as a single integer, and so describe a song as a sequence of integers (Chord her? I barely know her!) Bob's song consists of the $$$n$$$ notes $$$s_1, s_2, \dots, s_n$$$, and by his practice, the best he can do is sing the notes $$$b_1, b_2, \dots, b_n$$$.
The off-key-ness of his singing is calculated as the sum of the absolute difference between each of his notes and the corresponding note in the song. In symbols: $$$$$$ \text{off-key-ness} = \sum_{i=1}^n |b_i - s_i|. $$$$$$ Bob has a sneaky trick he can do. Instead of fixing his singing, he can just change the key of the backing music! Right now, it is in key $$$0$$$. If a part is to be sung in key $$$k$$$, we add $$$k$$$ to the $$$s_i$$$ of all notes in that part (this $$$k$$$ can be negative, but it must be an integer).
Also, Bob wants to do a key shift at some note $$$m$$$, meaning he will sing notes $$$1$$$ to $$$m$$$ in key $$$k_1$$$, and then sing notes $$$m+1$$$ to $$$n$$$ in key $$$k_2$$$. Note that it is allowed to have $$$k_1 = k_2$$$, if you determine that it would be optimal.
For each $$$m$$$ from $$$1$$$ to $$$n-1$$$: Determine the minimum off-key-ness of Bob's singing if the key shift happens at note $$$m$$$, and the two keys ($$$k_1$$$ and $$$k_2$$$) are chosen optimally.
The first line of input contains a single integer $$$n$$$.
The second line of input contains the $$$n$$$ space-separated integers $$$s_1, s_2, \dots, s_n$$$.
The third line of input contains the $$$n$$$ space-separated integers $$$b_1, b_2, \dots, b_n$$$.
Output a single line containing $$$n-1$$$ space-separated integers, the $$$m$$$th of which is the minimum off-key-ness if the key shift happens at note $$$m$$$.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 2 \leq n \leq 2 \times 10^5 \\ -10^9 \leq s_i, b_i \leq 10^9 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{50} & \text{$0 \leq s_i, b_i \lt 8$ and $n \leq 1000$} \\ \hline 2 & \mathbf{20} & 0 \leq s_i, b_i \lt 8 \\ \hline 3 & \mathbf{20} & n \leq 1000 \\ \hline 4 & \mathbf{10} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
4 7 2 2 7 5 1 0 6
1 2 1
For the sample input, let's consider what to do when the key change is at note $$$m=1$$$. Here is an optimal series of steps.
We get minimal off-key-ness answers of $$$2$$$ and $$$1$$$ for the remaining values of $$$m$$$.
Alice, Bob, and Cindy are having a blast playing the hot new game Injurious Company, an indie horror survival game where players assume the role of underpaid laborers who must persevere through ludicrously unsafe working conditions just to earn scraps for their day's wage (maybe the real horror is capitalism).
The gang are located at position $$$(x, y)$$$ (using the usual Cartesian coordinate system) and must return back to their ship, located at the origin $$$(0, 0)$$$. But they have to move strategically in order to dodge the monsters that are coming after them! The strategy guide describes a winning strategy according to $$$n$$$ pieces of information, each described by an integer $$$K_i$$$ and a direction $$$dir_i$$$ (each of which is H or V). This means that on their $$$i$$$th move they choose a direction $$$d_i$$$ and a number of steps $$$k_i$$$—then, they head $$$k_i$$$ steps in the direction of $$$d_i$$$. Their choice is subject to the following restrictions:
Determine if it is possible for them to return to their ship alive, and if so, provide a series of moves that they can take. Also, please answer $$$T$$$ different test cases per file.
The first line of input contains a single integer $$$T$$$. Then, the descriptions of each of the $$$T$$$ test cases follows.
The first line of each test case contains the three space-separated integers $$$n$$$, $$$x$$$, and $$$y$$$.
Then, $$$n$$$ lines follow, each containing two space-separated values: the integer $$$K_i$$$, and the direction $$$dir_i$$$.
For each test case, if the task is possible, output a line containing the word YES. Otherwise, output NO.
If YES, also output $$$n$$$ lines containing the moves that should be made. Each line should contain two space separated values: the number of steps $$$k_i$$$, and the direction $$$d_i$$$.
If there are multiple possible answers, any will be accepted as long as they respect the strategy guide and return the gang to the ship.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \leq T \\ 1 \leq n \\ \text{The sum of $n$ across all test cases is $\leq 2 \times 10^5$.} \\ |x|, |y| \leq 10^{15} \\ \text{$1 \leq K_i \leq 10^9$ for each $i$} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{30} & n \leq 2 \\ \hline 2 & \mathbf{20} & n \leq 3 \\ \hline 3 & \mathbf{20} & \text{$n \leq 15$ and $T \leq 50$} \\ \hline 4 & \mathbf{30} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
2 3 -3 2 1 H 3 V 4 H 2 -100 -100 3 H 3 V
YES 1 E 2 S 2 E NO
These sample images correspond to the first of the test cases in the sample input.
Alice noticed this trend in some contest problems where they add "flavor" to a pure mathematical statement by introducing some formal abstract arbitrary property and then binding it to an adjective that has absolutely nothing to do with that definition. These problems are usually then titled "adjective + mathematical object". For example, "beautiful numbers", "interesting sequences", and the classic "good colorings". As an aspiring problem setter, Alice wishes to partake in this tradition.
A $$$k$$$-jolly divisor of $$$n$$$ is some positive integer $$$d$$$ such that $$$n$$$ is divisible by $$$d$$$ and by $$$d^k$$$. For example, $$$4$$$ is a $$$3$$$-jolly divisor of $$$960$$$, since both $$$4$$$ and $$$4^3 = 64$$$ divide $$$960$$$. We can show that $$$4$$$ is the largest $$$3$$$-jolly divisor of $$$960$$$.
Given $$$N$$$ and $$$k$$$, find the sum of the largest $$$k$$$-jolly divisors of $$$n$$$ across all $$$n$$$ from $$$1$$$ to $$$N$$$.
Python users are advised to submit to PyPy for this problem.
Input consists of a single line with the two space-separated integers $$$N$$$ and $$$k$$$.
Output a line containing a single integer, the answer.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 2 \leq k \leq 10^9 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{30} & 1 \leq n \leq 10^3 \\ \hline 2 & \mathbf{30} & 1 \leq n \leq 10^5 \\ \hline 3 & \mathbf{30} & 1 \leq n \leq 10^6 \\ \hline 4 & \mathbf{10} & 1 \leq n \leq 5 \times 10^7 \\ \hline \end{array}\\
\end{align*}$$$$$$
12 2
17
12345678 3
16854689
Cindy is helping her dojo with the logistics of their upcoming promotion exam.
There is a queue of $$$n$$$ students, each ready to take the exam. Cindy will then hire $$$k$$$ instructors as the ones who will administer the promotion exam. The $$$i$$$th person from the front of the queue takes $$$a_i$$$ seconds to complete their test (pass or fail) under an instructor, and each instructor can only administer the test to one student at a time.
The process is as follows. The person in front of the queue looks around for any free instructors; if they see one, they go up to that instructor and start their test with them. If there are many that are free, one is chosen arbitrarily (the time spent walking to each instructor is negligible). If no instructor is free, the student at the front of the queue (and thus, everyone else behind them) waits until one is free.
Is it possible to finish all tests in at most $$$T$$$ seconds? If yes, what is the smallest $$$k$$$ (the number of instructors to hire) needed in order to achieve this goal? Also, please answer $$$t$$$ different test cases per file.
The first line of each test case contains $$$t$$$, the number of test cases. The descriptions of $$$t$$$ test cases follow.
The first line of each test case contains two space-separated integers $$$n$$$ and $$$T$$$.
The second line of each test case contains the $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$, the finishing times in order of the front of the queue to the back.
For each test case:
Here, $$$N$$$ denotes the sum of $$$n$$$s in a single test file.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \le t \le 500 \\ 1 \leq n \\ 1 \leq T, a_i \leq 10^{16} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{25} & \text{$n \leq 3$, $N \leq 1500$} \\ \hline 2 & \mathbf{15} & \text{$n \leq 75$, $N \leq 1500$} \\ \hline 3 & \mathbf{20} & \text{$n \leq 500$, $N \leq 2000$} \\ \hline 4 & \mathbf{20} & \text{$n \leq 2000$, $N \leq 6000$} \\ \hline 5 & \mathbf{20} & \text{$n \leq 150000$, $N \leq 450000$} \\ \hline \end{array}\\
\end{align*}$$$$$$
1 7 16 10 4 6 8 6 4 3
YES 3
Fingers on buzzers teams, it's time for the Missing Vowels Round. In this game, we've taken famous words, phrases, or sayings, removed the vowels, and then re-spaced the consonants.
So for example, for the category "Sports for nerds," the clue might be,
Alice, Bob, and Cindy are training for their appearance on Only Connect (their team name is "The Github Heatmappers"), and in particular they would like to train for the Missing Vowels Round. They ask for your help in creating a program that allows them to train.
As a formalization of the rules given above, in the Missing Vowels Round, the following transformation is applied to a string:
The first line of input contains the string $$$s$$$, which may contain whitespaces.
The second line of input contains a single integer $$$i$$$.
If $$$\mathcal{L}(s)$$$ has fewer than $$$i$$$ elements, output the phrase "out of bounds" (without the quotes; note it is in all-lowercase), Otherwise, output the $$$i$$$th element in $$$\mathcal{L}(s)$$$.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \leq i \leq 10^{18} \\ 1 \leq |s| \leq 2 \times 10^5 \\ \text{$s$ consists of upper and lowercase letters, punctuation }\mathtt{,.!?}\text{ and spaces.} \\ \text{$s$ does not begin or end in a space, and it has no two consecutive spaces.} \\ \text{$s$ contains at least one consonant.} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{40} & |s| \leq 15 \\ \hline 2 & \mathbf{40} & i \leq 2 \times 10^5 \\ \hline 3 & \mathbf{20} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
NOI.PH 3
NP H
Alice, Bob, and Cindy 344
LC BB ND CNDY
Who Lives, Who Dies, Who Tells Your Story 1000000000000000000
out of bounds
!B 1
B
Comparison operators like < are actually defined on strings in almost all programming languages. Try it!
They are defined in a way consistent with "dictionary ordering". Suppose we have two strings $$$s$$$ and $$$t$$$ such that $$$s \neq t$$$.
So, for example, "LIL MAN" (without the quotes) comes before LILAC because the two strings first differ at their fourth character, and there, the space precedes A in ASCII ordering.
The motivating story and definition of a rectilinear path (and related terms) are the same in Mondridalgo (Verification) and (Optimization). Skip to the bolded text for the first section where the two differ.
Bob created a magnificent painting this year in the Mondridalgo style (a combination of Piet Mondrian's rectangles and Felix Hidalgo's neoclassicism), which both Alice and Cindy adore. Unfortunately, when Cindy asked him if she could keep the painting, he was too lovestruck and immediately said yes... forgetting that he had already previously promised the painting to Alice! Oh no! Remember everyone—don't be like Bob.
Unable to choose between his two friends, Bob decides the best way to resolve this situation is to cut up his painting into two contiguous pieces using a pair of scissors, and then hand one piece to Alice and the other Cindy. That way, each of his friends is equally unhappy.
We formalize "cutting with scissors" by defining a rectilinear path to be a non-empty sequence of "cuts" such that:
The first line of input contains a single integer $$$T$$$. Then, the descriptions of each of the $$$T$$$ test cases follows.
The first line of each test case contains the two space separated integers $$$r$$$ and $$$c$$$.
Then, an $$$r \times c$$$ grid follows—that is, $$$r$$$ lines follow, each containing a string of length $$$c$$$, each one A or C. The letter A means that this square should go to Alice, and the letter C means that this square should go to Cindy.
For each test case:
Let $$$A$$$ be the sum of $$$rc$$$ across all test files.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 1 \leq T \leq 100 \\ 2 \leq r, c \leq 400 \\ A \le 10^6 \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{20} & \text{$r = c = 2$} \\ && \text{$T \le 16$} \\ \hline 2 & \mathbf{20} & \text{$r = 2$} \\ && \text{$c \leq 50$} \\ \hline 3 & \mathbf{20} & \text{$r \leq 3$} \\ && \text{$c \leq 50$} \\ \hline 4 & \mathbf{30} & \text{$r, c \leq 50$} \\ && \text{$A \le 20000$} \\ \hline 5 & \mathbf{10} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
5 4 6 AAAAAA AAAAAA AAAAAA CCCCCC 4 6 CCCCCC CCCCCC AACCCC AACCCC 4 6 CCCCCC ACCCCC AAACCC AAACCC 5 5 AACCA AAACA ACCCA ACCAA AAAAA 3 3 AAA ACA CAA
YES 1 YES 2 YES 4 YES 9 NO
The first three test cases correspond to the examples illustrated in the problem statement.
The motivating story and definition of a rectilinear path (and related terms) are the same in Mondridalgo (Verification) and (Optimization). Skip to the bolded text for the first section where the two differ.
Bob created a magnificent painting this year in the Mondridalgo style (a combination of Piet Mondrian's rectangles and Felix Hidalgo's neoclassicism), which both Alice and Cindy adore. Unfortunately, when Cindy asked him if she could keep the painting, he was too lovestruck and immediately said yes... forgetting that he had already previously promised the painting to Alice! Oh no! Remember everyone—don't be like Bob.
Unable to choose between his two friends, Bob decides the best way to resolve this situation is to cut up his painting into two contiguous pieces using a pair of scissors, and then hand one piece to Alice and the other Cindy. That way, each of his friends is equally unhappy.
We formalize "cutting with scissors" by defining a rectilinear path to be a non-empty sequence of "cuts" such that:
Our goal is to try to find a partition which is not "lop-sided"—that is, neither one of Alice nor Cindy should be significantly happier than the other in this interaction. This partition also shouldn't be too complicated.
Formally, given an integer $$$k$$$, find any partition whose valid rectilinear path uses at least $$$1$$$ and at most $$$k$$$ cuts, and which minimizes the value $$$|\text{Alice's happiness} - \text{Cindy's happiness}|$$$ among such partitions.
The first line of input contains the three space-separated integers $$$r$$$ and $$$c$$$ and $$$k$$$.
Then, an $$$r \times c$$$ grid follows, describing the Alice adoration ratings—that is, $$$r$$$ lines follow, each containing $$$c$$$ integers: $$$$$$ \begin{array}{cccc} u_{1, 1} & u_{1, 2} & \dots & u_{1, c} \\ u_{2, 1} & u_{2, 2} & \dots & u_{2, c} \\ \vdots & \vdots & \ddots & \vdots \\ u_{r, 1} & u_{r, 2} & \dots & u_{r, c} \end{array} $$$$$$ where $$$u_{i, j}$$$ is the Alice adoration rating of the square in the $$$i$$$th row from the top and $$$j$$$th column from the left.
Then, another $$$r \times c$$$ grid follows, describing the Cindy cherish ratings—that is, $$$r$$$ lines follow, each containing $$$c$$$ integers: $$$$$$ \begin{array}{cccc} v_{1, 1} & v_{1, 2} & \dots & v_{1, c} \\ v_{2, 1} & v_{2, 2} & \dots & v_{2, c} \\ \vdots & \vdots & \ddots & \vdots \\ v_{r, 1} & v_{r, 2} & \dots & v_{r, c} \end{array} $$$$$$ where $$$v_{i, j}$$$ is the Cindy cherish rating of the square in the $$$i$$$th row from the top and $$$j$$$th column from the left.
Output a single positive integer—the minimal value of $$$|\text{Alice's happiness} - \text{Cindy's happiness}|$$$.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 2 \leq r, c \leq 6 \\ 1 \leq k \leq 6 \\ \text{$-10^9 \leq u_{i, j}, v_{i, j} \leq 10^9$ for each $i, j$} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{20} & k=1 \\ \hline 2 & \mathbf{30} & k \leq 2 \\ \hline 3 & \mathbf{20} & r, c \leq 3 \\ \hline 4 & \mathbf{20} & r, c \leq 4 \\ \hline 5 & \mathbf{10} & \text{No further constraints.} \\ \hline \end{array}\\
\end{align*}$$$$$$
4 5 1 20 -8 11 4 0 -7 -5 12 9 -2 12 12 -9 5 -2 11 10 12 1 -2 -9 -6 -9 -2 9 15 22 -5 -6 9 -1 21 -5 10 9 -1 29 -5 10 9
10
4 5 2 20 -8 11 4 0 -7 -5 12 9 -2 12 12 -9 5 -2 11 10 12 1 -2 -9 -6 -9 -2 9 15 22 -5 -6 9 -1 21 -5 10 9 -1 29 -5 10 9
1
4 5 5 20 -8 11 4 0 -7 -5 12 9 -2 12 12 -9 5 -2 11 10 12 1 -2 -9 -6 -9 -2 9 15 22 -5 -6 9 -1 21 -5 10 9 -1 29 -5 10 9
0
4 5 6 20 -8 11 4 0 -7 -5 12 9 -2 12 12 -9 5 -2 11 10 12 1 -2 -9 -6 -9 -2 9 15 22 -5 -6 9 -1 21 -5 10 9 -1 29 -5 10 9
0
Here are the corresponding partitions for the first three sample inputs.
Alice, Bob, and Cindy are learning networking in the computer club! Each of them started with five computers; each computer has a unique name to identify it. Cables can be used to directly connect two different computers; each cable is two-way. A collection of computers and cables is called a network. Their networks are originally configured in the following shapes (for privacy reasons, we've hidden the computers' names).
They decide to give you a little puzzle. They'll give you the setup of a computer network. Whose is it! The answer could be even "none of them", and you also need to be able to identify if this is the case. Also, please answer $$$T$$$ different test cases per file.
The first line of input contains a single integer $$$T$$$. Then, the descriptions of each of the $$$T$$$ test cases follows.
The first line of each test case contains two space-separated integers $$$n$$$ and $$$m$$$.
The second line of each test case contains $$$n$$$ space-separated strings, the names of the computers in the presented network.
Then, $$$m$$$ lines follow, each containing two space-separated strings. These strings are names of computers, and it means, "There exists a cable that connects these two computers"
For each test cases, output the answer to that test case:
Consider the set of all people (among Alice and Bob and Cindy) such that it is possible for this person to have been the owner of the presented network, i.e. the set of all names that can fill in the blank in: "It is possible that the owner of this network is _____". Output a line containing their space-separated names, sorted in lexicographic (dictionary) order.
If none of them could possibly be the owner of the presented network, output PRANKED instead.
Here, $$$N$$$ denotes the sum of $$$n$$$s in a single test file, and $$$M$$$ the sum of $$$m$$$s in a single test file.
$$$$$$\begin{align*}
&\begin{array}{|l|} \hline \text{Constraints For All Subtasks} \\ \hline 0 \leq T \\ 1 \leq n \leq 2 \times 10^5 \\ N \leq 2 \times 10^5 \\ 0 \leq m \leq 2 \times 10^5 \\ M \leq 2 \times 10^5 \\ \text{Each computer's name is distinct, and consists} \\ \text{of at most $5$ upper and lowercase letters.} \\ \text{No cable connects a computer to itself.} \\ \text{At most one cable connects any pair of computers.} \\ \hline \end{array}\\
&\begin{array}{|c|c|l|} \hline \text{Subtask} & \text{Points} & \text{Constraints} \\ \hline 1 & \mathbf{20} & \text{Someone owns each network.} \\ \hline 2 & \mathbf{20} & \text{Neither Alice nor Bob own each network.} \\ \hline 3 & \mathbf{20} & \text{Neither Alice nor Cindy own each network.} \\ \hline 4 & \mathbf{20} & \text{Neither Bob nor Cindy own each network.} \\ \hline 5 & \mathbf{20} & \text{No further constraints} \\ \hline \end{array}\\
\end{align*}$$$$$$
3 6 6 CompA CompB CompC CompD CompE CompF CompA CompB CompA CompC CompC CompD CompB CompD CompB CompE CompD CompF 7 7 CompA CompB CompC CompD CompE CompF CompG CompA CompB CompB CompC CompC CompD CompD CompE CompE CompA CompD CompF CompD CompG 8 7 CompA CompB CompC CompD CompE CompF CompG CompH CompA CompH CompB CompH CompB CompG CompC CompG CompC CompF CompD CompF CompD CompE
Alice PRANKED Cindy
Here are computer networks in the sample test cases: