Recently added DMOJ problemshttps://dmoj.ca/The latest problems added on the DMOJ: Modern Online Judge websiteen-caSun, 26 Mar 2017 18:23:42 +0000TLE '16 Contest 7 P6 - Everyone Hates Readinghttps://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...Sun, 26 Mar 2017 18:23:42 +0000https://dmoj.ca/problem/tle16c7p6TLE '16 Contest 7 P5 - Shortest Path Faster Algorithmhttps://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...Sun, 26 Mar 2017 18:23:34 +0000https://dmoj.ca/problem/tle16c7p5TLE '16 Contest 7 P4 - Abstract Problemhttps://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 ...Sun, 26 Mar 2017 18:23:24 +0000https://dmoj.ca/problem/tle16c7p4TLE '16 Contest 7 P3 - NORhttps://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...Fri, 24 Mar 2017 03:20:24 +0000https://dmoj.ca/problem/tle16c7p3TLE '16 Contest 7 P2 - Judginghttps://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 ...Fri, 24 Mar 2017 03:20:14 +0000https://dmoj.ca/problem/tle16c7p2TLE '16 Contest 7 P1 - Math Helperhttps://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...Fri, 24 Mar 2017 03:20:03 +0000https://dmoj.ca/problem/tle16c7p1Vera and Love Triangleshttps://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...Sun, 19 Mar 2017 20:45:37 +0000https://dmoj.ca/problem/waterloow2017eVera and Sortinghttps://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...Sun, 19 Mar 2017 20:45:33 +0000https://dmoj.ca/problem/waterloow2017dVera and Mean Sortinghttps://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...Sun, 19 Mar 2017 20:45:28 +0000https://dmoj.ca/problem/waterloow2017cVera and LCShttps://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...Sun, 19 Mar 2017 20:45:21 +0000https://dmoj.ca/problem/waterloow2017bVera and Outfitshttps://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...Sun, 19 Mar 2017 20:45:15 +0000https://dmoj.ca/problem/waterloow2017aECOO '16 R3 P3 - CamelCasehttps://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>
<...Mon, 13 Mar 2017 22:18:09 +0000https://dmoj.ca/problem/ecoo16r3p3ECOO '16 R3 P2 - Target Practicehttps://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 ...Mon, 13 Mar 2017 22:17:44 +0000https://dmoj.ca/problem/ecoo16r3p2ECOO '16 R3 P1 - Nerd Pokerhttps://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...Mon, 13 Mar 2017 22:17:26 +0000https://dmoj.ca/problem/ecoo16r3p1COCI '07 Contest 1 #6 Stazahttps://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...Fri, 10 Mar 2017 16:05:39 +0000https://dmoj.ca/problem/coci07c1p6COCI '07 Contest 1 #5 Srednjihttps://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...Fri, 10 Mar 2017 15:53:17 +0000https://dmoj.ca/problem/coci07c1p5COCI '07 Contest 1 #4 Zapishttps://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 \([ ( \{ \} ) ]\), \([ ] ( ) \{ \}...Fri, 10 Mar 2017 15:26:48 +0000https://dmoj.ca/problem/coci07c1p4COCI '07 Contest 1 #3 Prinovahttps://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...Thu, 09 Mar 2017 16:55:43 +0000https://dmoj.ca/problem/coci07c1p3COCI '07 Contest 2 #2 PEGhttps://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 ...Thu, 09 Mar 2017 03:11:22 +0000https://dmoj.ca/problem/coci07c1p2COCI '07 Contest 1 #1 Cetvrtahttps://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...Thu, 09 Mar 2017 03:07:15 +0000https://dmoj.ca/problem/coci07c1p1Decodinghttps://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...Tue, 07 Mar 2017 03:02:32 +0000https://dmoj.ca/problem/python3Disclosurehttps://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...Tue, 07 Mar 2017 03:02:27 +0000https://dmoj.ca/problem/python2Self-deceptionhttps://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="...Tue, 07 Mar 2017 03:02:21 +0000https://dmoj.ca/problem/python1CCC '17 J4 - Favourite Timeshttps://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 <...Mon, 06 Mar 2017 16:11:16 +0000https://dmoj.ca/problem/ccc17j4CCC '17 S1 - Sum Gamehttps://dmoj.ca/problem/ccc17s1<div><p>Annie has two favourite baseball teams: the Swifts and the Semaphores.
She has followed them throughout the season, which is now over.
The season lasted for \(N\) days.
Both teams played exactly one game on each day.</p>
<p>For each day, Annie recorded the number of runs scored by the Swifts
on that day.
She also recorded this information for the Semaphores.</p>
<p>She would like you to determine the largest integer \(K\) such that \(K \leq N\)
and the
Swifts and the Semaphores had score...Sun, 05 Mar 2017 15:49:41 +0000https://dmoj.ca/problem/ccc17s1