Recently Added MCPT Problemshttps://mcpt.ca/2019-11-09T02:27:40.337427+00:00The latest problems added on the MCPT's Online Judge websiteA Squirrel Problem2019-11-09T02:27:40.337427+00:002019-11-09T02:27:40.337427+00:00https://mcpt.ca/problem/asquirrelproblem<div><p>[user:ChrisT] is feeling hungry. He has snacks lined up in a row, numbered from \(1\) to \(N\). Each snack has \(C_i\) calories. Because [user:ChrisT] doesn't want to get too thicc, he would like to know the number of calories in snack number \(i\). However, his house has a squirrel infestation! The squirrels like to leave nuts or eat part of the snacks from number \(l\) to number \(r\), inclusive. Please help [user:ChrisT]!</p>
<h4>Input Specification</h4>
<p>The first line contains the...A Unique List2019-11-09T02:27:40.337427+00:002019-11-09T02:27:40.337427+00:00https://mcpt.ca/problem/duplicate<div><p>Given an array of length \(N\), remove all duplicates in the array and then print it out, sorted in ascending order.</p>
<h4>Input Specification</h4>
<p>The first line will contain integer \(N\) \((1 \leq N \leq 8)\), the size of the array.</p>
<p>The next line will contain array \(a\), the array that you need to remove the duplicates from. It is guaranteed that each element of the array will not be larger than \(N\).</p>
<h4>Output Specification</h4>
<p>The same array without the duplic...Component Sum2019-11-09T02:27:40+00:002019-11-09T02:27:40+00:00https://mcpt.ca/problem/components<div><p>You have a graph of \(N\) nodes and \(Q\) queries.</p>
<p>Queries will be in two types:</p>
<p><code>1 x y</code>: Add an edge between nodes \(X\) and \(Y\) \((1 \leq X,Y \leq N, X\neq Y\)).</p>
<p><code>2 k</code>: Print the sum of the sizes of the connected components whose sizes are less than or equal to \(K\) \((1 \leq K \leq N)\).</p>
<h4>Input Specification</h4>
<p>The first line will contain two integers \(N\) and \(Q\) \((2 \leq N,Q \leq 2\cdot 10^5)\).</p>
<p>The next \(Q\) line...MLE '19 Contest 2 P2 - Meta2019-11-03T14:50:09.626777+00:002019-11-03T14:50:09.626777+00:00https://mcpt.ca/problem/mle19c2p2<div><p>In any tree, the <em>diameter</em> of the tree is the maximum number of nodes of any simple path. Of course, there can only be one maximum. However, there may be multiple simple paths that are the maximum. The <em>metadiameter</em> of the tree is a path consisting of the intersecting nodes of all of these diameter paths. Given a tree of \(N\) nodes, what is the <em>number of nodes</em> in the <em>metadiameter</em>?</p>
<h4>Input Specification</h4>
<p>The first line will contain the integ...MLE '19 Contest 2 P1 - FUN2019-11-03T14:50:09.626777+00:002019-11-03T14:50:09.626777+00:00https://mcpt.ca/problem/mle19c2p1<div><p>A string is <em>fun</em> if it contains each character at most \(K\) times. Given a string \(S\), how many substrings of the string are <em>fun</em>? A substring is a <strong>non-empty</strong> contiguous sequence of characters within a string.</p>
<h4>Input Specification</h4>
<p>The first line will contain the string \(S\) \((1 \le |S| \le 10^5)\). The string will only consist of lowercase latin characters.</p>
<p>The second line will contain the integer \(K\) \((1 \le K \le |S|)\).</p>...1-Pile Nim2019-11-01T15:48:56+00:002019-11-01T15:48:56+00:00https://mcpt.ca/problem/nimeasy<div><p>You are playing a game with your friend. There is a pile of \(N\) rocks, and you start removing rocks from the pile, then you take turns with your friend. On your turn, you can remove \(1\) to \(K\) rocks from the pile. The person who takes the last rock loses. If you both play optimally, who will win?</p>
<h4>Input Specification</h4>
<p>The first line will contain the integers \(N, K\) \((1 \le N, K \le 10^9)\).</p>
<h4>Output Specification</h4>
<p>If you will win, print <code>:hudab:</...A Snowball Problem2019-10-21T23:16:17+00:002019-10-21T23:16:17+00:00https://mcpt.ca/problem/asnowballproblem<div><p>[user:MstrPikachu] is very unhappy that <a href="https://mcpt.ca/problem/lcc19c1j2" rel="nofollow">A Car Problem</a> was moved from J1 to J2. In fact, he is so angry he decides roll a snowball from the top of a hill to [user:Ninjaclasher]'s house! Can you help him find the time it takes for the snowball to hit [user:Ninjaclasher]'s house?</p>
<p>Assume the mass \(M\) and radius \(R\) of the snowball does not change during its descent, and the snowball rolls without slipping. The snowball...A Harder Contest '19 - A Permutation Problem 22019-10-17T23:34:00.612183+00:002019-10-17T23:34:00.612183+00:00https://mcpt.ca/problem/ahc19p4<div><p>Given 2 integers \(N\) and \(K\), find the lexicographically largest permutation of \(1 \ldots N\) such that it takes exactly \(K\) swaps (between any two elements) to most efficiently sort it.</p>
<p>We define the most efficient sorting of an array of integers as one where the number of swaps is minimized.</p>
<p>The answer is guaranteed to exist.</p>
<h4>Input Specification</h4>
<p>The first and only line will contain \(2\) integers, \(N\) \((1 \leq N \leq 10^6),\) \(K\) \((0 \leq K \l...A Harder Contest '19 - How Perfect?2019-10-17T23:34:00.612183+00:002019-10-17T23:34:00.612183+00:00https://mcpt.ca/problem/ahc19p1<div><p>You are a judge for a number contest! You are given an integer, \(N\) and you want to determine how perfect it is.</p>
<p>If the number is a perfect square (but <em>not</em> a perfect cube), it is <code>Somewhat Perfect</code>.</p>
<p>If the number is a perfect cube (but <em>not</em> a perfect square), it is <code>Kinda Perfect</code>.</p>
<p>If the number is both a perfect square <em>and</em> a perfect cube, it is <code>Perfectly Perfect</code>.</p>
<p>If the number isn't a perfect squa...A Harder Contest '19 - Spy2019-10-17T23:34:00.612183+00:002019-10-17T23:34:00.612183+00:00https://mcpt.ca/problem/ahc19p2<div><p>You are a spy sent to DMOJstan to sabotage their internal servers. To keep communications with your nation (WLMOJstan) private, you are issued a one-time pad code book.</p>
<p>The code book and encrypted messages are both strings of numeric digits.</p>
<p>You want to create program to help you decode communications so you can spend more time on espionage.</p>
<p>One-time pad decryption works as follows:</p>
<ol>
<li>Split each string into two-digit blocks: each two-digit block in the enc...A Harder Contest '19 - An Alternating Problem2019-10-17T23:34:00+00:002019-10-17T23:34:00+00:00https://mcpt.ca/problem/ahc19p5<div><p>Given a array \(a\) of \(N\) integers and an integer \(M\), find a subsequence of this array such that the alternating sum of this subsequence is maximal, and the absolute difference between any two adjacent elements in the subsequence is at most \(M\).</p>
<p>If there are multiple solutions, print the lexicographically least.</p>
<p>An array \(b\) is a subsequence of \(a\) if \(b\) can be obtained by deleting some of the elements in \(a\). It is not required to delete any elements.</p>
...A Harder Contest '19 - Flipper 22019-10-17T23:34:00+00:002019-10-17T23:34:00+00:00https://mcpt.ca/problem/ahc19p3<div><p>Help [user:ssheep] solve this problem!</p>
<p>Define the prefix of an array as a sub-array from the beginning of the array up to an index. For example, the prefix of index \(3\) of the array \([1,2,3,4,5]\) would be \([1,2,3]\).</p>
<p>Define a prefix query when you take a prefix of the array, \(A\), and multiply all the elements in the prefix with \(-1\). Essentially, this operation flips the signs of the elements.</p>
<p>Given an array of \(N\) integers, find the maximum sum of the ele...Peter's Lightsabers2019-10-17T00:13:12+00:002019-10-17T00:13:12+00:00https://mcpt.ca/problem/lightsabers<div><p>Peter is a Star Wars nerd, and has \(N\) plastic lightsabers with various amounts of strength that he bought to play with his friends.
Unfortunately, Peter has no real life friends, and now needs to find something to do with his lightsabers.</p>
<p>Peter decides that he will put his lightsabers on display for all to see.
However, Peter is very picky about how this design must look.
Specifically, there must be between \(A\) and \(B\) lightsabers put on display, and any two adjacent light...Favourite Numbers2019-10-16T22:00:00+00:002019-10-16T22:00:00+00:00https://mcpt.ca/problem/favouritenum<div><p>Out of all the numbers that exist, [user:justinzhu] only likes some specific numbers. The only numbers that he like are numbers, if prime factorized, only contain the numbers 2 or 3. However, since [user:justinzhu] really likes to be number 1 (even though that never happens), the smallest number that he likes is the number 1.</p>
<p>Out of all these numbers, [user:justinzhu] would like for you to write a solution that finds the \(N^{th}\) smallest number that he likes.</p>
<p>Note that y...LCC/Moose '19 Contest 1 S3 - Chomp2019-10-15T00:40:29+00:002019-10-15T00:40:29+00:00https://mcpt.ca/problem/lcc19c1s3<div><p>Alice and Bob recently bought a few chocolate bars that they want to share and they decided to make a game out of eating them. Starting with Alice, they take turns picking a square of the bar, breaking off all of the squares above and/or to the right of that square, and eating the broken off pieces. The person who eats the last square loses. Here are two examples of valid moves (selected square marked with <code>X</code>):</p>
<pre><code>### #.. ... ...
#X# --> #.. , ##. --...LCC/Moose '19 Contest 1 S5 - Division Tests2019-10-15T00:34:33+00:002019-10-15T00:34:33+00:00https://mcpt.ca/problem/lcc19c1s5<div><p>A division test for a number \(K\) is a simple algorithm for checking some number is divisible by \(K\). The most well-known division tests are those for two: a number is divisible by two if its last digit is even; and for three: three divides a number if and only if three divides the sum of its digits.</p>
<p>Rosalina has learned a division test for all the numbers up to \(N\). She now wonders how useful this skill is. Specifically, she wants to know how many numbers less than or equal ...LCC/Moose '19 Contest 1 S4 - Morphgrams2019-10-15T00:27:36+00:002019-10-15T00:27:36+00:00https://mcpt.ca/problem/lcc19c1s4<div><p>Justine loves learning about the different ways in which words can be related. Recently, she learned about anagrams: a pair of words where the order of the letters of one word can be rearranged to form another. For example, "listen" is an anagram for "silent".</p>
<p>Learning about anagrams made Justine wonder: what if instead of changing the positions of the letters, the positions stay the same but the letters themselves change? Justine has decided to call such pairs of words morphgrams...LCC/Moose '19 Contest 1 S2 - Siege2019-10-15T00:10:36+00:002019-10-15T00:10:36+00:00https://mcpt.ca/problem/lcc19c1s2<div><p>Darbian is speedrunning a game that requires him to lay siege on a castle. The castle is in the shape of a square with \(N\) walls wrapping around it. Each wall is broken into sections of different heights.</p>
<p>Darbian sieges the castle by repeatedly picking a section of the outermost unbreached wall and scaling that section, which takes time equal to the height of the section. Once he reaches the top, the wall is considered breached, and he can immediately move onto breaching the nex...LCC/Moose '19 Contest 1 S1 - Travel Conflicts2019-10-15T00:03:26+00:002019-10-15T00:03:26+00:00https://mcpt.ca/problem/lcc19c1s1<div><p>Nadir is building a travel agent service which recommends potential vacations to clients based on their preference. One of the service's challenges is scheduling conflicts: if a person has booked a vacation, then no future recommendations should overlap with that vacation.</p>
<p>Nadir has asked you to help solve this problem by creating a program that, given two vacations, determines if they overlap.</p>
<h4>Input Specification</h4>
<p>The input consists of two lines, each describing a ...A Newton Problem2019-10-06T20:50:57+00:002019-10-06T20:50:57+00:00https://mcpt.ca/problem/anewtonproblem<div><p>Given \(A, B,\) and \(C\), and \(f(x) = Ax+B \sin(x)\), find when \(f(x)=C\).</p>
<h4>Input Specification</h4>
<p>The first line will contain three integers, \(A, B, C\) \((1 \le B \le A \le 10^5, 1 \le C \le 10^5)\).</p>
<h4>Output Specification</h4>
<p>Output a value of \(x\) where \(f(x)=C\). Your value of \(x\) will be considered correct if \(|f(x)-C| \le 10^{-5}\).</p>
<h4>Sample Input</h4>
<pre><code>1 1 20</code></pre>
<h4>Sample Output</h4>
<pre><code>19.4417867</code></pre>
</...LCC/Moose '19 Contest 1 J5 - Om and uwu2019-09-29T04:50:24+00:002019-09-29T04:50:24+00:00https://mcpt.ca/problem/lcc19c1j5<div><p>Om frequently uses "uwuwu" in his messages. Inspired to find the perfect message, he needs a way to quantify how good a message is. He defines the quality of a message as the number of substrings of the message that contain the subsequence "uwuwu". Given a string \(S\) consisting of lowercase English letters, determine the quality of the string.</p>
<p>We define a subsequence of a string \(S\) to be any string that can be obtained from \(S\) by deleting some (possibly no) characters from...A Stack Problem2019-09-26T04:14:59+00:002019-09-26T04:14:59+00:00https://mcpt.ca/problem/astackproblem<div><p>Josh felt bored during his lessons, so he took out some pennies, laid \(N\) \((1 \le N \le 3000)\) of them in a row and stacked the coins such that each coin rests on \(2\) other coins. He began wondering how many ways could you stack pennies on top of each other if there are \(N\) pennies on the bottom row. Josh couldn't figure it out so he passed the problem to you.</p>
<p>Given \(Q\) \((1 \le Q \le 1000)\) queries, output the number of ways to stack pennies if there were \(N\) pennies...A Counting Problem 32019-09-25T13:23:50+00:002019-09-25T13:23:50+00:00https://mcpt.ca/problem/acountingproblem3<div><p>Define a full binary tree as a binary tree where all nodes, except the leaves, in the tree have \(2\) children (the leaves have \(0\)). All nodes in levels except the bottom must have \(2\) children. The height is defined as the number of nodes in the path from the root to a leaf, including the root.</p>
<p>You are given a full binary tree with a height of \(N\) (\(0 \leq N \leq 10^7\)). Can you count the number of subtrees in the graph? Unlike the usual definition of subtree, a subtree ...A Tree Problem 22019-09-24T17:51:28+00:002019-09-24T17:51:28+00:00https://mcpt.ca/problem/atreeproblem2<div><p>Marcus has a tree with \(N\) nodes, numbered \(1\) through \(N\). The \(i^\text{th}\) edge in this tree connects nodes \(a_i\) and \(b_i\) and has a length of \(c_i\).</p>
<p>Marcus created a complete graph with \(N\) nodes. The length of the edge connecting nodes \(u\) and \(v\) in this graph is equal to the shortest distance between nodes \(u\) and \(v\) in the tree described above.</p>
<p>Marcus would like to know the length of the longest <em>Hamiltonian path</em> in this complete gr...A Vector Problem2019-09-24T17:51:28+00:002019-09-24T17:51:28+00:00https://mcpt.ca/problem/avectorproblem<div><p>Given a three-dimensional vector's components, find the magnitude of the vector.</p>
<h4>Input Specification</h4>
<p>The first line will contain three integers, \(u_x, u_y, u_z\) \((|u_x|, |u_y|, |u_z| \le 10^9)\), the components of the vector.</p>
<h4>Output Specification</h4>
<p>Output the magnitude of the vector, rounded to <strong>exactly</strong> three decimal places.</p>
<h4>Sample Input</h4>
<pre><code>2 3 -1</code></pre>
<h4>Sample Output</h4>
<pre><code>3.742</code></pre>
</di...