Recently added DMOJ problemshttps://dmoj.ca/2017-03-29T15:20:13+00:00The latest problems added on the DMOJ: Modern Online Judge websiteIOI '13 P6 - Game2017-03-29T15:20:13+00:00https://dmoj.ca/problem/ioi13p6<div><p>Bazza and Shazza are playing a game. The board is a grid of cells, with \(R\) rows number \(0, \ldots, R - 1\), and \(C\) columns numbered \(0, \ldots, C - 1\). We let \((P, Q)\) denote the cell in row \(P\) and column \(Q\). Each cell contains a non-negative integer, and at the beginning of the game all of the these integers are zero.</p>
<p>The game proceeds as follows. At any time, Bazza may either:</p>
<ul>
<li>update a cell \((P, Q)\), by assigning the integer that it contains;</li>...TLE '16 Contest 7 P6 - Everyone Hates Reading2017-03-26T18:23:42+00:00https://dmoj.ca/problem/tle16c7p6<div><div style="float:right; width:300px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/5a37816663698be31664d5a3c6b62983e10e60eb/68747470733a2f2f70657463732e63612f7374617469632f696d616765732f746c652f746c65313663372f746c653136633770362e706e67" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">Your brain after reading certain books.</div></div><p>Your neighbourhood fox has another English project. There's only one proble...TLE '16 Contest 7 P5 - Shortest Path Faster Algorithm2017-03-26T18:23:34+00:00https://dmoj.ca/problem/tle16c7p5<div><div style="float:right; width:300px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/50b6a2f7856db4620f18d2944c877cab830abc53/68747470733a2f2f70657463732e63612f7374617469632f696d616765732f746c652f746c65313663372f746c653136633770352e706e67" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">Flaco Lombradi using high-tech instruments to oversee the new freeway system.</div></div><p>Fax McClad, Croneria's least politica...TLE '16 Contest 7 P4 - Abstract Problem2017-03-26T18:23:24+00:00https://dmoj.ca/problem/tle16c7p4<div><div style="float:right; width:150px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/b132d5654a15c2427b3715275282f22ed0b5c9e2/68747470733a2f2f70657463732e63612f7374617469632f696d616765732f746c652f746c65313663372f746c653136633770342e6a706567" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">Abstract art, like abstract problems, is very enjoyable.</div></div><p>You see an abstract problem on Codeforces.</p>
<p>Given ...TLE '16 Contest 7 P3 - NOR2017-03-24T03:20:24+00:00https://dmoj.ca/problem/tle16c7p3<div><div style="float:right; width:300px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/324b4a858643beeffc31737d61be6f5c76e441f8/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f332f33632f56656e6e313030302e7376672f33383470782d56656e6e313030302e7376672e706e67" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">A Venn diagram of \(A \text{ NOR } B\) from the Wikimed...TLE '16 Contest 7 P2 - Judging2017-03-24T03:20:14+00:00https://dmoj.ca/problem/tle16c7p2<div><div style="float:right; width:300px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/de5201f984beaa7dafcf6f04e05d4727591f7487/68747470733a2f2f70657463732e63612f7374617469632f696d616765732f746c652f746c65313663372f746c653136633770322e706e67" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">Students having fun at last year's ECOO contest!</div></div><p>Mr. C is a judge at the ECOO (Educational Cooking Organization of ...TLE '16 Contest 7 P1 - Math Helper2017-03-24T03:20:03+00:00https://dmoj.ca/problem/tle16c7p1<div><div style="float:right; width:300px; padding: 10px 10px">
<img src="https://camo.dmuser.ml/35fc9c6c8ca9e23572dc3192ba6d4a1ed1b28a85/68747470733a2f2f70657463732e63612f7374617469632f696d616765732f746c652f746c65313663372f746c653136633770312e706e67" style="display: block; margin: 0 auto; width:100%;">
<div style="text-align:center;font-style:italic;margin-top:0.5em">A stapled package on simple derivatives - with lots of practice!</div></div><p>While the CS nerd is preparing for various computi...Vera and Love Triangles2017-03-19T20:45:37+00:00https://dmoj.ca/problem/waterloow2017e<div><h5>2017 Winter Waterloo Local ACM Contest, Problem E</h5>
<p>Vera has N friends numbered from \(0\) to \(N-1\). Being in Software Engineering, all her friends do not have enough spare time to engage in relationships. However, friends have crushes on each other.</p>
<p>If \(x\) is a non-negative integer, let \(g(x)\) be the number of ones in the binary representation of \(x\).</p>
<p>Let \(f(i,j) = g((A \cdot B^{(i \cdot N +j)}) \% M)\), where \(A,B,M\) are integer constants.</p>
<p>It is k...Vera and Sorting2017-03-19T20:45:33+00:00https://dmoj.ca/problem/waterloow2017d<div><h5>2017 Winter Waterloo Local ACM Contest, Problem D</h5>
<p>Vera is very smart and invented a new sorting algorithm. She coded the following Python function to count how many steps her algorithm takes.</p>
<div class="codehilite"><pre><span></span><code><span class="k">def</span> <span class="nf">steps</span><span class="p">(</span><span class="n">array</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">array</spa...Vera and Mean Sorting2017-03-19T20:45:28+00:00https://dmoj.ca/problem/waterloow2017c<div><h5>2017 Winter Waterloo Local ACM Contest, Problem C</h5>
<p>The <em>harmonic mean</em> of a sequence of positive integers \(x_1, \cdots, x_N\) is
\[
H(x_1, \cdots, x_N) = \left(\frac{\sum_{i=1}^N x_i^{-1}}{N} \right)^{-1}
\]</p>
<p>Vera classifies an array of positive integers \(A = [A_1, \cdots, A_N]\) of length \(N\) as \(K\)<em>-mean-sorted</em> if \(M(i) \ge M(i+1)\) for \(1 \le i \le N-K\) where
\[
M(i) = H(A_i, \cdots, A_{i+K-1})
\]</p>
<p>A <em>permutation</em> \(P\) is an ordered...Vera and LCS2017-03-19T20:45:21+00:00https://dmoj.ca/problem/waterloow2017b<div><h5>2017 Winter Waterloo Local ACM Contest, Problem B</h5>
<p>Vera is learning about the longest common subsequence problem.</p>
<p>A string is a (possibly empty) sequence of lowercase letters. A subsequence of a string \(S\) is a string obtained by deleting some letters of \(S\) (possibly none or all). For example <code>vra</code>, <code>a</code>, <code> </code> (empty string), and <code>vera</code> are all subsequences of <code>vera</code>. The <em>longest common subsequence (LCS)</em> of...Vera and Outfits2017-03-19T20:45:15+00:00https://dmoj.ca/problem/waterloow2017a<div><h5>2017 Winter Waterloo Local ACM Contest, Problem A</h5>
<p>Vera owns \(N\) tops and \(N\) pants. The \(i\)-th top and \(i\)-th pants have colour \(i\), for \(1 \le i \le N\), where all \(N\) colors are different from each other.</p>
<p>An outfit consists of one top and one pants. Vera likes outfits where the top and pants are not the same colour.</p>
<p>How many different outfits does she like?</p>
<h4>Constraints</h4>
<ul>
<li>\(1 \le N \le 2017\)</li>
<li>\(N\) is integer</li>
</ul>
<h...ECOO '16 R3 P3 - CamelCase2017-03-13T22:18:09+00:00https://dmoj.ca/problem/ecoo16r3p3<div><p>Many programmers use <code>CamelCase</code> when naming variables, functions, classes and other entities. In CamelCase, when a name consists of multiple words concatenated together, such as <code>myawesomevariablename</code>, the first letter of every distinct word is capitalized. Sometimes there is more than one way to turn a string of letters into CamelCase.</p>
<table class="table" style="max-width:50%">
<thead>
<tr>
<th></th>
<th>Lower</th>
<th>Upper</th></tr></thead>
<tbody>
<...ECOO '16 R3 P2 - Target Practice2017-03-13T22:17:44+00:00https://dmoj.ca/problem/ecoo16r3p2<div><p>You wake up to find yourself in an airless, friction-less, gravity-less arena armed with an object that bounces perfectly off any surface. Targets are appearing at one end of the room and you have to hit as many of them as you can. You can throw the ball directly at a target, or bounce it off the side walls before hitting the target. However, it doesn't count if you hit the wall behind the target before hitting the target.</p>
<p>The diagram below shows three different attempts to hit a ...ECOO '16 R3 P1 - Nerd Poker2017-03-13T22:17:26+00:00https://dmoj.ca/problem/ecoo16r3p1<div><p><code>Nerd Poker</code> is a podcast where you get to listen in on a group of people playing a game of <code>Dungeons and Dragons</code>. There is a lot of die rolling in this game, using a lot of different types of dice. There are dice with \(4\), \(6\), \(8\), \(10\) \(12\), and \(20\) sides that are regularly used to play the game. In combat and at other critical junctures of the game, low rolls are often bad.</p>
<p>The <code>Nerd Poker</code> players are superstitious, so before ent...COCI '07 Contest 1 #6 Staza2017-03-10T16:05:39+00:00https://dmoj.ca/problem/coci07c1p6<div><p>A bicycle race is being organized in a country. The transport network of the country consists of \(N\) cities numbered \(1\) through \(N\), with \(M\) bidirectional roads connecting them. We will use the following terms:</p>
<ul>
<li>A <strong>path</strong> is a sequence of roads in which each road starts in the city the preceding road ended in. </li>
<li>A <strong>simple path</strong> is a path which never visits a city more than once. </li>
<li>A <strong>ring</strong> is a <strong>sim...COCI '07 Contest 1 #5 Srednji2017-03-10T15:53:17+00:00https://dmoj.ca/problem/coci07c1p5<div><p>Consider a sequence \(A\) of integers, containing \(N\) integers between \(1\) and \(N\). Each integer appears
exactly once in the sequence.</p>
<p>A subsequence of \(A\) is a sequence obtained by removing some (possibly none) numbers from the
beginning of \(A\), and then from the end of \(A\).
Calculate how many different subsequences of \(A\) of
odd length have their median equal to \(B\). The
median of a sequence is the element in the middle of the s...COCI '07 Contest 1 #4 Zapis2017-03-10T15:26:48+00:00https://dmoj.ca/problem/coci07c1p4<div><p>A regular bracket-sequence is a string of characters consisting only of opening and closing brackets, and
satisfying the following conditions:</p>
<ul>
<li>An empty string is a regular bracket-sequence.</li>
<li>If \(A\) is a regular bracket-sequence, then \((A)\), \([A]\) and \(\{A\}\) are also regular bracket-sequences.</li>
<li>If \(A\) and \(B\) are regular bracket-sequences, then \(AB\) is also a regular bracket-sequence.
For example, the sequences \([ ( \{ \} ) ]\), \([ ] ( ) \{ \}...COCI '07 Contest 1 #3 Prinova2017-03-09T16:55:43+00:00https://dmoj.ca/problem/coci07c1p3<div><p>Brojko and Brojana are happily married with \(N\) little boys. The boys are named with distinct even
integers \(P_1 , P_2 , \ldots, P_N\) .</p>
<p>Brojko and Brojana are expecting an addition to their family and have to come up with a nice name for
the little girl. They have decided that the name will be an odd integer in the range \([A, B]\). Because they
find all integers in that range equally beautiful, they have decided to choose the number which
maximizes the distance to the name of...COCI '07 Contest 2 #2 PEG2017-03-09T03:11:22+00:00https://dmoj.ca/problem/coci07c1p2<div><p>In the famous logic game Peg, pieces jump over other pieces to remove them from the game, until only
one piece is left.</p>
<p>Here is the initial layout of the board:</p>
<pre><code> ooo
ooo
ooooooo
ooo.ooo
ooooooo
ooo
ooo</code></pre>
<p>The lowercase letter <code>o</code> represents a piece, while the character <code>.</code> is an empty square. In one move, a
player may choose one piece and one of the four main directions (up, down, left, right), if there is
another piece in ...COCI '07 Contest 1 #1 Cetvrta2017-03-09T03:07:15+00:00https://dmoj.ca/problem/coci07c1p1<div><p>Mirko needs to choose four points in the plane so that they form a rectangle with sides parallel to the
axes. He has already chosen three points and is confident that he hasn't made a mistake, but is having
trouble locating the last point. Help him.</p>
<h4>Input Specification</h4>
<p>Each of the three points already chosen will be given on a separate line. All coordinates will be integers
between \(1\) and \(1\,000\).</p>
<h4>Output Specification</h4>
<p>Output the coordinates of the fo...Decoding2017-03-07T03:02:32+00:00https://dmoj.ca/problem/python3<div><p>[user:Xyene] had a dream about a hard problem last night, and this morning he's decided to see if anyone can solve it.</p>
<p>[user:Xyene] has some code that does some funky stuff with a secret <code>x</code>, and stores it into a variable <code>y</code>.</p>
<div class="codehilite"><pre><span></span><code><span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
<span class="n">x</span> <span class="o">=</span> <span class="o"><</span><span class="n">some</s...Disclosure2017-03-07T03:02:27+00:00https://dmoj.ca/problem/python2<div><p>[user:quantum] is not feeling well today, and so has decided to create a painful challenge for you.</p>
<p>You are given the following function <code>x</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="k">def</span> <span class="nf">outer</span><span class="p">():</span>
<span class="n">secret</span> <span class="o">=</span> <span class="o"><</span><span class="n">some</span> <span class="n">special</span> <span class="n">value</span> <span class="n">you</sp...Self-deception2017-03-07T03:02:21+00:00https://dmoj.ca/problem/python1<div><p>[user:quantum] is not feeling well today, and so has decided to create a painful challenge for you.</p>
<p>You are given the following class:</p>
<div class="codehilite"><pre><span></span><code><span class="k">class</span> <span class="nc">Magic</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">method</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="...CCC '17 J4 - Favourite Times2017-03-06T16:11:16+00:00https://dmoj.ca/problem/ccc17j4<div><p>Wendy has an LED clock radio, which is a 12-hour clock, displaying
times from \(\tt 12:00\) to \(\tt 11:59\). The hours do
not have leading zeros but minutes may have leading zeros,
such as \(\tt 2:07\) or \(\tt 11:03\).</p>
<p>When looking at her LED clock radio, Wendy likes to spot arithmetic
sequences in the digits. For example, the times \(\tt 12:34\) and
\(\tt 2:46\) are some of her favourite times, since the digits form
an arithmetic sequence.</p>
<p>A sequence of digits is an <...