Recently Added DMOJ Problemshttps://dmoj.ca/2019-11-05T01:15:31+00:00The latest problems added on the DMOJ: Modern Online Judge websiteBoard Games2019-11-05T01:15:31+00:002019-11-05T01:15:31+00:00https://dmoj.ca/problem/boardgames<div><p>Soupy boy is playing a game! He is currently on the \(N^{th}\) square, and wants to get to the \(M^{th}\) square <strong>exactly</strong>. However, moves in this game are a bit different than your average board game.</p>
<p>Starting from the current square, he can do one of \(4\) things.</p>
<ul>
<li>Go to the \((3 \times N)^{th}\) square.</li>
<li>Go to the \((N-1)^{th}\) square.</li>
<li>Go to the \((N-3)^{th}\) square.</li>
<li>Go to the \((\dfrac{N}{2})^{th}\) square if the current s...Magic Maze2019-11-04T03:44:05+00:002019-11-04T03:44:05+00:00https://dmoj.ca/problem/magicmaze<div><p>Naofumi is exploring a magical maze! The maze is a 2D array with \(N \times N\) pillars. The height of each pillar is generated using two arrays \(R\) and \(C\), each of size \(N\). Specifically, the height of the pillar at row \(i\) and column \(j\), pillar \((i, j)\), would be \(R_i \times C_j\). A path in this maze is defined as a sequence of pillars where every successive pillar is below or to the right of the previous pillar (i.e. only moving down or to the right). A valid path is d...Rectangle Counting2019-11-04T02:46:35+00:002019-11-04T02:46:35+00:00https://dmoj.ca/problem/rectanglecounting<div><p>In the sport of rectangle counting, participants are given a set of \(N\) rectangles and race to count the number of intersecting pairs. In order to check the answer, judges are called in to verify that the number of pairs counted by each contestant is correct.</p>
<p>The other day, Angie was invited to judge one of the competitions and now has to produce the correct answer for today's set of \(N\) rectangles. Her schedule is very busy so she doesn't have the time to do all the calcula...Angie and Functions2019-11-04T02:46:20+00:002019-11-04T02:46:20+00:00https://dmoj.ca/problem/angieandfunctions<div><p>Angie is studying functions!</p>
<p>For her homework, she was asked to figure out the coefficients \(c_1, c_2, ..., c_N, c_{N+1}\) in the following function:</p>
<blockquote><p>\(f(x)=c_1x^N+c_2x^{N-1}+...+c_Nx+c_{N+1}\) (All the coefficients are integers)</p>
</blockquote>
<p>To assist her on this question, her math teacher has allowed her to ask queries in the following form:</p>
<blockquote><p>Given an integer \(x\), what is \(f(x)\)?</p>
</blockquote>
<p>However, as he doesn't want t...Big Deposits2019-11-03T19:34:12+00:002019-11-03T19:34:12+00:00https://dmoj.ca/problem/bdep<div><p>Kazuma is depositing money! Every year, Kazuma puts \(N\) coins into his bank account. At the end of each year, Kazuma's investments will grow by \(P\) percent, rounded down to the nearest coin. After \(Y\) years, he would like to have at least \(T\) coins in his bank account so that he can buy some presents for a special someone. Since Kazuma is an efficient individual, he would like to know the minimum number of coins he has to put into his bank account every year so that he will have ...Wesley's Anger Contest 2 Problem 6 - Haunted Houses2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p6<div><p>Halloween has finally arrived and the ghosts on your street have decided to volunteer at your local haunted houses. Each of the \(N\) ghosts (numbered from \(1\) to \(N\)) will volunteer at <strong>exactly one of the \(5\) haunted houses</strong> and perform their prepared routine. The \(i^{th}\) ghost will perform \(k_i\) <strong>unique</strong> moves in their routine, with the \(k_i\) moves each being one of \(4\) types of moves:</p>
<ul>
<li>spook</li>
<li>hide</li>
<li>creep</li>
<li...Wesley's Anger Contest 2 Problem 5 - Oober Treats2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p5<div><p>After years of deliberation, you have finally decided to get a job for the fast growing startup called Oober Treats! Oober Treats has decided that rather than having children running around streets on Halloween, the candy will instead be delivered right to their door!</p>
<p>On Halloween night, you will drive a delivery truck that has \(F\) units of fuel, and will have \(N\) different candy delivery routes to choose from. Each route takes \(f_i\) units of fuel and allows you to earn cash...Wesley's Anger Contest 2 Problem 4 - The Ninth Triangle of the Underworld2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p4<div><p>At your neighbourhood Halloween party, appropriately named <code>The Ninth Triangle of the Underworld</code>, you've decided to play a fun game! Two witch hats are placed on conveyor belts moving in opposite directions. For simplicity, we can imagine the witch hats as triangles, with their bases on the same line parallel to the \(x\)-axis, and that the witch hats will continue moving in opposite directions for eternity.</p>
<p><img src="https://dmoj.algome.me/media/martor/f3b6c055-13fb-4...Wesley's Anger Contest 2 Problem 3 - Pumpkin Counting2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p3<div><p><strong>For this question, Python users are recommended to use PYPY over CPython.</strong></p>
<p>To celebrate Halloween, you have decided to hold an art contest! A drawing is a grid of pixels with \(N\) rows and \(2N\) columns, composed of only <code>#</code> and <code>.</code> characters. <code>#</code> can be thought of as a black pixel, and <code>.</code> can be thought of as a white pixel. <strong>It is guaranteed that the drawing will be framed with a single layer of black pixels.<...Wesley's Anger Contest 2 Problem 2 - Costume Shopping2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p2<div><p>With Halloween coming up in \(N\) days, you realized that you need to buy costumes! Specifically, you want to buy \(M\) different costumes <strong>before Halloween</strong> so that you have multiple options to choose from on Halloween. Thankfully there is a store nearby that allows you to <strong>buy at most one costume a day</strong>, however the price of the costume keeps changing. Initially, the costumes will cost \($1\,000\,000\), however over the course of \(N\) days, they will chan...Wesley's Anger Contest 2 Problem 1 - OCT 31 = DEC 25?2019-11-03T04:00:00+00:002019-11-03T04:00:00+00:00https://dmoj.ca/problem/wac2p1<div><p>Halloween is coming up soon! Unfortunately you forgot what day of the week it is on. Thankfully, [user:Pookmeister] has remembered the day of the week that Christmas is on, and knowing that OCT 31 = DEC 25, believes this information is more than enough to help you out.</p>
<p>Given the day of the week the Christmas is on, determine the day that Halloween is on.</p>
<p>Recall that Halloween is on October 31 and Christmas is on December 25 based on the <a href="https://en.wikipedia.org/wik...Brazilian IOI TST '19 Day 1 - Secret Santa2019-10-24T22:44:35+00:002019-10-24T22:44:35+00:00https://dmoj.ca/problem/braziloi19p2<div><p>The company where Arthur works organizes a secret Santa every year, and unfortunately, he is responsible for organizing the game this year. In this game, every person has to send a gift to someone previously chosen at random, and in the day of the gifts exchange, when person \(A\) sends a gift to person \(B\), \(B\) is the next person to send a gift (in case \(B\) hasn't sent it yet). When the next person to send a gift isn't defined (at the start of the game, for example), this person i...Fast Factorial Calculator 32019-10-22T21:53:56+00:002019-10-22T21:53:56+00:00https://dmoj.ca/problem/factorial3<div><p>ho94949 is in a good mood today. He discovered a secret method to compute large factorials very quickly. Can you beat him?</p>
<h4>Input Specification</h4>
<p>The first and only line of integer contains two positive integers, \(N\) and \(P\).</p>
<p>You may assume \(1 \le N < P \le 10^{10}\), and that \(P\) is prime.</p>
<h4>Output Specification</h4>
<p>Print \(N! \pmod{P}\).</p>
<h4>Sample Input</h4>
<pre><code>9999999966 9999999967</code></pre>
<h4>Sample Output</h4>
<pre><code>99...A Simple Multiplication2019-10-22T18:51:53+00:002019-10-22T18:51:53+00:00https://dmoj.ca/problem/asm4<div><p>Your computer engineering instructor decided to give you another task (you are the best in the class, after all):</p>
<blockquote><p>Write a program that prints the result of \(N ^ P \bmod M\).</p>
</blockquote>
<p>Unimpressed by the supposed challenge, you open up you favourite text editor (Vim, of course) and begin typing away\(\ldots\) in assembly.</p>
<h4>Input Specification</h4>
<p>The first line will contain 3 space-separated integers, \(N\ (1 \le N \le 100)\), \(P\ (1 \le P \le 10...DMOPC '19 Contest 2 P4 - A Greedy Problem2019-10-21T13:47:37+00:002019-10-21T13:47:37+00:00https://dmoj.ca/problem/dmopc19c2p4hard<div><p>Jack is doing a programming contest. There are \(N\) problems in this contest and the contest will last a total of \(T\) minutes. The \(i\)-th problem will take Jack exactly \(t_i\) minutes to solve. Having an aversion to certain problem types such as dynamic programming, Jack wonders how many subsets of problems he can solve within \(q_i\) minutes if he decides that he definitely wants to solve problem \(a_i\) and problem \(b_i\). More formally, Jack wants to determine the number of sub...DMOPC '19 Contest 2 P6 - Two Roots2019-10-21T13:30:12+00:002019-10-21T13:30:12+00:00https://dmoj.ca/problem/dmopc19c2p6<div><p>You are given a tree consisting of \(N\) nodes. Bob has chosen two distinct nodes, \(A\) and \(B\), which you are to determine. You can ask up to \(Q\) queries of the form: \(k\) \(x_1\) \(x_2\) \(\ldots\) \(x_k\) and Bob will tell you the distance between the lowest common ancestor of \(x_1, x_2, \ldots , x_k\) if the tree were rooted at \(A\) and the lowest common ancestor of \(x_1, x_2, \ldots , x_k\) if the tree were rooted at \(B\). The lowest common ancestor of \(x_1, x_2, \ldots ,...DMOPC '19 Contest 2 P5 - Connections2019-10-21T13:29:51+00:002019-10-21T13:29:51+00:00https://dmoj.ca/problem/dmopc19c2p5<div><p>In the country of Nocrae, there exists \(N\) villages, the \(i\)th of which contains \(a_i\) people. The Nocraean villages are connected to each other by \(N-1\) roads of length \(1\) such that it is possible to reach any village from any other village while only using these roads. The villages wish to establish a meeting place where all of the villagers can meet up. Knowing that any single village might be too far for some people to go to, the villages decided to choose two distinct vil...DMOPC '19 Contest 2 P3 - Selection2019-10-21T13:29:19+00:002019-10-21T13:29:19+00:00https://dmoj.ca/problem/dmopc19c2p3<div><p>Veshy has a box with \(N\) items, the \(i\)th of which has a "goodness" of \(g_i\) on Veshy's standards. Over a period of \(M\) minutes, one of two events may occur. On the \(i\)th minute, either Veshy's standards have changed and the \(a_i\)th item's "goodness" has changed to \(b_i\), or he wants to know the goodness of the \(c_i\)th best item in the subarray of items, \(g_{l_i},g_{l_i+1},\ldots,g_{r_i}\).</p>
<p><strong>It is recommended Python users use PYPY instead.</strong></p>
<h4>...DMOPC '19 Contest 2 P2 - Squares2019-10-21T13:28:20+00:002019-10-21T13:28:20+00:00https://dmoj.ca/problem/dmopc19c2p2<div><p>You are given an \(N \times M\) grid of squares. Each square contains a number \(a_i\), \(1 \le i \le (N\times M)\), the cost to travel through that square. You are starting at the most top-left square. At each turn you may choose to move down or right but not both. Find the minimum cost it would take you to travel to the most bottom-right square.</p>
<h4>Constraints</h4>
<p>In all tests,<br>
\(2 \le N, M \le 500\)<br>
\(1 \le a_i \le 10^6\)</p>
<h4>Input Specification</h4>
<p>The first ...DMOPC '19 Contest 2 P1 - Box and Whiskers2019-10-21T13:27:56+00:002019-10-21T13:27:56+00:00https://dmoj.ca/problem/dmopc19c2p1<div><p>Veshy is struggling in data management class. Veshy forgot how to make a <a href="https://www.purplemath.com/modules/boxwhisk.htm" rel="nofollow">box and whisker plot</a>, so he wants you to tell him the important values to make the plot of the \(N\) data points \(a_1,a_2,a_3,\ldots,a_N\), \(a_i \in N\) he gives you: the <strong>minimum</strong>, <strong>maximum</strong>, \(Q_1\) (Quartile 1 or median of the first \(\left\lfloor\frac{N}{2}\right\rfloor\) elements), \(Q_2\) (Quartile 2 or...DMOPC '19 Contest 2 P0 - Roller Coaster2019-10-21T13:26:56+00:002019-10-21T13:26:56+00:00https://dmoj.ca/problem/dmopc19c2p0<div><p>You are working at an amusement park roller coaster. There is a line of \(N\) incoming children. However, each person needs to be at least height \(H_{min}\) and at most \(H_{max}\) for safety reasons. Given the heights of each child, \(h_1,h_2,h_3,...,h_N\), count the number of children who can go on the ride. \(N, H_{min}, H_{max}, h_i\) are natural numbers.</p>
<h4>Constraints</h4>
<p>In all tests,<br>
\(1 \le N \le 10^5\)<br>
\(1 \le H_{min} \le H_{max} \le 10^6\)<br>
\(1 \le h_i \le...Tower2019-10-20T17:56:14+00:002019-10-20T17:56:14+00:00https://dmoj.ca/problem/dpx<div><p><strong>These problems are from the <a href="https://atcoder.jp/contests/dp" rel="nofollow">atcoder DP contest</a>, and were transferred onto DMOJ. All problem statements were made by several atcoder users. As there is no access to the test data, all data is randomly generated. If there are issues with the statement or data, please contact [user:Rimuru] or [user:Ninjaclasher] on slack.</strong></p>
<p>There are \(N\) blocks, numbered \(1, 2, \ldots, N\). For each \(i\ (1 \le i \le N)\), ...OCC '19 G1 - Top Coder2019-10-18T02:24:59+00:002019-10-18T02:24:59+00:00https://dmoj.ca/problem/occ19g1<div><p>Little Andrew has a dream: to be a <code>top coder</code>. A top coder must have a number of skills, like algorithm design, time complexity analysis, logic thinking, coding and debugging, etc.</p>
<p>Andrew designed a model for how to become a top coder. In his model, a top coder needs to master \(k\) kinds of skills, conveniently numbered from \(1\) to \(k\). Andrew's initial skill values are \(a_1, a_2, \ldots, a_k\). To improve these skills, Andrew needs to practice a lot of questions...OCC '19 G2 - A Guessing Game2019-10-18T02:24:53+00:002019-10-18T02:24:53+00:00https://dmoj.ca/problem/occ19g2<div><p>Alex is playing a game with William. Alex gets two sequences: sequence \(A\) and sequence \(W\), each of which has \(N\) numbers. Alex will show William the sequence \(W\) but not the sequence \(A\). The objective of this game is to figure out each number in sequence \(A\).</p>
<p>During the game, William can ask Alex questions as many times as he wants. For each question, William will pick up an interval \([L, R]\) (\(1 \le L \le R \le N\)) and ask Alex the sum of \(a_i\) for \(i \in [L...OCC '19 G3 - Binary Game2019-10-18T02:24:20+00:002019-10-18T02:24:20+00:00https://dmoj.ca/problem/occ19g3<div><p>Bob is learning binary numbers. To help Bob memorizes the first \(2^k\) (from \(0\) to \(2^k-1\)) binary representations, his teacher, Mr. Ecurb, designs a binary game. In this game, Bob is given a binary sequence \(S\), which only consists of <code>0</code> and <code>1</code>, and \(2^k\) substitution rules, where the \(i^{th}\) rule (\(0 \le i \le 2^k-1\)) replaces number \(i\)'s \(k\)-bit binary representation with character \(c_i\) (\(c_i = 0 \text{ or } 1\)) and generates value \(v_...