Recently Added OlympiadsOJ Problemshttps://oj.olympiads.ca/2020-02-16T04:32:43+00:00The latest problems added on the Olympiads Online Judge | DMOJ websiteA Permutation Problem 22020-02-16T04:32:43+00:002020-02-16T04:32:43+00:00https://oj.olympiads.ca/problem/invperm<div><p>Given 2 integers $$N$$ and $$K$$, find the lexicographically largest permutation of $$1, 2, 3 \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 \leq...Mock CCC '20 Contest 1 J5 - A Prime Problem2020-02-12T05:27:33+00:002020-02-12T05:27:33+00:00https://oj.olympiads.ca/problem/mockccc2020c1j5<div><p>[user:koosaga] likes numbers which are constructed by concatenating two prime numbers together. A number which can be formed by concatenating two primes that both have at least \(D$$ digits is a $$D$$-level prime pair certificate. Leading zeroes are not permitted.</p> <p>Given two integers $$D$$ and $$N$$, compute the smallest $$D$$-level prime pair certificate greater than or equal to $$N$$.</p> <h4>Constraints</h4> <p>The output will never exceed $$2 \cdot 10^9$$.</p> <p>There are no s...Mock CCC '20 Contest 1 J4 - A Binary Problem2020-02-12T05:27:20+00:002020-02-12T05:27:20+00:00https://oj.olympiads.ca/problem/mockccc2020c1j4<div><p>[user:koosaga] lives on a street with $$N$$ houses, all equally spaced apart. Each house either has the lights on or off. [user:koosaga] rates a house with a score equal to the minimum distance, in house units, that he must travel to be at a house that has its lights on.</p> <p>[user:koosaga] wants to compute the sum of the ratings of all the houses on his street.</p> <h4>Constraints</h4> <p>$$1 \le N \le 10^6$$</p> <p>In tests worth 5 marks, $$N \le 10^3$$.</p> <p>At least one house wil...Mock CCC '20 Contest 1 J3 - A Geometry Problem2020-02-12T05:27:04+00:002020-02-12T05:27:04+00:00https://oj.olympiads.ca/problem/mockccc2020c1j3<div><p>[user:koosaga] is drawing a logo for the next iteration of the KAIST contest. He has gotten lazy, so he has taken a rectangle of length $$X$$ and height $$Y$$ and drawn the two diagonals of the rectangle, forming four small triangles. He wishes to know the area of one of these triangles in the figure he has drawn.</p> <h4>Constraints</h4> <p>$$1 \le X, Y \le 10^9$$</p> <p>In tests worth 14 marks, $$\max(X, Y) \le 10$$.</p> <h4>Input Specification</h4> <p>The input will consist of two pos...Mock CCC '20 Contest 1 J2 - A Simplex Problem2020-02-12T05:26:40+00:002020-02-12T05:26:40+00:00https://oj.olympiads.ca/problem/mockccc2020c1j2<div><p>[user:koosaga] has been training hard for programming contests! One day, he decides to study linear programming, which invariably gets him to learn about the simplex algorithm.</p> <p>Unrelated to the simplex algorithm, [user:koosaga] has discovered that there are two things which spark joy in his life - cacti and matroids. If [user:koosaga] has $$C$$ cacti and $$M$$ matroids, then his joy is $$C U_c + M U_m$$.</p> <p>[user:koosaga] is a busy person though, so $$C + M$$ cannot be too lar...Mock CCC '20 Contest 1 J1 - A Rage Tree Problem2020-02-12T05:26:07+00:002020-02-12T05:26:07+00:00https://oj.olympiads.ca/problem/mockccc2020c1j1<div><p>[user:koosaga] has been training hard for programming contests! One day, he decides to pick up a new data structure, the rage tree.</p> <p>The rage tree efficiently supports operations on collections of integers - for example, it can be used to quickly find the minimum integer among a collection of integers or the maximum integer among a collection of integers.</p> <p>To ensure that he properly understands the mechanics of the rage tree data structure, he will use one to solve the follow...Wesley's Anger Contest 3 Bonus Problem - Game of Death2020-02-10T18:33:15+00:002020-02-10T18:33:15+00:00https://oj.olympiads.ca/problem/wac3bonus<div><p>The following problem was originally planned for problem 4 in <strong><a href="https://dmoj.ca/contest/wac3">Wesley's Anger Contest 3</a></strong>.</p> <p>There is a $$(2N + 1) \times (2N + 1)$$ grid of squares. Each square has an integer coordinate with the lower left square having the coordinate $$(-N, -N)$$, and the upper right square having the coordinate $$(N, N)$$. Each square is coloured either black or white.</p> <p>Initially, the entire grid is white, except for a single black s...Wesley's Anger Contest 3 Problem 7 - Mirrors2020-02-10T18:33:07+00:002020-02-10T18:33:07+00:00https://oj.olympiads.ca/problem/wac3p7<div><p>A set of $$N$$ double sided mirrors are scattered on an integer coordinate plane <strong>uniformly at random</strong>. For simplicity, the $$i^{th}$$ mirror can be thought of as a point at $$(x_i, y_i)$$ with an infinitesimally small radius. You will fire a laser starting at one of the mirrors in the direction of a different mirror. When a laser hits a mirror, it will reflect off the mirror and continue in its new direction until it hits another mirror (or forever if it never hits anothe...Wesley's Anger Contest 3 Problem 6 - Zeyu's Sadness Contest 12020-02-10T18:33:00+00:002020-02-10T18:33:00+00:00https://oj.olympiads.ca/problem/wac3p6<div><p>Zeyu is making his first ever Sadness Contest! His contest consists of $$M$$ problems (numbered from $$1$$ to $$M$$) with $$N$$ contestants participating (numbered from $$1$$ to $$N$$).</p> <p>The rules of his contests are as follows:</p> <ul> <li>The contest lasts for $$10\,000\,000$$ minutes.</li> <li>Each contestant may submit at most $$10\,000\,000$$ times to each problem.</li> <li>Contestants are ordered by the number of problems solved. The more problems they solved, the better the...Wesley's Anger Contest 3 Problem 5 - Triangle: The Root of All Evil2020-02-10T18:32:52+00:002020-02-10T18:32:52+00:00https://oj.olympiads.ca/problem/wac3p5<div><p>In a parallel universe, the least important data structure in computer science is the triangle. In fact, it is widely frowned upon to have a triangle in any way, shape, or form. As you are reading this the problem author is being locked up behind bars for mentioning the forbidden shape.</p> <p>You were recently given a shipment of $$N$$ rods for building structures. The $$i^{th}$$ rod has an integer length of $$l_i$$ and a value of $$v_i$$. To prevent a catastrophe, you need to remove s...Wesley's Anger Contest 3 Problem 4 - Canadian Construction Crew2020-02-10T18:32:44+00:002020-02-10T18:32:44+00:00https://oj.olympiads.ca/problem/wac3p4<div><p>The Canadian Construction Crew (CCC) is working on a new project! They have been tasked with paving the roads in a city. The road network can be modelled by a graph with $$N$$ vertices and some number of edges, with the vertices representing intersections, and the roads representing edges. Over $$Q$$ days, they will be given an additional requirement, specifying that a new road is to be paved between intersections $$a_i$$ and $$b_i$$, which requires their road paving machine to pave the ...Wesley's Anger Contest 3 Problem 3 - Wesley Plays DDR2020-02-10T18:32:35+00:002020-02-10T18:32:35+00:00https://oj.olympiads.ca/problem/wac3p3<div><p>Wesley has recently visited the arcade and has tasked himself with mastering all songs on Dance Dance Revolution. Unfortunately, the machine that Wesley has claimed is broken and is unable to keep track of his score. Can you help Wesley determine his final score?</p> <p>In Dance Dance Revolution, there are 4 different moves that can be played - up, down, left, and right.</p> <p>The song that Wesley plays consists of multiple beats and he will match each beat with a single move. Every mov...Wesley's Anger Contest 3 Problem 2 - Eat, Sleep, Code, Repeat2020-02-10T18:32:27+00:002020-02-10T18:32:27+00:00https://oj.olympiads.ca/problem/wac3p2<div><p>As an avid programmer, Carson likes to live by the following phrase:</p> <blockquote><p>"Eat, sleep, code, repeat."</p> </blockquote> <p>However, sometimes he does one task more than the others. When doing a self-assessment on his efficiency during a specific day, he has developed the following formula to measure his productivity.</p> <p>The formula is defined as $$E \cdot S \cdot C$$, where $$E$$, $$S$$, and $$C$$ are the number of hours in the day used on eating, sleeping, and coding r...Wesley's Anger Contest 3 Problem 1 - Snow Day Predictor2020-02-10T18:31:52+00:002020-02-10T18:31:52+00:00https://oj.olympiads.ca/problem/wac3p1<div><p>Being fed up with online snow day predictors and their inaccurate results, you have decided to take matters into your own hands and write your own snow day predictor.</p> <p>You are given the temperature $$T$$ (in Celsius), the total amount of snowfall $$D$$ (in centimetres), and the probability of freezing rain $$P$$ (as a percentage).</p> <p>A snow day will only occur if <strong>at least two</strong> of the following conditions are satisfied:</p> <ul> <li>The temperature is <strong>str...COCI '19 Contest 5 #5 Zapina2020-02-09T18:39:30+00:002020-02-09T18:39:30+00:00https://oj.olympiads.ca/problem/coci19c5p5<div><p>There is a total of $$N$$ young programmers which are preparing for the second part of competitive season during a winter camp in <del>Krapina</del> Zagreb. Mr. Malnar, a big promoter of order, discipline and hard work, told the programmers to form a line and gave each of them a certain number (possibly zero) tasks. He gave away a total of $$N$$ <strong>different</strong> tasks and he knows that the $$i$$-th programmer in line will be happy if they got exactly $$i$$ tasks.</p> <p>In how ...COCI '19 Contest 5 #4 Putovanje2020-02-09T18:39:19+00:002020-02-09T18:39:19+00:00https://oj.olympiads.ca/problem/coci19c5p4<div><p>Little Fabijan loves bars and travels. He wishes to drink <del>beer</del> coffee in each of the N towns in his country conveniently numbered from $$1$$ to $$N$$. The towns are connected via $$(N − 1)$$ bidirectional roads such that each town is reachable from any other town by traversing some of the roads. Fabijan decided to drink coffee in every town in order from town number $$1$$ to town number $$N$$. Therefore, he starts from town number $$1$$ (where he drinks his first coffee) and t...COCI '19 Contest 5 #3 Matching2020-02-09T18:38:29+00:002020-02-09T18:38:29+00:00https://oj.olympiads.ca/problem/coci19c5p3<div><p>You are given $$N$$, where $$N$$ is even, points on a plane that have integer coordinates. For each integer $$a$$, there are at most two points with coordinates $$(a, x)$$. Analogously, for each integer $$b$$, there are at most two points with coordinates $$(x, b)$$.</p> <p>You are able to draw horizontal or vertical line segments between pairs of given points. Is it possible to draw $$\frac{N}{2}$$ lines such that each of the given points is an endpoint of exactly one line segment and t...COCI '19 Contest 5 #2 Političari2020-02-09T18:33:48+00:002020-02-09T18:33:48+00:00https://oj.olympiads.ca/problem/coci19c5p2<div><p>All politicians of an unknown, completely invented and totally unrealistic country are spending their time accusing each other on national television instead of doing their jobs. It all started one Sunday afternoon when politician <strong>number 1</strong> was a guest in the first episode of a (now very popular) talk show. During the show, he accused the politician <strong>number 2</strong> for the poor state of the country. Naturally, in the second episode of the show the guest was poli...COCI '19 Contest 5 #1 Emacs2020-02-09T18:33:29+00:002020-02-09T18:33:29+00:00https://oj.olympiads.ca/problem/coci19c5p1<div><p>While playing in his favourite text editor, Daniel decided to draw a picture that was $$N$$ characters high and $$M$$ characters wide. The picture consists solely of characters <code>.</code> and <code>*</code> such that characters <code>*</code> form some non-overlapping rectangles. The rectangles don’t even touch each other on their sides or corners.</p> <p>Help Daniel count the number of rectangles drawn on the picture.</p> <h4>Input</h4> <p>The first line contains two integers $$N$$ ...Overflow2020-02-07T20:06:41+00:002020-02-07T20:06:41+00:00https://oj.olympiads.ca/problem/olep1<div><p>Joe is an economical man and he has found a new scheme to save some money! Joe wants to save money on his water bill, so he decides to collect rainwater. Joe has a row of $$N$$ water containers, all initially empty and each with a maximum capacity of $$v_i$$ liters of water. The containers are connected in such a way that when container $$i$$ overflows, the excess liquid flows to container $$i+1$$. When container $$N$$ overflows, the extra water magically disappears. Joe wishes to gather...Willie's Fan Club2020-02-04T23:01:28+00:002020-02-04T23:01:28+00:00https://oj.olympiads.ca/problem/williefanclub<div><p>Willie attends a party consisting of $$N$$ people, including himself. Everyone at the party is assigned a number between $$1$$ to $$N$$ and no two people will be assigned the same number.</p> <p>The following statements regarding the party are true,</p> <ul> <li>Everyone at the party knows Willie because everyone attending the party is part of Willie's Fan Club</li> <li>Willie does not know anyone at the party because he has too many fans</li> <li>Willie's fans occasionally hold gatherin...Link Cut Tree2020-01-28T23:17:43+00:002020-01-28T23:17:43+00:00https://oj.olympiads.ca/problem/lct<div><p>Larry was playing with a link cut tree last night. He has made $$Q$$ LCA queries to his link cut tree. Each time, the link cut tree responded with the integer representing the lowest common ancestor. He cut one too many edges and now he can't restore his tree. However, he will be satisfied with any tree that will give him the same results when asked the LCA queries again. Your task is to help him restore his tree. You will be given the $$Q$$ queries, and the result of those queries.</p> ...Figurines2020-01-21T18:06:38+00:002020-01-21T18:06:38+00:00https://oj.olympiads.ca/problem/figurines<div><p>Riolku has $$N$$ friends, labelled from $$1$$ to $$N$$. Him and his $$N$$ friends recently got into collecting figurines! However, since their parents don't want them wasting all their money, they can only have two figurines at a time.</p> <p>Each friend has one figurine that they consider "prized", and would never willingly give away, whereas they have another that they could trade, which we will call their "trade" figurine.</p> <p>Being figurine connoisseurs, Riolku and his friends kno...JSB '19 - P42020-01-07T02:23:33+00:002020-01-07T02:23:33+00:00https://oj.olympiads.ca/problem/jsb19p4<div><p>Please output the flag.</p> <p>Download the Java agent <a href="https://dmoj.algome.me/data/jsb19/p4/p4_agent.jar" rel="nofollow">here</a>.</p> <p>Download the source code of the agent <a href="https://dmoj.algome.me/data/jsb19/p4/p4_source.zip" rel="nofollow">here</a>.</p> <p>You can test locally using the command <code>java -javaagent:p4_agent.jar YourClass</code>.</p> <h4>Source Code</h4> <h6>File: <code>Agent.java</code></h6> <div class="codehilite"><pre><span></span><code><span clas...JSB '19 - P32020-01-07T02:23:32+00:002020-01-07T02:23:32+00:00https://oj.olympiads.ca/problem/jsb19p3<div><p>Please call the method <code>flag()</code> in the class <code>Secret</code>.</p> <p>Download the Java agent <a href="https://dmoj.algome.me/data/jsb19/p3/p3_agent.jar" rel="nofollow">here</a>.</p> <p>Download the source code of the agent <a href="https://dmoj.algome.me/data/jsb19/p3/p3_source.zip" rel="nofollow">here</a>.</p> <p>You can test locally using the command <code>java -javaagent:p3_agent.jar YourClass</code>.</p> <h4>Source Code</h4> <h6>File: <code>Agent.java</code></h6> <div ...