Skip to content

Commit 929ea47

Browse files
committed
Try catalyst extension
1 parent fd127fa commit 929ea47

22 files changed

+20
-128
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"F. Diameter Cuts","contestId":"1499","problemIndex":"F","timeLimit":"2 seconds","memLimit":"256 megabytes","inputFormat":"standard input","outputFormat":"standard output","problemHtml":"<p>You are given an integer $$$k$$$ and an undirected tree, consisting of $$$n$$$ vertices.</p><p>The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree is the maximum length of a simple path between all pairs of vertices of this tree.</p><p>You are about to remove a set of edges from the tree. The tree splits into multiple smaller trees when the edges are removed. The set of edges is valid if all the resulting trees have diameter less than or equal to $$$k$$$.</p><p>Two sets of edges are different if there is an edge such that it appears in only one of the sets.</p><p>Count the number of valid sets of edges modulo $$$998\\,244\\,353$$$.</p>","inSpecsHtml":"<div class=\"section-title\">Input</div><p>The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 5000$$$, $$$0 \\le k \\le n - 1$$$)&#xA0;&#x2014; the number of vertices of the tree and the maximum allowed diameter, respectively.</p><p>Each of the next $$$n-1$$$ lines contains a description of an edge: two integers $$$v$$$ and $$$u$$$ ($$$1 \\le v, u \\le n$$$, $$$v \\neq u$$$).</p><p>The given edges form a tree.</p>","outSpecsHtml":"<div class=\"section-title\">Output</div><p>Print a single integer&#xA0;&#x2014; the number of valid sets of edges modulo $$$998\\,244\\,353$$$.</p>","noteHtml":"<div class=\"section-title\">Note</div><p>In the first example the diameter of the given tree is already less than or equal to $$$k$$$. Thus, you can choose any set of edges to remove and the resulting trees will have diameter less than or equal to $$$k$$$. There are $$$2^3$$$ sets, including the empty one.</p><p>In the second example you have to remove the only edge. Otherwise, the diameter will be $$$1$$$, which is greater than $$$0$$$.</p><p>Here are the trees for the third and the fourth examples: </p><center> <img class=\"tex-graphics\" src=\"https://espresso.codeforces.com/b32002c8fe21ac9d1296f3e4664b38c1d955c580.png\" style=\"max-width: 100.0%;max-height: 100.0%;\"> </center>","sampleTestcases":[{"id":1616243779399,"input":"4 3\n1 2\n1 3\n1 4\n","output":"8\n"},{"id":1616243779400,"input":"2 0\n1 2\n","output":"1\n"},{"id":1616243779401,"input":"6 2\n1 6\n2 4\n2 6\n3 6\n5 6\n","output":"25\n"},{"id":1616243779402,"input":"6 3\n1 2\n1 5\n2 3\n3 4\n5 6\n","output":"29\n"}],"submitUrl":"https://codeforces.com/contest/1499/submit","language":"c++"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"E. Chaotic Merge","contestId":"1499","problemIndex":"E","timeLimit":"2 seconds","memLimit":"256 megabytes","inputFormat":"standard input","outputFormat":"standard output","problemHtml":"<p>You are given two strings $$$x$$$ and $$$y$$$, both consist only of lowercase Latin letters. Let $$$|s|$$$ be the length of string $$$s$$$.</p><p>Let&apos;s call a sequence $$$a$$$ a merging sequence if it consists of exactly $$$|x|$$$ zeros and exactly $$$|y|$$$ ones in some order.</p><p>A merge $$$z$$$ is produced from a sequence $$$a$$$ by the following rules: </p><ul> <li> if $$$a_i=0$$$, then remove a letter from the beginning of $$$x$$$ and append it to the end of $$$z$$$; </li><li> if $$$a_i=1$$$, then remove a letter from the beginning of $$$y$$$ and append it to the end of $$$z$$$. </li></ul><p></p><p>Two merging sequences $$$a$$$ and $$$b$$$ are different if there is some position $$$i$$$ such that $$$a_i \\neq b_i$$$.</p><p>Let&apos;s call a string $$$z$$$ <span class=\"tex-font-style-it\">chaotic</span> if for all $$$i$$$ from $$$2$$$ to $$$|z|$$$ $$$z_{i-1} \\neq z_i$$$.</p><p>Let $$$s[l,r]$$$ for some $$$1 \\le l \\le r \\le |s|$$$ be a substring of consecutive letters of $$$s$$$, starting from position $$$l$$$ and ending at position $$$r$$$ inclusive.</p><p>Let $$$f(l_1, r_1, l_2, r_2)$$$ be the number of different merging sequences of $$$x[l_1,r_1]$$$ and $$$y[l_2,r_2]$$$ that produce <span class=\"tex-font-style-it\">chaotic</span> merges. Note that only non-empty substrings of $$$x$$$ and $$$y$$$ are considered.</p><p>Calculate $$$\\sum \\limits_{1 \\le l_1 \\le r_1 \\le |x| \\\\ 1 \\le l_2 \\le r_2 \\le |y|} f(l_1, r_1, l_2, r_2)$$$. Output the answer modulo $$$998\\,244\\,353$$$.</p>","inSpecsHtml":"<div class=\"section-title\">Input</div><p>The first line contains a string $$$x$$$ ($$$1 \\le |x| \\le 1000$$$).</p><p>The second line contains a string $$$y$$$ ($$$1 \\le |y| \\le 1000$$$).</p><p>Both strings consist only of lowercase Latin letters.</p>","outSpecsHtml":"<div class=\"section-title\">Output</div><p>Print a single integer&#xA0;&#x2014; the sum of $$$f(l_1, r_1, l_2, r_2)$$$ over $$$1 \\le l_1 \\le r_1 \\le |x|$$$ and $$$1 \\le l_2 \\le r_2 \\le |y|$$$ modulo $$$998\\,244\\,353$$$.</p>","noteHtml":"<div class=\"section-title\">Note</div><p>In the first example there are: </p><ul> <li> $$$6$$$ pairs of substrings &quot;<span class=\"tex-font-style-tt\">a</span>&quot; and &quot;<span class=\"tex-font-style-tt\">b</span>&quot;, each with valid merging sequences &quot;<span class=\"tex-font-style-tt\">01</span>&quot; and &quot;<span class=\"tex-font-style-tt\">10</span>&quot;; </li><li> $$$3$$$ pairs of substrings &quot;<span class=\"tex-font-style-tt\">a</span>&quot; and &quot;<span class=\"tex-font-style-tt\">bb</span>&quot;, each with a valid merging sequence &quot;<span class=\"tex-font-style-tt\">101</span>&quot;; </li><li> $$$4$$$ pairs of substrings &quot;<span class=\"tex-font-style-tt\">aa</span>&quot; and &quot;<span class=\"tex-font-style-tt\">b</span>&quot;, each with a valid merging sequence &quot;<span class=\"tex-font-style-tt\">010</span>&quot;; </li><li> $$$2$$$ pairs of substrings &quot;<span class=\"tex-font-style-tt\">aa</span>&quot; and &quot;<span class=\"tex-font-style-tt\">bb</span>&quot;, each with valid merging sequences &quot;<span class=\"tex-font-style-tt\">0101</span>&quot; and &quot;<span class=\"tex-font-style-tt\">1010</span>&quot;; </li><li> $$$2$$$ pairs of substrings &quot;<span class=\"tex-font-style-tt\">aaa</span>&quot; and &quot;<span class=\"tex-font-style-tt\">b</span>&quot;, each with no valid merging sequences; </li><li> $$$1$$$ pair of substrings &quot;<span class=\"tex-font-style-tt\">aaa</span>&quot; and &quot;<span class=\"tex-font-style-tt\">bb</span>&quot; with a valid merging sequence &quot;<span class=\"tex-font-style-tt\">01010</span>&quot;; </li></ul><p></p><p>Thus, the answer is $$$6 \\cdot 2 + 3 \\cdot 1 + 4 \\cdot 1 + 2 \\cdot 2 + 2 \\cdot 0 + 1 \\cdot 1 = 24$$$.</p>","sampleTestcases":[{"id":1616243777835,"input":"aaa\nbb\n","output":"24\n"},{"id":1616243777836,"input":"code\nforces\n","output":"1574\n"},{"id":1616243777837,"input":"aaaaa\naaa\n","output":"0\n"},{"id":1616243777838,"input":"justamassivetesttocheck\nhowwellyouhandlemodulooperations\n","output":"667387032\n"}],"submitUrl":"https://codeforces.com/contest/1499/submit","language":"c++"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"C. Minimum Grid Path","contestId":"1499","problemIndex":"C","timeLimit":"2 seconds","memLimit":"256 megabytes","inputFormat":"standard input","outputFormat":"standard output","problemHtml":"<p>Let&apos;s say you are standing on the $$$XY$$$-plane at point $$$(0, 0)$$$ and you want to reach point $$$(n, n)$$$.</p><p>You can move only in two directions: </p><ul> <li> to the <span class=\"tex-font-style-it\">right</span>, i.&#xA0;e. horizontally and in the direction that increase your $$$x$$$ coordinate, </li><li> or <span class=\"tex-font-style-it\">up</span>, i.&#xA0;e. vertically and in the direction that increase your $$$y$$$ coordinate. </li></ul><p></p><p>In other words, your path will have the following structure: </p><ul> <li> initially, you choose to go to the right or up; </li><li> then you go some <span class=\"tex-font-style-bf\">positive integer</span> distance in the chosen direction (distances can be chosen independently); </li><li> after that you change your direction (from right to up, or from up to right) and repeat the process. </li></ul><p></p><p>You don&apos;t like to change your direction too much, so you will make no more than $$$n - 1$$$ direction changes.</p><p>As a result, your path will be a polygonal chain from $$$(0, 0)$$$ to $$$(n, n)$$$, consisting of <span class=\"tex-font-style-bf\">at most</span> $$$n$$$ line segments where each segment has positive integer length and vertical and horizontal segments alternate.</p><p>Not all paths are equal. You have $$$n$$$ integers $$$c_1, c_2, \\dots, c_n$$$ where $$$c_i$$$ is the cost of the $$$i$$$-th segment.</p><p>Using these costs we can define the <span class=\"tex-font-style-it\">cost of the path</span> as the sum of lengths of the segments of this path multiplied by their cost, i.&#xA0;e. if the path consists of $$$k$$$ segments ($$$k \\le n$$$), then the cost of the path is equal to $$$\\sum\\limits_{i=1}^{k}{c_i \\cdot length_i}$$$ (segments are numbered from $$$1$$$ to $$$k$$$ in the order they are in the path).</p><p>Find the path of the minimum cost and print its cost.</p>","inSpecsHtml":"<div class=\"section-title\">Input</div><p>The first line contains the single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)&#xA0;&#x2014; the number of test cases.</p><p>The first line of each test case contains the single integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$).</p><p>The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \\dots, c_n$$$ ($$$1 \\le c_i \\le 10^9$$$)&#xA0;&#x2014; the costs of each segment.</p><p>It&apos;s guaranteed that the total sum of $$$n$$$ doesn&apos;t exceed $$$10^5$$$.</p>","outSpecsHtml":"<div class=\"section-title\">Output</div><p>For each test case, print the minimum possible cost of the path from $$$(0, 0)$$$ to $$$(n, n)$$$ consisting of at most $$$n$$$ alternating segments.</p>","noteHtml":"<div class=\"section-title\">Note</div><p>In the first test case, to reach $$$(2, 2)$$$ you need to make at least one turn, so your path will consist of exactly $$$2$$$ segments: one horizontal of length $$$2$$$ and one vertical of length $$$2$$$. The cost of the path will be equal to $$$2 \\cdot c_1 + 2 \\cdot c_2 = 26 + 176 = 202$$$.</p><p>In the second test case, one of the optimal paths consists of $$$3$$$ segments: the first segment of length $$$1$$$, the second segment of length $$$3$$$ and the third segment of length $$$2$$$.</p><p>The cost of the path is $$$1 \\cdot 2 + 3 \\cdot 3 + 2 \\cdot 1 = 13$$$.</p><p>In the third test case, one of the optimal paths consists of $$$4$$$ segments: the first segment of length $$$1$$$, the second one&#xA0;&#x2014; $$$1$$$, the third one&#xA0;&#x2014; $$$4$$$, the fourth one&#xA0;&#x2014; $$$4$$$. The cost of the path is $$$1 \\cdot 4 + 1 \\cdot 3 + 4 \\cdot 2 + 4 \\cdot 1 = 19$$$.</p>","sampleTestcases":[{"id":1616243774819,"input":"3\n2\n13 88\n3\n2 3 1\n5\n4 3 2 1 4\n","output":"202\n13\n19\n"}],"submitUrl":"https://codeforces.com/contest/1499/submit","language":"c++","langId":"54"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"G. Graph Coloring","contestId":"1499","problemIndex":"G","timeLimit":"7 seconds","memLimit":"1024 megabytes","inputFormat":"standard input","outputFormat":"standard output","problemHtml":"<p>You are given a bipartite graph consisting of $$$n_1$$$ vertices in the first part, $$$n_2$$$ vertices in the second part, and $$$m$$$ edges, numbered from $$$1$$$ to $$$m$$$. You have to color each edge into one of two colors, red and blue. You have to minimize the following value: $$$\\sum \\limits_{v \\in V} |r(v) - b(v)|$$$, where $$$V$$$ is the set of vertices of the graph, $$$r(v)$$$ is the number of red edges incident to $$$v$$$, and $$$b(v)$$$ is the number of blue edges incident to $$$v$$$.</p><p>Sounds classical and easy, right? Well, you have to process $$$q$$$ queries of the following format:</p><p></p><ul> <li> $$$1$$$ $$$v_1$$$ $$$v_2$$$ &#x2014; add a new edge connecting the vertex $$$v_1$$$ of the first part with the vertex $$$v_2$$$ of the second part. This edge gets a new index as follows: the first added edge gets the index $$$m + 1$$$, the second &#x2014; $$$m + 2$$$, and so on. After adding the edge, you have to print the <span class=\"tex-font-style-it\">hash</span> of the current optimal coloring (if there are multiple optimal colorings, print the <span class=\"tex-font-style-it\">hash</span> of any of them). <span class=\"tex-font-style-bf\">Actually, this hash won&apos;t be verified, you may print any number as the answer to this query, but you may be asked to produce the coloring having this hash</span>; </li><li> $$$2$$$ &#x2014; print the optimal coloring of the graph with the same <span class=\"tex-font-style-it\">hash</span> you printed while processing the previous query. The query of this type will only be asked after a query of type $$$1$$$, and there will be at most $$$10$$$ queries of this type. If there are multiple optimal colorings corresponding to this <span class=\"tex-font-style-it\">hash</span>, print any of them. </li></ul><p></p><p>Note that if an edge was red or blue in some coloring, it may change its color in next colorings.</p><p>The <span class=\"tex-font-style-it\">hash</span> of the coloring is calculated as follows: let $$$R$$$ be the set of indices of red edges, then the <span class=\"tex-font-style-it\">hash</span> is $$$(\\sum \\limits_{i \\in R} 2^i) \\bmod 998244353$$$.</p><p>Note that you should solve the problem in <span class=\"tex-font-style-tt\">online</span> mode. It means that you can&apos;t read the whole input at once. You can read each query only after writing the answer for the last query. Use functions <span class=\"tex-font-style-tt\">fflush</span> in <span class=\"tex-font-style-tt\">C++</span> and <span class=\"tex-font-style-tt\">BufferedWriter.flush</span> in <span class=\"tex-font-style-tt\">Java</span> languages after each writing in your program.</p>","inSpecsHtml":"<div class=\"section-title\">Input</div><p>The first line contains three integers $$$n_1$$$, $$$n_2$$$ and $$$m$$$ ($$$1 \\le n_1, n_2, m \\le 2 \\cdot 10^5$$$).</p><p>Then $$$m$$$ lines follow, the $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \\le x_i \\le n_1$$$; $$$1 \\le y_i \\le n_2$$$) meaning that the $$$i$$$-th edge connects the vertex $$$x_i$$$ from the first part and the vertex $$$y_i$$$ from the second part.</p><p>The next line contains one integer $$$q$$$ ($$$1 \\le q \\le 2 \\cdot 10^5$$$)&#xA0;&#x2014; the number of queries you have to process.</p><p>The next $$$q$$$ lines contain the queries in the format introduced in the statement.</p><p>Additional constraints on the input:</p><p></p><ul> <li> at any moment, the graph won&apos;t contain any multiple edges; </li><li> the queries of type $$$2$$$ are only asked if the previous query had type $$$1$$$; </li><li> there are at most $$$10$$$ queries of type $$$2$$$. </li></ul><p></p>","outSpecsHtml":"<div class=\"section-title\">Output</div><p>To answer a query of type $$$1$$$, print one integer&#xA0;&#x2014; the <span class=\"tex-font-style-it\">hash</span> of the optimal coloring.</p><p>To answer a query of type $$$2$$$, print one line. It should begin with the integer $$$k$$$&#xA0;&#x2014; the number of red edges. Then, $$$k$$$ <span class=\"tex-font-style-bf\">distinct</span> integer should follow&#xA0;&#x2014; the indices of <span class=\"tex-font-style-bf\">red</span> edges in your coloring, in any order. Each index should correspond to an existing edge, and the <span class=\"tex-font-style-it\">hash</span> of the coloring you produce should be equal to the <span class=\"tex-font-style-it\">hash</span> you printed as the answer to the previous query.</p><p>If there are multiple answers to a query, you may print any of them.</p>","noteHtml":null,"sampleTestcases":[{"id":1616243780874,"input":"3 4 2\n1 2\n3 4\n10\n1 1 3\n1 2 3\n2\n1 3 3\n2\n1 2 4\n2\n1 2 1\n1 1 1\n2\n","output":"8\n8\n1 3\n40\n2 3 5\n104\n3 5 6 3\n104\n360\n4 5 6 3 8\n"}],"submitUrl":"https://codeforces.com/contest/1499/submit","language":"c++"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"D. The Number of Pairs","contestId":"1499","problemIndex":"D","timeLimit":"2 seconds","memLimit":"512 megabytes","inputFormat":"standard input","outputFormat":"standard output","problemHtml":"<p>You are given three positive (greater than zero) integers $$$c$$$, $$$d$$$ and $$$x$$$. </p><p>You have to find the number of pairs of positive integers $$$(a, b)$$$ such that equality $$$c \\cdot lcm(a, b) - d \\cdot gcd(a, b) = x$$$ holds. Where $$$lcm(a, b)$$$ is the least common multiple of $$$a$$$ and $$$b$$$ and $$$gcd(a, b)$$$ is the greatest common divisor of $$$a$$$ and $$$b$$$.</p>","inSpecsHtml":"<div class=\"section-title\">Input</div><p>The first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) &#x2014; the number of test cases.</p><p>Each test case consists of one line containing three integer $$$c$$$, $$$d$$$ and $$$x$$$ ($$$1 \\le c, d, x \\le 10^7$$$).</p>","outSpecsHtml":"<div class=\"section-title\">Output</div><p>For each test case, print one integer &#x2014; the number of pairs ($$$a, b$$$) such that the above equality holds.</p>","noteHtml":"<div class=\"section-title\">Note</div><p>In the first example, the correct pairs are: ($$$1, 4$$$), ($$$4,1$$$), ($$$3, 6$$$), ($$$6, 3$$$).</p><p>In the second example, the correct pairs are: ($$$1, 2$$$), ($$$2, 1$$$), ($$$3, 3$$$).</p>","sampleTestcases":[{"id":1616243776133,"input":"4\n1 1 3\n4 2 6\n3 3 7\n2 7 25\n","output":"4\n3\n0\n8\n"}],"submitUrl":"https://codeforces.com/contest/1499/submit","language":"c++","langId":"54"}

0 commit comments

Comments
 (0)