Recently Added MCPT Problemshttps://mcpt.ca/2020-01-19T00:14:50+00:00The latest problems added on the MCPT's Online Judge websiteSubarray GCD2020-01-19T00:14:50+00:002020-01-19T00:14:50+00:00https://mcpt.ca/problem/subarraygcd<div><p>Given an array $$A$$ of length $$N$$, count the number of distinct greatest common divisors (GCDs) of all subarrays of this array.</p> <p>We define the greatest common divisor of a subarray as the greatest common divisor of all the subarray's elements.</p> <h4>Input Specification</h4> <p>The first line of input will contain the integer $$N\ (1 \leq N \leq 10^5)$$, the length of the array $$A$$.</p> <p>The next line will contain $$N$$ space separated integers $$A_i\ (1 \leq A_i \leq 10^9)...A Squirrel Problem 22020-01-19T00:14:45+00:002020-01-19T00:14:45+00:00https://mcpt.ca/problem/asquirrelproblem2<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 eat the first $$r$$ snacks, halving their calorie value (rounding down). Please help [user:ChrisT]!</p> <h4>Input Specification</h4> <p>The first line contains the integer \...Over Optimization2020-01-19T00:14:41+00:002020-01-19T00:14:41+00:00https://mcpt.ca/problem/opt<div><p>There exists so many problems on MCPT that require a lot of optimization and implementing. To solve those problems, you must use algorithms that are more efficient <a href="https://docs.google.com/presentation/d/1GxtBgrwGvufWOuuQ6ooNJ5dJgxD45eSITGKb9boMArQ/edit?usp=sharing" rel="nofollow">like the ones we learned last week</a>, but those will be required in the later problems. However, let's assume that we are in a theoretical world where optimizing code is a lot simpler. In this world, ...MLE '19 Contest 3 P1 - PHP2019-12-29T20:10:10.532144+00:002019-12-29T20:10:10.532144+00:00https://mcpt.ca/problem/mle19c3p1<div><p>Your friend has a <strong>randomly-generated</strong> directed graph of $$N$$ nodes. This is a special graph. Each node will have an outdegree of at most one. That is, there will be at most one edge going out from each node. He does not want to tell you the graph, but will allow you to ask $$Q$$ questions of the form:</p> <ul> <li><code>? a b</code> Is $$a$$ a <strong>descendant</strong> of $$b$$? That is, is there a path that allows for you to travel from $$b$$ to $$a$$? If $$1 \le a, b...MLE '19 Contest 3 P2 - Depression2019-12-29T20:10:10+00:002019-12-29T20:10:10+00:00https://mcpt.ca/problem/mle19c3p2<div><p>You are given a tree consisting of \(N$$ nodes and $$N-1$$ edges. Each edge has a weight $$w_i$$ and each node as a value $$v_i$$. You can perform the following two operations on the tree any number of times:</p> <ul> <li>Double a node $$u$$'s value. In other words, $$v_u = v_u \times 2$$.</li> <li>Take an edge $$k$$ and divide (integer division) the edge's weight by the GCD (greatest common divisor) of the value of the nodes connected by the edge. In other words, $$w_k = \bigg\lfloor \f...MLE '19 Contest 4 P10 - ISO2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p10<div><p>Given two bidirectional <strong>graphs</strong> \(S$$ and $$T$$, can you determine if they are <a href="https://en.wikipedia.org/wiki/Graph_isomorphism" rel="nofollow">isomorphic</a>?</p> <h4>Input Specification</h4> <p>The first line will contain two integers, $$N, M$$ $$(1 \le N \le 8, 1 \le M \le N^2)$$, the number of nodes and edges in graph $$S$$ and graph $$T$$, respectively.</p> <p>The next $$M$$ lines will each contain two integers, $$a_i, b_i$$ $$(1 \le a_i, b_i \le N)$$, denoti...MLE '19 Contest 4 P8 - IOI Game2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p8<div><p>You and your friend are playing a game on a line of $$N$$ stones. Each stone has a value $$v_i$$. Alternating turns, starting from you, the following move is performed until there are no more stones:</p> <ul> <li>If there is only one stone, take that stone.</li> <li>Otherwise, take either stone $$1$$ or stone $$2$$. <ul> <li>If stone $$1$$ is taken, stone $$2$$ becomes the new stone $$1$$, stone $$3$$ becomes the new stone $$2$$, etc. </li> <li>If stone $$2$$ is taken, stone $$3$$ become...MLE '19 Contest 4 P7 - Desperate2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p7<div><p>A string $$S$$ consisting of $$N$$ lowercase latin characters is hashed using the following method:</p> <p>$hash(S) = \displaystyle \left( \sum_{i=1}^N S_i \times B^i \right) \bmod P$</p> <p>$$S_i$$ is the ASCII value of the $$i^\text{th}$$ (one-indexed) character of string $$S$$. $$B$$ and $$P$$ are values given to you.</p> <p>Given a string $$S$$, and integers $$B$$ and $$P$$, can you calculate $$hash(S)$$?</p> <h4>Input Specification</h4> <p>The first line will contain the integer \...MLE '19 Contest 4 P9 - Poggers2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p9<div><p>An array $$a$$ of $$N$$ integers can be transformed into a new array through this process:</p> <ul> <li>$$a_i$$ is modified to be the maximum of $$a_i$$ and $$a_{i+1}$$ for all $$1 \le i &lt; N$$.</li> </ul> <p>An array is <em>stable</em> if it remains the same after the above transformation is performed on the array. For example, $$[2,1,1,1]$$ is a <em>stable</em> array.</p> <p>It can be proven that array $$a$$, after a certain number of transformations, will result in a <em>stable</em>...MLE '19 Contest 4 P6 - No2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p6<div><p>Evan/Ninjaclashette is in terrible need of easy problems. He (or she :eyes:) wants to make $$N$$ number of problems before a certain deadline which is any time from <code>0:00 December 22 2019</code> to <code>23:59 December 22 2019</code>. Since he is making so many questions, he wants to plan out the maximum amount of time he can spend making each problem. Therefore, he asked you, just because you're totally trash at programming, to make a program to help him plan.</p> <p><strong>He wil...MLE '19 Contest 4 P5 - Geo2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p5<div><p>Given a set of $$N$$ points, find the smallest Manhattan distance between any two unique points.</p> <p>Manhattan distance between two points is defined as the total distance traveled parallel along the $$x$$-axis or $$y$$-axis.</p> <h4>Input Specification</h4> <p>The first line will contain the integer $$N$$ $$(2 \le N \le 1000)$$.</p> <p>The next $$N$$ lines will each contain two integers $$x$$ and $$y$$ $$(|x|,|y| \le 10^{18})$$, representing a point.</p> <h4>Output Specification</h4>...MLE '19 Contest 4 P3 - Convex Hull Tree2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p3<div><p>Implement a Convex Hull Tree.</p> <hr> <p>JUST KIDDING.</p> <p>Given an array of $$N$$ positive integers, print the minimum GCD (greatest common divisor) of the numbers in any non-empty subarray and the maximum GCD of the numbers in any non-empty subarray.</p> <h4>Input Specification</h4> <p>The first line will contain the integer $$N$$ $$(1 \le N \le 5000)$$, the number of elements in the array.</p> <p>The second line will contain $$N$$ integers, the array, $$v_i\ (1 \le v_i \le 10^9)$$...MLE '19 Contest 4 P4 - Wesley2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p4<div><p>Wesley has a broken Wesley++ template. He knows the bug is in the longest line in his template. Please print out the longest line.</p> <h4>Input Specification</h4> <p>The first line will contain the integer $$N$$ $$(1 \le N \le 100)$$, the number of lines.</p> <p>The next $$N$$ lines will each contain a string consisting solely of lowercase latin characters. The length of each line will be at most $$100$$.</p> <h4>Output Specification</h4> <p>Output the longest line in Wesley's template....MLE '19 Contest 4 P2 - Troll2019-12-26T17:16:00.253762+00:002019-12-26T17:16:00.253762+00:00https://mcpt.ca/problem/mle19c4p2<div><p>Given two integers $$a$$ and $$b$$, print $$|a| + |b|$$. $$|X|$$ denotes the absolute value of $$X$$.</p> <h4>Input Specification</h4> <p>The first line will contain two integers, $$a, b$$ $$(|a|, |b| \le 10^9)$$.</p> <h4>Output Specification</h4> <p>Output $$|a| + |b|$$.</p> <h4>Sample Input</h4> <pre><code>-3 0</code></pre> <h4>Sample Output</h4> <pre><code>3</code></pre> </div>...MLE '19 Contest 4 P1 - Hi2019-12-26T17:16:00+00:002019-12-26T17:16:00+00:00https://mcpt.ca/problem/mle19c4p1<div><p>A positive integer $$a$$ is called a solution to $$y = 3x + 5$$ if $$3 \times a + 5 = 0$$. Given $$a$$, can you determine if it is a solution?</p> <h4>Input Specification</h4> <p>The first line will contain the integer $$a$$ $$(1 \le a \le 100)$$.</p> <h4>Output Specification</h4> <p>If $$a$$ is a solution to $$y = 3x+5$$, output <code>SOLUTION</code>. Otherwise, output <code>NO</code>.</p> <h4>Sample Input</h4> <pre><code>1</code></pre> <h4>Sample Output</h4> <pre><code>NO</code></pre...Grid Paths2019-12-20T19:23:30+00:002019-12-20T19:23:30+00:00https://mcpt.ca/problem/gridpaths<div><p>In a grid of size $$W$$ by $$H$$ $$(1 \leq W,H \leq 10^6)$$, you are to determine the amount of paths from the square $$(1,1)$$ to the square $$(W,H)$$ that do not go through $$X$$ blocked off squares only moving to the right or up. $$(0 \leq X \leq 2)$$.</p> <h4>Input Specification</h4> <p>The first line will contain three integers, $$W$$, $$H$$, and $$X$$.</p> <p>The next $$X$$ lines will contain two integers $$x$$ and $$y$$. $$(1 \leq x \leq W)$$ $$(1 \leq y \leq H)$$</p> <h4>Output S...Array Distances2019-12-20T19:23:19+00:002019-12-20T19:23:19+00:00https://mcpt.ca/problem/arrdist<div><p>You have been given an array of $$N$$ unique integers (with starting index $$1$$) and $$Q$$ queries to perform. For each query, you are given an index $$j$$. For each integer in the array, you must calculate the product of the integer and the distance between their index and the given index $$j$$. That is, if the integer has index $$i$$ you must calculate $$x_i\times(|i-j|)$$. Output, for each query, the sum of the calculations for all integers in the array, modulo $$10^9+7$$.</p> <h4>In...insignificant trolling2019-12-20T19:23:11+00:002019-12-20T19:23:11+00:00https://mcpt.ca/problem/troll<div><p>Because people like to troll on <a href="https://mcpt.ca/problem/troll" rel="nofollow">P1</a>, [user:insignificant] is very worried about LCC. He realized that each of his $$N$$ teammates has a $$\frac{1}{M}$$ chance to troll during the contest. Help him find the chance that at least 1 person does not troll during the contest.</p> <p>Assume that trolling is an independent event. Then, $$P(A \cap B) = P(A) \times P(B)$$. In other words, the chance that event $$A$$ and $$B$$ occurs at the ...Middle Squares2019-12-14T02:09:27+00:002019-12-14T02:09:27+00:00https://mcpt.ca/problem/middlesquares<div><p>The middle-square method is a method used to generate a sequence of pseudorandom numbers. To generate a sequence $$a$$ of $$M$$-digit numbers, an $$M$$-digit number $$a_1$$ is chosen as the first number of the sequence. $$a_1$$ is squared, producing a $$2M$$ digit number (padded with leading zeroes if it has less than $$2M$$ digits). The middle $$M$$ digits of this square are used to form $$a_2$$, the next number in the sequence. This process is then repeated to generate more numbers.</p...Icebergs2019-12-14T02:05:41+00:002019-12-14T02:05:41+00:00https://mcpt.ca/problem/icebergs<div><p>As the navigator of the newly christened RMS Titanic II, you've been commissioned to plot the ship's course through the ocean, represented by an $$R$$ by $$C$$ grid. Keeping with the tradition of the biggest and best, the Titanic II is a large ship, with length $$L$$ and width $$W$$ $$(1 \le L \le R, 1 \le W \le C)$$. Not wanting awful newspaper headlines again, you decide that this time, you will do your best to avoid icebergs, which are represented by the character <code>#</code>. The ...Classified!2019-12-14T02:02:01+00:002019-12-14T02:02:01+00:00https://mcpt.ca/problem/classified<div><h4>Problem</h4> <p>Ben was having a great time <del>self-advertising</del> playing his own game, <strong>Classified</strong>, when he suddenly encountered a strange bug which caused him to somehow lose. After months of interrogation, he soon realized that the cause of his loss was not a bug, but simply him being bad at his own game. Since Ben was so tired of losing over, and over, and over again, he has asked YOU to perform this task for him - Create a program which will output the highest...Art Academy2019-12-14T02:00:53+00:002019-12-14T02:00:53+00:00https://mcpt.ca/problem/art<div><p>Welcome to [user:hewmatt10]'s <del>Basement</del> Art Academy!</p> <p>Today, we will be learning how to draw mountains. You will draw $$N$$ mountains, the $$i^{th}$$ of which has a height of $$h_i$$.</p> <p>Mountains are consisted only of <code>^</code>, which are separated by spaces.</p> <p>An example of a mountain would be:</p> <pre><code> ^ ^ ^ ^ ^ ^</code></pre> <p>When drawing <strong>multiple</strong> mountains, you should separate them by a space.</p> <pre><code> ^ ^ ^ ^ ^...LCC/Moose '19 Contest 3 J5 - Pesky Pascallions2019-12-14T01:44:35.693121+00:002019-12-14T01:44:35.693121+00:00https://mcpt.ca/problem/lcc19c3j5<div><p>Find the $$X_{th}$$ number, <strong>indexed from 0</strong>, in the $$N_{th}$$ row of <a href="https://en.wikipedia.org/wiki/Pascal%27s_triangle" rel="nofollow">Pascal's Triangle</a>.</p> <p>Below are the first few rows of pascal's triangle:</p> <pre><code> 1 0th Row 1 1 1st Row 1 2 1 2nd Row 1 3 3 1 3rd Row 1 4 6 4 1 4th Row</code></pre> <p>Each number is created by adding the two numbers directly above it.</p> <h4>Input Specification</h4> <p>The first...LCC/Moose '19 Contest 3 J4 - Hash2019-12-14T01:44:35.693121+00:002019-12-14T01:44:35.693121+00:00https://mcpt.ca/problem/lcc19c3j4<div><p>Any string can be "hashed" into some sequence of characters or integers. However, before we start hashing, let us define a simple procedure that can be operated on a string, called <em>folding</em> the string:</p> <ol> <li>First, add a <code>y</code> to the end of the string if the string has an odd length.</li> <li>Take the first and last character of string and convert each of them to a number between $$1$$ and $$26$$. If the character is <code>a</code>, it becomes the integer <code>1<...LCC/Moose '19 Contest 3 J3 - WELCOME TO MY MINE2019-12-14T01:44:35.693121+00:002019-12-14T01:44:35.693121+00:00https://mcpt.ca/problem/lcc19c3j3<div><p>After more than 3 years of complete dominance, <a href="https://www.youtube.com/channel/UCPT7fE_u4Q-ioN49Bi2G74Q" rel="nofollow">MineCraft Awesome Parodys</a> has a new competitor: <name>Theodore</name>. Since <name>Theodore</name> is bad at writing Minecraft parodies, he has decided to randomly generate them, but that creates a lot of songs not related to Minecraft. You have been tasked with checking to make sure the song lyrics involve enough Minecraft.</p> <p><name>Theodore</name> set...