Recently Added MCPT Problemshttps://mcpt.ca/2019-10-06T20:50:57+00:00The latest problems added on the MCPT's Online Judge websiteA 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>
</div...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 on th...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>
</div>...A Swapping Problem2019-09-24T17:51:28+00:002019-09-24T17:51:28+00:00https://mcpt.ca/problem/aswappingproblem<div><p>Given a one-indexed array \(a\) of \(N\) integers, you can perform the following operation an infinite number of times:</p>
<ul>
<li>Choose an index \(i\ (1 \le i \le N-3)\) and swap \(a_i\) and \(a_{i+3}\).</li>
</ul>
<p>Find the lexicographically smallest array after performing this operation any number of times.</p>
<h4>Input Specification</h4>
<p>The first line will contain the integer \(N\ (1 \le N \le 10^5)\), the number of elements.</p>
<p>The second line will contain \(N\) intege...Script Me2019-09-20T12:51:53+00:002019-09-20T12:51:53+00:00https://mcpt.ca/problem/scriptme<div><h4>Rules</h4>
<pre><code>()+() = ()() => [combine]
((()))+() = ((())()) => [absorb-right]
()+((())) = (()(())) => [absorb-left]
(())(())+() = (())(()()) => [combined-absorb-right]
()+(())(()) = (()())(()) => [combined-absorb-left]
(())(())+((())) = ((())(())(())) => [absorb-combined-right]
((()))+(())(()) = ((()...Frog2019-08-19T01:15:20+00:002019-08-19T01:15:20+00:00https://mcpt.ca/problem/frog<div><p>There are \(N\) stones, numbered \(1, 2, \ldots, N\). For each \(i\ (1 \le i \le N)\), the height of Stone \(i\) is \(h_i\). Here, \(h_1 \lt h_2 \lt \ldots \lt h_N\) holds.</p>
<p>There is a frog who is initially at Stone \(1\). He will repeat the following action some number of times to reach Stone \(N\):</p>
<ul>
<li>If the frog is currently on Stone \(i\), jump to one of the following stones: Stone \(i+1, i+2, \ldots, N\). Here, a cost of \((h_j - h_i)^2 + C\) is incurred, where \(j\)...Too Much Memory!2019-08-17T03:51:03+00:002019-08-17T03:51:03+00:00https://mcpt.ca/problem/mle<div><p>Everybody loves using memory: <a href="https://files.larry.science/f/wzhe1h3i.png" rel="nofollow">Chrome does it</a>, <a href="https://files.larry.science/f/y0z4m1nq.png" rel="nofollow">Discord loves it</a> and <a href="https://files.larry.science/f/oj37tu6j.png" rel="nofollow">Java is even infamous for it</a>. So today you are given a challenge: to use more then \(32\) megabytes of it!</p>
<p>There is just one catch: your code must only consist of exactly \(1\) character.</p>
<p>Good lu...A Harder Coin Problem2019-08-11T17:03:24+00:002019-08-11T17:03:24+00:00https://mcpt.ca/problem/ahardercoinproblem<div><p>Angie is going shopping!</p>
<p>She has \(N\) different types of coins in her pocket, with the \(i^{th}\) type of coin being worth \(d_i\) dollars, and she's going to \(V\) stores. From the \(j^{th}\) store, she wants to buy \(c_j\) dollars worth of stuff from store \(j\), but store \(j\) only accepts the first \(l_j\) types of coins in her pocket!</p>
<p>Can you help her figure out the minimum number of coins to pay for each transaction in exact change?</p>
<p>Note that for the purpose...Maintaining an Envelope2019-07-29T12:34:42+00:002019-07-29T12:34:42+00:00https://mcpt.ca/problem/lines<div><p>There is a 2D-plane where only lattice points with their x-coordinates from \(1\) to \(N\) are of interest.</p>
<p>Support the following operations:</p>
<ul>
<li><code>1 n m b</code> Add a line with an ID of \(n\) \((1 \leq n \leq Q)\) in the form of \(y = mx + b\) to the plane. All line IDs are guaranteed to be distinct.</li>
<li><code>2 n</code> Delete the line with an ID of \(n\). It is guaranteed that the line exists at this time.</li>
<li><code>3 c</code> Output the ID of the line t...Triples2019-07-25T02:27:06+00:002019-07-25T02:27:06+00:00https://mcpt.ca/problem/triples<div><p>Given an array of integers, \(a\), compute the number of unique ways to satisfy the equation \(a_i + a_j = a_k\), where \(i \neq j \neq k\) and \(a_i \leq a_j\). To be unique, each counted equation after being filled in must never have been counted before.</p>
<h4>Input Specification</h4>
<p>The first line will contain a single integer \(N\), \(3 \leq N \leq 5000\).</p>
<p>The next line will contain \(N\) space separated integers, describing the array. \(1 \leq a_i \leq 10^6\)</p>
<h4>Ou...Static Tree Test2019-07-20T20:28:34+00:002019-07-20T20:28:34+00:00https://mcpt.ca/problem/ds189<div><p>Given a unweighted tree rooted at of \(N\) nodes numbered from \(1\) to \(N\), rooted at Node \(1\), and each node \(u\) has a given initial value \(v_u\), support the following operations:</p>
<ul>
<li><code>1 u x</code>: Increment the subtree of node \(u\) by the value \(x\)</li>
<li><code>2 u v x</code>: Increment all nodes along the path from \(u\) to \(v\) by the value \(x\)</li>
<li><code>3 u</code>: Output the maximum value of all nodes in the subtree of \(u\)</li>
<li><code>4 u v...Fast Heavy-Light Decomposition2019-05-19T02:08:43+00:002019-05-19T02:08:43+00:00https://mcpt.ca/problem/hldfast<div><p>On an unweighted tree, there are \(N\) nodes and \(N - 1\) edges. The nodes are numbered from \(1\) to \(N\). All nodes \(i\) have a parent \(p_i\), except for the root node, for which \(p_i\) is \(0\). All nodes are able to reach the root by repeatedly going up the parent of the current node.</p>
<p>Initially, all nodes have a value of \(0\). Perform the following operation on each node \(i\):</p>
<p>Add \(x_i\) to the value of all nodes on the path from \(i\) to the root, including \(...A Cousin Problem2019-04-18T13:33:59+00:002019-04-18T13:33:59+00:00https://mcpt.ca/problem/cousin<div><p>There are \(N\) nodes with IDs from \(1\) to \(N\). All nodes, with the exception of Node \(1\), has a parent node with an ID less than itself. Each node has a value. The \(i^{\text{th}}\) node has a value of \(V_i\).</p>
<p>A \(k^{\text{th}}\) ancestor of a node is defined as follows:</p>
<ul>
<li>If \(k = 1\), the parent of the node</li>
<li>If \(k > 1\), the parent of the \((k - 1)^{\text{th}}\) ancestor of the node</li>
</ul>
<p>Two nodes are considered \(k^{\text{th}}\) cousins i...Girls Invitational '19 J1 - Ecalevol Triplets2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19j1<div><p>Finding Reppoh Ecarg too difficult a game, the children of Ada Land prefer to play the game of Ecalevol. This game is a lot simpler: a player draws \(3\) cards, and then exclaims <code>Ecalevol!</code> if they win, or <code>I lost.</code> if they lose.</p>
<p>All cards have an integer \(K\ (-100 \leq K \leq 100)\) on them. A hand is a winning hand if they can be arranged in an order where the first card divided by the second card, and then divided by the third card results in an integer....Girls Invitational '19 J2 - Emily Who2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19j2<div><p>Catherine has just gotten a new SIM card and is asking friends to text her their names so she can add their contacts to her new phone. However, she has run into a big problem: two of her friends are both named Emily Hu! Catherine knows that each Emily will get mad if she is mixed up with the other Emily, so she doesn't want to ask which Emily is messaging her. Instead, she decides to analyze their messages to see if she can use her knowledge of their personalities to figure out who is me...Girls Invitational '19 J4 - Who Will Win?2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19j4<div><p>Here at Mackenzie, we take great pride in our sports teams. Since winter has come to an end, our school's attention has shifted to the basketball team. They'll be competing for the best team in our region as they hope to make provincials.</p>
<p>In MCPT, we like to analyze other schools and assign power levels to each high school basketball team in our region, including ourselves. There is an upcoming single elimination round robin tournament where \(2^N\) teams will be competing.</p>
<d...Girls Invitational '19 J5 - Divisiblity2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19j5<div><p>Winnie has run out of backstory to give you, so she just gave you a question instead.</p>
<blockquote><p>Given a string \(A\) consisting of only integers, find the number of substrings of \(A\) that are divisible by \(9216\).</p>
</blockquote>
<h4>Input Specification</h4>
<p>The first line will contain a string \(A\ (1 \le |A| \le 2\ 000)\). \(A\) will only contain digits, and will not contain leading \(0\)s.</p>
<h4>Output Specification</h4>
<p>Output the number of substrings of \(A\) t...Girls Invitational '19 S4 - Miniature Sudoku2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19s4<div><p>The puzzle game Sudoku is a classical game. In the puzzle, the player is given a partially filled \(9 \times 9\) grid. The objective of the game is to fill in the grid such that each row, column, and each of the nine \(3 \times 3\) subgrids contain all the digits from \(1\) to \(9\).</p>
<div style="max-width: 100%;height: 275;max-height: 275;width: 275;text-align: center"><img src="https://mcpt.ca/texoid/9fa4d695e7d5deb4f38a4e383fa4a3ecc9b7d546/svg" onerror="this.src='//mcpt.ca/texoid/9...Girls Invitational '19 S1 - Evan's Essay2019-04-17T02:56:30.461135+00:002019-04-17T02:56:30.461135+00:00https://mcpt.ca/problem/gi19s1<div><p>Evan has just just finished writing an English essay about the importance of computer security and realizes that he used some words too much!</p>
<p>Can you help Evan write a program that finds the number of occurrences of a substring in a string and replace the \(N^{th}\) occurrence with a different string?</p>
<p>Evan would really appreciate it!</p>
<h4>Input Specification</h4>
<p>The first line will contain the string to search within.
<br>
The second line will contain the substring t...Girls Invitational '19 S3 - GOTO2019-04-17T02:56:30+00:002019-04-17T02:56:30+00:00https://mcpt.ca/problem/gi19s3<div><p>You are given a piece of code consisting of \(N\) lines from your friend! Unfortunately, your friend only knows the <code>GOTO</code>, <code>PRINT</code>, and <code>QUIT</code> statements, and has created a jumbled mess that you must now debug!</p>
<p>The description of each statement is as follows:</p>
<ul>
<li><code>GOTO i</code> Jump to line \(i\). If this statement is on line \(j\), it is guaranteed \(1 \le i \le N, i \ne j\). The lines are \(1\)-indexed.</li>
<li><code>PRINT k</code...Girls Invitational '19 S2 - Road Trip2019-04-17T02:56:30+00:002019-04-17T02:56:30+00:00https://mcpt.ca/problem/gi19s2<div><p>April is taking a road trip with her friends! April's world can be represented by a coordinate plane, where she starts at \((0,0)\). There are \(N\) attractions with coordinate positions she would like to visit. She must visit these coordinates in order, and can travel in a straight line between attractions.</p>
<p>Given a list of attractions to visit in order, can you calculate the total distance traveled?</p>
<h4>Input Specification</h4>
<p>The first line of input will contain one inte...Girls Invitational '19 J3 - Essay Scores2019-04-17T02:56:30+00:002019-04-17T02:56:30+00:00https://mcpt.ca/problem/gi19j3<div><p>You have just written an \(N\) line essay for English. Each line is numbered from \(1\) to \(N\), and line \(i\) is given a <em>value</em> of \(v_i\).</p>
<p>A paragraph is defined as a <em>subarray</em> of lines from the essay. Note that a paragraph may contain of a single line. The <em>score</em> of a paragraph is maximum <em>value</em> of any line in the paragraph. The <em>total score</em> of the essay is the sum of the <em>scores</em> of all the paragraphs.</p>
<p>Your teacher wants ...Girls Invitational '19 S5 - Dodgeball Club2019-04-17T02:56:30+00:002019-04-17T02:56:30+00:00https://mcpt.ca/problem/gi19s5<div><p>Kstar has found a new dodgeball club called the Anonymous Dodgeball Association (or ADA). The ADA loves laces, but more importantly, they love dodgeball, so let's focus on that.</p>
<p>The ADA has \(N\) members, who each have a unique ID from \(1\) to \(N\). Person \(i\) has a dodgeball skill level of \(A[i]\).
Some people are so bad that their skill level is negative.</p>
<p>There are two types of meetings: training meetings and game meetings.</p>
<p>At a training meeting, everyone prac...