Recently Added DMOJ Problemshttps://dmoj.ca/2018-10-16T04:04:53+00:00The latest problems added on the DMOJ: Modern Online Judge websiteAnother Contest 1 Problem 3 - Poutine2018-10-16T04:04:53+00:002018-10-16T04:04:53+00:00https://dmoj.ca/problem/acc1p3<div><p>Fast Fingers Thomas is eating poutine at Wilson's restaurant. Thomas has \(T\) dollars, and an order of poutine at Wilson's restaurant costs one dollar. Consequently, Thomas can place at most \(T\) orders of poutine.</p>
<p>There are \(N\) different types of poutine that Thomas can order. If Thomas orders poutine \(i\) for the first time, he gains \(a_i\) units of happiness.
If Thomas orders poutine \(i\) for the \(k\)th time, he gains \(\max(0, a_i - (k-1)b_i)\) units of happiness. Wils...Another Contest 1 Problem 2 - Graphs2018-10-16T04:04:27+00:002018-10-16T04:04:27+00:00https://dmoj.ca/problem/acc1p2<div><p>This problem has a simple statement.</p>
<p><code>Given an undirected, unweighted graph of N vertices and M edges, and Q pairs of vertices, compute the distance between each pair of vertices.</code></p>
<p>We ran out of time trying to set strong test data for the problem though, so we did it randomly. Here's how we generated our test data.</p>
<ul>
<li>We picked values for \(N\), \(M\), and \(Q\). The vertices are numbered from \(1\) to \(N\).</li>
<li>We generated, uniformly at random, ...Another Contest 1 Problem 1 - Binary String Operations2018-10-16T04:03:41+00:002018-10-16T04:03:41+00:00https://dmoj.ca/problem/acc1p1<div><p>Given a binary string, support the following two operations:</p>
<p><code>Update(i, l)</code> - take the substring starting at index <code>i</code> of length <code>l</code> within the binary string and reverse it. The reverse of string <code>0001</code> is <code>1000</code>. Given the string <code>0001</code>, <code>Update(1, 3)</code> changes the string to <code>0100</code>.</p>
<p><code>Query(i, l)</code> - take the substring starting at index <code>i</code> of length <code>l</code> wi...DMOPC '18 Contest 2 P6 - Standing Ovation2018-10-09T13:08:22+00:002018-10-09T13:08:22+00:00https://dmoj.ca/problem/dmopc18c2p6<div><p>At the Nova Theatre, the balcony seats can be seen as a grid with \(M\) rows and \(N\) columns. The theatre is packed and the seats are all filled. At the end of the play, \(K\) people in the balcony stand to give their applause. The \(i^{\text{th}}\) of these \(K\) people is sitting in row \(r_i\), column \(c_i\). The rest of the \(M\times N\) people will only stand if at least two people adjacent to them are standing. How many people will end up standing?</p>
<h4>Constraints</h4>
<p>\(...DMOPC '18 Contest 2 P3 - Thanksgiving Feast2018-10-08T05:37:02+00:002018-10-08T05:37:02+00:00https://dmoj.ca/problem/dmopc18c2p3<div><p>Mimi is attending a Thanksgiving feast! She lives in a town with \(N\) buildings numbered from \(1\) to \(N\) and \(M\) unweighted bidirectional roads connecting them. The \(i^{\text{th}}\) road connects buildings \(a_i\) and \(b_i\). Mimi is a good guest, so she wants to bring a gift for the host. However, Mimi is also a procrastinator! The Thanksgiving feast is soon and she hasn't bought a gift yet. There are \(K\) buildings \(s_1, s_2, \ldots, s_K\) which sell gifts. Mimi is currently...DMOPC '18 Contest 2 P4 - Damage Output2018-10-08T04:55:51+00:002018-10-08T04:55:51+00:00https://dmoj.ca/problem/dmopc18c2p4<div><p>Mimi is playing more Enur Yrotcaf 4, when she realizes that her damage output is...subpar.</p>
<p>Being a meticulous player, she has tracked her damage output over the last \(N\) seconds, and decides to take a contiguous subsection where her damage output is at least \(M\).</p>
<p>Wanting to show off to her friends, she wants this interval to be as short as possible. Can you help her find the length of the smallest interval where she deals at least \(M\) damage?</p>
<h4>Constraints</h4>
...DMOPC '18 Contest 2 P5 - Another Sequence Problem2018-10-08T01:47:49+00:002018-10-08T01:47:49+00:00https://dmoj.ca/problem/dmopc18c2p5<div><p>Bob is investigating properties of integer sequences in an attempt to solve George's least favourite problem: <a href="https://dmoj.ca/problem/seq2">Maintaining A Sequence</a>!</p>
<p>To help Bob achieve his dreams, George gives Bob a warm up problem:</p>
<blockquote><p>How many ordered sequences of \(N\) non-negative integers are such that each element is a member of the set \({a_1, a_2, \ldots a_K}\) and whose sum is at most \(M\)?</p>
</blockquote>
<p>Bob points out that this number m...Summing A Sequence2018-10-08T00:57:04+00:002018-10-08T00:57:04+00:00https://dmoj.ca/problem/seq0<div><p>Bob is trying to solve [user:Kirito]'s favourite problem, <a href="https://dmoj.ca/problem/seq2">Maintaining a Sequence</a>! He decides that he must first explore some properties of integer sequences in order to solve it. Bob has a sequence \(a\), consisting of \(N\) integers. He wants to add some of the elements together to obtain the maximum sum possible. However, to make this problem more challenging, Bob decides that he will not add two consecutive elements to his total. In other wor...DMOPC '18 Contest 2 P2 - Booster Cushions2018-10-06T17:42:50+00:002018-10-06T17:42:50+00:00https://dmoj.ca/problem/dmopc18c2p2<div><p>At the Nova Theatre, the balcony seats can be seen as a grid with \(M\) rows and \(N\) columns. The plays are popular and \(K\) people have bought tickets to see the next one. However, these tickets do not have set seats yet. Administration has decided to start selling booster cushions and will be rearranging people's seats to maximize their profit. In particular, an audience member can only see the play if their height is strictly more than the person in the seat directly in front. Othe...DMOPC '18 Contest 2 P1 - Pumpkin Patches2018-10-06T16:43:48+00:002018-10-06T16:43:48+00:00https://dmoj.ca/problem/dmopc18c2p1<div><p>Roger is getting ready for his final<sup>1</sup> Halloween of high school!</p>
<p>To celebrate, he goes to the land of Cartesia with Robert to grow \(P\) pumpkins. The \(i^{\text{th}}\) pumpkin is at point \((x_i, y_i)\).</p>
<p>Unfortunately, the Pumpkin King of Cartesia has demanded that he surround his field of pumpkins with an axis-aligned rectangular fence first. Given that Roger is very poor, can you determine the minimum length of fencing he needs to enclose all his pumpkins?</p>
...DMOPC '18 Contest 2 P0 - Mimi and Video Games2018-10-06T16:30:46+00:002018-10-06T16:30:46+00:00https://dmoj.ca/problem/dmopc18c2p0<div><p>Mimi is playing her favourite video game, Enur Yrotcaf 4.</p>
<p>In this game, you own an \(N \times N\) field, and can water an \(i \times i\) square of plants at the cost of \(\alpha \times i\) EP (Enur Points).</p>
<p>Given that Mimi has \(R\) EP, what is the largest square of plants that she can water?</p>
<h4>Constraints</h4>
<p>\(1 \leq N, \alpha, R \leq 1\,000\,000\,000\)</p>
<h4>Input Specification</h4>
<p>The only line of input will have 3 space-separated integers, \(N\), \(\alp...4Ever2018-09-29T00:17:24+00:002018-09-29T00:17:24+00:00https://dmoj.ca/problem/4ever<div><p>Raymond is good at sequences. He has made a puzzle that no one in his class could solve. It involves taking a number, finding the number of letters it has, then making this number the new number, and doing this over and over again to form a sequence. Raymond found that he would always end up repeating forever at the number \(4\), because it has 4 letters, <code>four</code>. He showed some sample sequences to get \(4\), but none of his classmates could solve the puzzle. He is exhausted fr...A Minus B2018-09-27T13:07:34+00:002018-09-27T13:07:34+00:00https://dmoj.ca/problem/aminusb<div><p>Tudor's math classmate, Raymond, is also on his laptop. He is not paying attention either. The math teacher is starting to get mad and makes them do some simple (not for them) subtraction problems. Neither of them know how to, and they need you to help them out.</p>
<h4>Input Specification</h4>
<p>The first line will contain an integer \(N\) \((1 \le N \le 10\ 000)\), the number of subtraction problems Tudor and Raymond need to do. The next \(N\) lines will each contain two space-separat...IOI '18 P6 - Meetings2018-09-25T04:06:44+00:002018-09-25T04:06:44+00:00https://dmoj.ca/problem/ioi18p6<div><p>There are \(N\) mountains lying in a horizontal row, numbered from through from
left to right. The height of the mountain \(i\) is \(H_i\) \((0 \leq i \leq N -1)\). Exactly one person lives on the top of each mountain.</p>
<p>You are going to hold \(Q\) meetings, numbered from \(0\) through \(Q-1\). The meeting \(j\) (\(0 \leq j \leq Q-1\)) will be attended by all the people living on the mountains from \(L_j\) to \(R_j\), inclusive \((0 \leq L_j \leq R_j \leq N-1)\). For this meeting, y...DMOPC '18 Contest 1 P5 - Sorting2018-09-12T16:11:07+00:002018-09-12T16:11:07+00:00https://dmoj.ca/problem/dmopc18c1p5<div><p>You are considering a <strong>permutation</strong> \(P\) of \(0\) to \(N-1\) and a non-negative integer \(C\). The elements at indices \(i\) and \(j\) may be swapped only if \(P_i \oplus P_j \le C\) where \(A\oplus B\) denotes the XOR of \(A\) and \(B\). However, \(C\) has not yet been decided. What is the smallest possible non-negative integer \(C\) so that this permutation may be sorted from least to greatest?</p>
<p>To make this more interesting, the permutation will be updated. You a...Back To School '18: Function Maximization2018-09-10T23:00:10+00:002018-09-10T23:00:10+00:00https://dmoj.ca/problem/bts18p8<div><p>Evan somehow found an array, \(a\), consisting of \(N\) integers in the range \([K, K+5\ 000]\) on the ground. Looking at it, he came up with a problem. However, he has no clue how to solve it. After asking all his friends, no one knew how to solve it, so he comes to you, asking for help.</p>
<p>Evan gives you the following function:</p>
<p>\[
f(x) = \begin{cases} x & \text{if }(x-1)!+1 \equiv 0 \pmod x\\ -1 & \text{if } (x-1)!+1 \not\equiv 0 \pmod x \end{cases}
\]</p>
<p>where \...Back To School '18: Trucking Troubles II2018-09-10T23:00:04+00:002018-09-10T23:00:04+00:00https://dmoj.ca/problem/bts18p7<div><p>Yi is one of many hardworking truck drivers in a mysterious land. In this mysterious land, there are \(N\) villages connected by \(N-1\) two-way roads. His job, like many others, is to transport mysterious substances from one village to another through these roads. Each village can travel to any other village using these roads. At each village, there is a population of \(p_i\) residents.</p>
<p>Yi has \(Q\) trips. For each trip, he must travel from village \(a\) to village \(b\). He want...Back To School '18: The Golden Porcupine2018-09-10T23:00:03+00:002018-09-10T23:00:03+00:00https://dmoj.ca/problem/bts18p6<div><p>Ohani was tired of sitting in a mall, watching people hold hands. He hates public displays of affection (PDA). So, he decided to take a walk. He was walking through a magical forest when he came across a porcupine. He noticed that the porcupine's body was completely made of gold. The porcupine said:</p>
<hr>
<p>Over a period of \(T\) seconds, I will shoot \(N\) quills out in total. The \(i^{th}\) quill exists only between the \(L_i^{th}\) and \(R_i^{th}\) seconds (inclusive).</p>
<p>The ...Back To School '18: An FFT Problem2018-09-10T23:00:02+00:002018-09-10T23:00:02+00:00https://dmoj.ca/problem/bts18p5<div><p>To prepare for the upcoming school year, Richard has bought \(N\) books for his English class. Each book is assigned a value, \(a_i\), Richard's willingness to read that book.</p>
<p>Richard wants to choose \(k\) of the \(N\) books and calculate his willingness to read those \(k\) books. The willingness to read those \(k\) books is the product of the willingness to read each individual book. For example, if he bought books of value \(a = [2, 5, 7, 9, 13]\), and he chose \(k = 3\) books w...Back To School '18: Beautiful Trees2018-09-10T23:00:01+00:002018-09-10T23:00:01+00:00https://dmoj.ca/problem/bts18p4<div><p>Junji has found a beautiful tree lying on the ground, and he wants to take it home to beautify his house. However, he only plans on taking a segment of the tree because he has aichmophobia and too many branches scares him.</p>
<p>The tree has \(N\) connection points. Each connection point has a <em>strength</em>, \(y_i\). A <em>good</em> segment is a segment of the tree where every connection point on the segment has a <em>strength</em> that has a solution to \(x^2 + x = y_i\) for some <...Back To School '18: Harambe2018-09-10T23:00:00+00:002018-09-10T23:00:00+00:00https://dmoj.ca/problem/bts18p1<div><p>As we all know, plagiarism is a huge issue, especially in Junyi's school. Being the exceptional student Junyi is, he is helping his Engrish teacher check for plagiarism.</p>
<p>Students nowadays are extremely lazy, meaning that they will <strong>only</strong> change individual letters in words to other letters. They will <strong>not</strong> change spaces to letters, or vice versa.</p>
<p>Plagiarism only occurs when the number of letters changed is less than or equal to \(K\).</p>
<p>Jun...Back To School '18: Making Friends2018-09-10T23:00:00+00:002018-09-10T23:00:00+00:00https://dmoj.ca/problem/bts18p3<div><p>The school year is starting soon, so Yunji wants to make some friends through his school's Discord server. In the server, there are \(N\) calls simultaneously going on, each with \(M_i\) participants.</p>
<p>Unfortunately, <s>everyone from Yunji's school dislikes him</s> everyone has important things to do other than Discord, so for every minute he is in the \(i^{th}\) call, \(1\) person will leave that call forever. However, if he is not in that call, no one will leave the call.</p>
<p>...Back To School '18: Letter Frequency2018-09-10T23:00:00+00:002018-09-10T23:00:00+00:00https://dmoj.ca/problem/bts18p2<div><p>Yunyi is given a sentence consisting of lowercase Latin letters and spaces, \(S\), and he has to determine which language the sentence is written in. One way that he knows of determining the language is by counting letter frequencies in certain sections of the sentence.</p>
<p>Yunyi will give you \(Q\) queries of the form <code>i j c</code>, which asks for the frequency of letter \(c\) between indices \(i\) and \(j\) (inclusive) \((1 \le i \le j \le |S|)\). Note that spaces (<code></code...DMOPC '18 Contest 1 P1 - Sorting2018-09-08T22:22:36+00:002018-09-08T22:22:36+00:00https://dmoj.ca/problem/dmopc18c1p1<div><p>Roger has a list of \(N\) positive integers \(A_1, A_2, \ldots, A_N\). However, his list is not yet finalized. Some of these numbers are <em>wildcards</em> which will be represented as zeroes in the list. Roger will try to assign the wildcards a value so that</p>
<ul>
<li>The list \(A\) is sorted from least to greatest</li>
<li>All wildcards have the same value, which is a positive integer</li>
</ul>
<p>Help Roger find out if this is possible. Output <code>YES</code> if he can assign the...DMOPC '18 Contest 1 P0 - Sorting2018-09-07T22:29:17+00:002018-09-07T22:29:17+00:00https://dmoj.ca/problem/dmopc18c1p0<div><p>Your baby brother is playing a game with 3 blocks. He wants to stack them so that the smallest block is at the top, and the largest block is at the bottom of the stack.</p>
<p>Having finished sorting them, he asks you to verify his ordering. Did he do it correctly?</p>
<h4>Input Specification</h4>
<p>The first line of input will contain the size of the block at the top of the stack.<br>
The second line of input will contain the size of the block at the middle of the stack.<br>
The third ...