You can use several words in query to find by all of them at the same time. In addition, if you are lucky search understands word forms and some synonyms. It supports search by title and author. Examples:

  • 305 — search for 305, most probably it will find blogs about the Round 305
  • andrew stankevich contests — search for words "andrew", "stankevich" and "contests" at the same time
  • user:mikemirzayanov title:testlib — search containing "testlib" in title by MikeMirzayanov
  • "vk cup" — use quotes to find phrase as is
  • title:educational — search in title

Results

1.
By Um_nik, history, 4 years ago, In English
Pro Tips - get them while they are free More tips to use while studying under my tutoring [here](https://um-nik.notion.site/Pro-Tips-8b923b0dc7c94770824bdf4184afc43c). ## Stop caring about the rating Unless there are prizes involved, your position in the standings makes no difference. I can feel awful after winning a contest if I know that I could solve one more problem. Or I can feel OK losing a bunch of rating points knowing that I solved everything I could.  Because rating is just a number. It is highly volatile and it depends on other people, not only on your skill. But solving problems is totally up to you. And you should evaluate yourself not based on some random metric, but on your honest feeling whether you performed up to your expectations. Your sense of self should be under your control, don't get hung up on some imaginary value, you cannot reduce your progress to a single number. ## Don't use more than one account Rating is just a number. Do not be afraid to lose your colour. You’ll get it back in no t...

Full text and comments »

  • Vote: I like it
  • +1119
  • Vote: I do not like it

2.
By zscoder, history, 7 years ago, In English
[Tutorial] Generating Functions in Competitive Programming (Part 1) Hi everyone! Inspired by the recent [Codeforces Round 641](https://codeforces.me/contest/1349), I decided to write an introductory tutorial on generating functions here. I am by no means an expert in generating functions so I will write about what I currently know about them. [user:MiFaFaOvO,2020-05-15] has written a really interesting [blog](https://codeforces.me/blog/entry/76447) here on Codeforces about more advanced applications of generating functions, but I think there is no English tutorial on the basics of this topic yet (or at least on CP sites). Thus, I would like to share about this topic here. I plan to split this tutorial into two parts. The first part (this post) will be an introduction to generating functions for those who have never learned about them at all, and some standard examples and showcases of generating functions. The second part will be a collection of several applications of generating functions in CP-style problems. If you are already familiar with ge...
{i\ge 1}i^{a_{i}} \cdot \displaystyle\prod_{i\ge 1}(a_{i}!)}$ (Hint: Assume the cycles are labelled

Full text and comments »

  • Vote: I like it
  • +1299
  • Vote: I do not like it

3.
By dario2994, 6 years ago, In English
About Problemsetting (for AtCoder and Codeforces) Since the amount of information available about the preparation of a competitive programming contest for AtCoder/Codeforces is very little, I decided to collect here what was my experience. I will try to both describe my experiences and give some general advice to wannabe problemsetters. I hope that this will be useful to future problemsetters who are "out of the loop". Moreover, participants might be curious to know what happens behind the scenes (and maybe the platforms may consider this as a form of constructive feedback). *Acronyms*: - AGC = Atcoder Grand Contest - GR = Codeforces Global Round ### Why I know something about problemsetting? I am in the competitive programming world since ~8 years: I have participated in IOI/ICPC/GCJ and a number of contests on AtCoder/Codeforces (and lately Codechef). I am not a top participant but, being in this world for so long, I know, more or less, all the standard tricks. Recently, I was the author of the *flagship conte...

Full text and comments »

  • Vote: I like it
  • +936
  • Vote: I do not like it

4.
By Um_nik, history, 5 years ago, In English
How to practice Competitive Programming [Um_nik version] CP is about solving problems fast. And as absurd as it may sound, I believe that <span style="color:blue">SOLVE</span> and <span style="color:red">FAST</span> are very different and almost independent parts, and you need to practice them separately. Let’s look at some <span style="color:red">contest</span>, like a CodeForces round. For the sake of simplicity let’s assume that every problem has some *difficulty*, which is a numerical value denoting how hard it is, bigger values correspond to harder problems (it is not true, but it is an ok-ish approximation, at least if we consider subjective difficulty for a fixed person). Contests are made for a wide range of participants, and problemsetters strive to make contests interesting for a wide range of participants, which means having a *smooth difficulty gradient*. Well... as smooth as it is possible with 5-6 problems. <spoiler summary="Graph 1"> ![ ](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/677e0ae2-a8df-4874-aff...
, or for a hint, just a yes/no question. Most of the time the answer will be “No”. In the case of a

Full text and comments »

  • Vote: I like it
  • +1117
  • Vote: I do not like it

5.
By Radewoosh, history, 8 years ago, In English
Blogewoosh #6 Hello, codeforces! Sorry for the long break, but the last weeks of holidays and the first weeks of academic year took my attention. I hope today's trick will make you forgive me. :P I invented this trick a few years ago, but for sure I wasn't first, and some of you already know it. Let's consider the following **interactive** task. There are $n$ ($1 \leq n \leq 10^5$) hidden integers $a_i$, each of them from range $[1, 10^{18}]$. You are allowed to ask at most $103000$ queries. In one query you can choose two integers $x$ and $y$ ($1 \leq x \leq n, 1 \leq y \leq 10^{18}$) and ask a question ''Is $a_x \geq y$?'' The task is to find the value of the greatest element in the hidden array. The checker **isn't** adaptive. Unfortunately, this task is only theoretical, and you cannot solve it anywhere, but it'll turn out, that solution can be handy in many other, much more complicated problems. [cut] $ $ Even beginners should be able to quickly come up with a solution which ask...
The limit on the number of queries slightly higher than the limit on $n$ should give us ahint: for

Full text and comments »

  • Vote: I like it
  • +1075
  • Vote: I do not like it

6.
By maomao90, 3 years ago, In English
Editorial for Hello 2024 ### [problem:1919a] Author: [user:maomao90,2024-01-02] <spoiler summary="Hint 1"> When does the game end? </spoiler> <spoiler summary="Solution"> Depending on whether the player chooses to exchange wallets with their opponent on step $1$, $1$ coins will be removed from either the opponent's wallet or the player's wallet. This means that if either of the players still has remaining coins, the game will not end as at least one of the choices will still be valid. The only way that the game ends is when both players have $0$ coins. Since each operation decreases the total amount of coins by exactly $1$, the only way for Alice to win the game is if $a + b$ is odd. </spoiler> <spoiler summary="Code"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if ((a + b) % 2 == 0) { cout << "Bob\n"; } else { cout << "Alice\n"; } } ...
Consider a dynamic programming approach. , Consider a greedy approach. , Consider starting with array $a = [1, 1, \ldots, 1, -1, -1, \ldots, -1, For some $i$ where $s_{i, i} = \mathtt{1}$, let $Z$ be a set containing, From hint 1, our new task now is to determine the amount of water, If $s_{i, i} = \mathtt{0}$, what should the value of $s_{j, i}$ be for, If isomorphism cannot be used, find a leaf edge of a lower depth than, If we want to add a new edge with depth $i$, we need to attach it to, Let $dp_{i, v}$ represent the minimum penalty when we are considering, Make use of isomorphism to handle the case in hint 4 where the largest, Speed up finding the minimum cut using a segment tree. , Speed up the transition by storing the state in a segment tree, Think about how you would construct matrix $s$ if you were given the, Try modelling this problem into a maximum flow problem. , Try rooting the tree at an **edge**. , Try solving the problem if the sum of elements of array $a$ is equal to, Try solving the problem if the values in each column are a constant. In, Try to find a lower bound. , Try using minimum cut to find the maximum flow. , Use $n - 2$ of query $2$ to find the distance of every edge to the root, Using hint 3, can we break down the problem into smaller sub-problems, We start with only the root edge, then add edges of depth $0$, followed, What does the distance of two leaves that share the same parent look, What happens if we delete two leaves that share the same parent, When $c_i$ and $z$ equals $10^{18}$, it means that all the remaining, When does the game end?

Full text and comments »

Tutorial of Hello 2024
  • Vote: I like it
  • +760
  • Vote: I do not like it

7.
By dario2994, 6 years ago, In English
Editorial of Global Round 11 #### General comments Broadly speaking, problems A-B-C-D were "div2 problems", while F-G-H were "strong grandmaster problems" (with E staying in the middle). I did not expect anyone to solve all the problems and thus I decided to give the scoring F+G=H (so that maybe someone would have solved H). <br><br> Many of the problems (A, C, D, E, G) admit multiple solutions. Sometimes the core of the solution is the same (C, D) and sometimes the solutions are truly different (A, E, G). <br><br> If you are an experienced participant, I would like to hear your opinion on the problems. Feel free to comment on this post or send me a private message. <br><br> <spoiler summary="Overview of the problemset" > The easiest problem of the contest, *A-Avoiding Zero*, is about rearranging an array of numbers. It is intended as a very easy problem that still requires to think. Then, in *B-Chess Cheater* an intuitive (but nontrivial to prove) greedy approach is the way to go. *C-The Hard Work of P...
summary="A" > If $a_1 + \cdots + a_n = 0$, then the answer is NO, summary="Hint 1" >If $a_1 + \cdots + a_n = 0$, then the answer is NO.

Full text and comments »

  • Vote: I like it
  • +758
  • Vote: I do not like it

8.
By Errichto, 6 years ago, In English
Matrix Exponentiation tutorial + training contest tl;dr &mdash; video tutorial https://www.youtube.com/watch?v=eMXNWcbw75E and codeforces GYM training https://codeforces.me/gym/102644 (register by finding this contest in GYM instead of using the link directly) video editorial: [part 1 (ABCDEF)](https://www.youtube.com/watch?v=kQuCOFzWoa0) and [part 2 (GHI)](https://www.youtube.com/watch?v=RA_SpxP2t54) codes to all 9 problems: https://github.com/Errichto/youtube/tree/master/matrix-exponentiation Prerequisites: binary exponentiation and iterative dp (you don't need to know matrices) The youtube tutorial ([link](https://www.youtube.com/watch?v=eMXNWcbw75E)) focuses on intuition and graph-like visualization . Or, if you prefer, below is a shorter (less detailed) text tutorial instead. You can practice by solving a set of 9 educational problems in GYM https://codeforces.me/gym/102644. ABCD are easy, EF medium, GHI are hard. If you are stuck, see hints below or watch the full solution analysis &mdash; [part 1 (ABCDEF)](https:...

Full text and comments »

  • Vote: I like it
  • +606
  • Vote: I do not like it

9.
By dario2994, 5 years ago, In English
Codeforces Global Round 15 <img src="/predownloaded/2e/e2/2ee2f0f95f05aae6ca6f47812dae2dc2aabf277b.png" style="width:200px; float:right; margin: 0 1em 1em 1em"/> Hi! On [contest_time:1552] we will host [contest:1552]. This is the third round of the 2021 series of [Codeforces Global Rounds](https://codeforces.me/blog/entry/65002). The rounds are open and rated for everybody. The prizes for this round are as follows: - 30 best participants get a t-shirt. - 20 t-shirts are randomly distributed among those with ranks between 31 and 500, inclusive. The prizes for the 6-round series in 2021: - In each round top-100 participants get points according to the [table](https://pastebin.com/QT5sXEaT). - The final result for each participant is equal to the sum of points he gets in the four rounds he placed the highest. - The best 20 participants over all series get sweatshirts and place certificates. Thanks to XTX, which in 2021 supported the global rounds initiative! Problems for this round ar...

Full text and comments »

Announcement of Codeforces Global Round 15
  • Vote: I like it
  • +823
  • Vote: I do not like it

10.
By adamant, history, 19 months ago, In English
Complex FFT is not as bad as you think ... Probably. Hi everyone! As some of you _might_ already know, I don't like NTT. Primary reasons for this are: - I don't like modular arithmetic optimizations (Montgomery, etc). - I don't like NTT mods, and prefer good, old $10^9+7$. - I do like algebra of complex numbers. But, to my regret, the overwhelming mainstream in modern competitive programming is NTT. Primary reasons are: - It's allegedly faster. - It needs less memory. - It has no precision issues. - People don't like algebra of complex numbers. There is nothing I can do about the last, but today I'll address the first 3. Optimizing complex FFT was on my mind for quite some time, but I didn't really work on it _that much_ until the [blog](https://codeforces.me/blog/entry/142063) by [user:Qwerty1232,2025-04-24] on optimizing NTT has dropped, which motivated me to actually put some serious effort into this. In this blog, we will primarily focus on optimizations that are specific to complex arithmetic...
the actual output, I couldn't find any way at all to hint compiler to use `_mm256_mul_epu32

Full text and comments »

  • Vote: I like it
  • +731
  • Vote: I do not like it

11.
By -is-this-fft-, history, 6 years ago, In English
How to ask for help in PM There was a blog today with a similar title, and although it was (I think, not really sure as I didn't get a good look) some kind of satire/joke blog, I wanted to post some serious advice about things I (don't) like to see when people are PMing me. However I decided that this wouldn't be in the spirit of the blog and decided to make a separate blog. And now that blog is deleted anyway. While it's not a bad thing to write messages to more experienced users, most people who write me do things that make them very difficult to deal with. These are my opinions, but somewhy I feel that many reds will agree. Some things here feel silly to write because they are so obvious. But I'm only writing them because people regularly mess them up. [cut] $~$ ####Use punctuation and spelling. There are some [very simple rules](https://codeforces.me/blog/entry/82186#comment-689836) that make your messages infinitely more readable. I find it especially strange when many of these messagers call...

Full text and comments »

  • Vote: I like it
  • +746
  • Vote: I do not like it

12.
By twosquares, 11 months ago, In English
Good Bye 2025 Editorial We'd like to thank you all for participating in the contest, and hope you enjoyed it. Any feedback would be appreciated! <!-- You lost the game. --> <spoiler summary="Rate the contest"> - Great contest: - Good contest: - Average contest: - Bad contest: </spoiler> --- <spoiler summary="Did Franklin (from problem D) succeed in massacring a village of innocent elves like Frieren and Dilhan (from problem E)?"> The official lore is that he got lost in a forest of oddly colored Christmas trees (from problem F) and decided instead to write this editorial. </spoiler> <!-- ########### --> <!-- #PROBLEM A# --> <!-- ########### --> <h2>[problem:2178A]</h2> <spoiler summary="Did you like the problem?"> - Great problem: - Good problem: - Average problem: - Bad problem: - Did not solve: ...
$m=0$ must be handled separately (why?). The hardest part is killing, Although we considered the operations for a given type of present, Assume there are no flatten operations after the final concatenate (why, Based on Hint 2, try to characterize the set of edges that cannot be, Consider the connected components formed by the parent edge of all, Consider the number of 'Yes's in the string, and what happens to this, Exactly one child will not be chosen by Santa. If we fix/decide which, Figure out how to count the number of chains containing a specific, Figure out how we can compute the number of chains ending at chord $1, Find an upper bound on the number of elves that can survive., Fix the $m$ surviving elves. They must have attacked. Who are the, From the previous hint, the final array can be split into the two, How can you tell which array was flattened more times? , If one array was flattened more times than the other, which contains, If we tried to merge all three presents into a single graph, the, In a single operation, what are some shared properties of the vertices, It may be easier to start with no presents (but eventually force, Once the elves that survive are fixed, and the elves they attack are, One of the color classes of the bipartite graph must have size at most, Recurse. , The input essentially just creates a graph, where cities are connected, The input graph is bipartite. , The number of children on the naughty and nice lists combined will be, The operation is clearly independent for each present. Solve the, The problem forces you to incrementally compute the values for $\ell=1, The two arrays were flattened from some common ancestor — i.e, There is one big idea that you need from here, the following small, Try drawing the operation on some not small graphs! , Try finding an equivalent formulation to what the explosiveness can, Try to solve the problem for only $\ell=n$., We can brute force over all possible subsets of the smaller bipartite, What are the invariants of the operation? , What are the properties/invariants of the flatten operation? Use this, What can we say about the number of 'Yes's. , What does the conquered condition mean in terms of these, You have a suspicious string. For a fixed u, suppose the closest s is, You have a suspicious string. Suppose there are two consecutive u's, You have yet to use the fact that we want every chord to appear, You only care about parity. Figure out how to speed this up to $O(n, $ you store the parity of number of chains ending at chord $I$. Then, the value inHint 1.2 can be, : [user:conqueror_of_tourist,2025-12-27] What can we say about the number

Full text and comments »

Tutorial of Good Bye 2025
Tags sus
  • Vote: I like it
  • +697
  • Vote: I do not like it

13.
By Xellos, history, 11 years ago, In English
Codeforces Round #333 — editorial ### Hints: [div2A](#div2A): Try conversions between bases. [div2B](#div2B): Solve a simpler version of the problem where $A_{i+1} \neq A_i$ for all $i$. [div1A](#div1A): What are the shortest paths of the vehicles? what's the shorter of those paths? [div1B](#div1B): Forget about the ceiling function. Draw points $(i,A[i])$ and lines between them &mdash; what's the Lipschitz constant geometrically? [div1C](#div1C): Some dynamic programming. Definitely not for the exp. score of one person &mdash; look at fixed scores instead. [div1D](#div1D): Compute $dif(v)$ in $O(N)$ (without hashing) and then solve the problem in $O(N^2)$. You need some smart merges. [div1E](#div1E): Can you solve the problem without events of type 1 or 2? Also, how about solving it offline &mdash; as queries on subsets. ![ ](https://i.imgur.com/bnWmD60.png) ### <a name="div2A"></a>Div. 2 A: Two Bases ------------------------------------ It's easy to compare two numbers if the same bas...

Full text and comments »

  • Vote: I like it
  • +490
  • Vote: I do not like it

14.
By platelet, 3 years ago, In English
CodeTON Round 5 Editorial ### [problem:1842A] <spoiler summary="Tutorial"> Let's view it as when monsters $x$ and $y$ fight, their health changes into $\max(x-y,0)$ and $\max(y-x,0)$ respectively. So any monster with $0$ health is considered dead. Therefore, a player loses when the health of his monsters are all $0$. Notice that $\max(x-y,0)=x-\min(x,y)$ and $\max(y-x,0)=y-\min(x,y)$. Therefore, after each step, the sum of the health of monsters decrease by the same amount for both players. Therefore, we only need to know $\sum a_i$ and $\sum b_i$ to determine who wins. If $\sum a_i > \sum b_i$, Tsondu wins. Else if $\sum a_i < \sum b_i$, Tenzing wins. Else, it is a draw. </spoiler> <spoiler summary="Code"> ~~~~~ #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int T; cin >> T; while (T--) { int n, m, a[50], b[50]; long long sumA = 0, sumB = 0; cin >> n >> m; for (int i = 0; i < n;...
DP+divide and conquer , How to solve it if you want to cut exactly $m$ edges ? , Ignoring time complexity for now, how do we calculate the answer? The, Sort all variables $x_i$ by $\min(x_i,1-x_i)$ and enumerate the sorted

Full text and comments »

  • Vote: I like it
  • +573
  • Vote: I do not like it

15.
By zscoder, history, 10 years ago, In English
[Tutorial] Non-trivial DP Tricks and Techniques Hi everyone! Today I want to share some DP tricks and techniques that I have seen from some problems. I think this will be helpful for those who just started doing DP. Sometimes the tutorials are very brief and assumes the reader already understand the technique so it will be hard for people who are new to the technique to understand it. Note : You should know how to do basic DP before reading the post DP + Bitmasks ------------------ This is actually a very well-known technique and most people should already know this. This trick is usually used when one of the variables have very small constraints that can allow exponential solutions. The classic example is applying it to solve the Travelling Salesman Problem in $O(n^{2} \cdot 2^{n})$ time. We let $dp[i][j]$ be the minimum time needed to visit the vertices in the set denoted by $i$ and ending at vertex $j$. Note that $i$ will iterate through all possible subsets of the vertices and thus the number of states is $O(2^{n} \cdo...

Full text and comments »

  • Vote: I like it
  • +612
  • Vote: I do not like it

16.
By Errichto, 10 years ago, In English
Good Bye 2016 — hints and codes You can download my codes to all problems [here](http://www.filedropper.com/codes_1). I will write a full editorial in the next few days. Now you can read hints and short solutions. [problem:750B] <spoiler summary="hint"> Create a variable that will denote your current distance from the North Pole. What are allowed values of this variable? When can't we go West or East? </spoiler> [problem:750C] <spoiler summary="hint1"> Let $x$ denote the initial rating (or his final rating, whatever is easier for you to think about). The information that Limak is in some division in the $i$-th contest gives us some inequality for $x$. Can you see it? </spoiler> <spoiler summary="hint2"> For every contest we know that the current rating is $x$ increased by some prefix sum of c_i (changes of rating). If Limak is in the division 1, we have inequality x+prefSum >= 1900 so we have x >= 1900-prefSum. If Limak is in the division 2, we have inequality x_prefSum <= 1899 so it is ...
Create a variable that will denote your current distance from the North, the i-th digit to x". This is a big hint. , :750B] Create a variable that will denote your current distance from the

Full text and comments »

Tutorial of Good Bye 2016
  • Vote: I like it
  • +168
  • Vote: I do not like it

17.
By TheScrasse, history, 3 years ago, In English
Editorial of Pinely Round 3 (Div. 1 + Div. 2) The official implementations of all the problems are [here](https://drive.google.com/file/d/1q2PHS9nJt84FRwfMoiMslQULFE4dTMU4/view?usp=sharing). <spoiler summary="Timeline of the round proposal (may contain spoilers)"> (problems D', H', etc. were not used) - Feb 19, 2022: I proposed problem D' to [contest:1654], but it was not used. - Mar 13, 2023: I invented problem A. - May 16: I invented problem H'. - May 19: I realized problem G can be solved in $O(n)$ time and we used it in the Italian team selection test for IOI. - Jul 04: I opened a Div. 1 proposal containing A, D', G, H' and other problems which are not going to be used. - Aug 09: I invented problem I, with intended solution in $O(n^3)$. - Sep 27: I invented problem C. - Oct 14: [user:errorgorn,2023-12-23] replied to my contest proposal. - Nov 02: I invented problem D''. [user:errorgorn,2023-12-23] solved problem I in $O(n^2 \log n)$. - Nov 08: I invented problems E and F. I didn't propose problem F because I th...
$\texttt{A}$ will always remain $\texttt{A}$. For each $\texttt{B, $k = 2$ works in many cases. What if it does not work? , After Hints 3 and 4, the array is sorted. Prove it (it will be useful, Answer to Hint 6:, Assign $\texttt{B}$ to the indices $i$ such that $a_i < a_{i-1}$ and, Assign bigger costs to shorter intervals. , Binomials are compatible with NTT. , Do you notice any similarities between the cases with $k = 0$ and with, Draw a $n \times n$ grid, with tokens in $(i, p_i)$. Which constraints, Find a clean way to visualize the problem. , Find a strategy that turns "few" lamps on in most cases. , Find a strategy which is as simple and "easy to handle" as possible, Find a value of $k$ that works in many cases. , First, for each $i$ from left to right, do the operation on $[j, i, For each $\texttt{B}$, you can precompute the number of moves needed, For example, you can use a segment tree with the following information, If $k = 2$ does not work, either all the numbers are even or all the, If the strategy in Hint 2 does not work, at most $3$ lamps must be on, If you remove the condition $s = x+y+z$, the problem becomes harder, Insert the elements into the permutation in some comfortable order, Iterate over all subsets of at most $3$ lamps that must be on at the, Only perform operations such that all swapped pairs have $a_i > a_{i+1, Pressing all the buttons turns $\lfloor \sqrt n \rfloor$ lamps on, Repeat the same algorithm from right to left. , Solve for a fixed $|y|$ (length of $y$). , Solve the following case: $l = [1, 2]$, $r = [3, 4]$, $c = [1, 2]$. Can, Solve the problem with $k = 0$. , Solve the problem with $n = 2$. , Solve the problem with generic $k$. When is the answer $-1$? , Split each shape into $2$ rectangles and iterate over the number of, Suppose $m$ is even. You can insert elements in the order $[m/2, m/2, Suppose you can only use $\texttt{U}$, $\texttt{R}$, $\texttt{D, Suppose you have found a valid $y$. Shift it one position to the right, The first part of the DP (where you insert both "small" and "big, The rest of the proof (i.e., what happens during the process in Hint 4, The second part of the DP can be replaced with combinatorics formulas, The valid $y$ with $|y| = l$ start in consecutive positions. , Using the same idea of the proof of Hint 4, you can find all the valid, You can solve for a single $m$ with DP. Can you calculate the DP for, You have some "L" shapes, and each of them must contain a fixed number, You have to find the longest $\texttt{AB} \dots \texttt{AB}$ ending in, Now let's find an efficient implementation. We have to use the properties in Hint 7.

Full text and comments »

  • Vote: I like it
  • +354
  • Vote: I do not like it

18.
By MikeMirzayanov, 8 years ago, translation, In English
Codeforces: Results of 2018 Hi Codeforces! February 2019 is already on the calendar, which means that I was late with the report for 2018. Better late than never! Let's remember last year. In 2018, [user:_kun_,2019-02-05], [user:300iq,2019-02-05] and [user:arsijo,2019-02-05] joined the team of coordinators. The work of the coordinators is headed (and is the coordinator of the coordinators) [user:KAN,2019-02-05]. I really hope that a more measured schedule of preparing rounds by a large team of coordinators will give a better insight into the contests. The main innovations in the platform are implemented by me and the developers [user:kuviman,2019-02-05], [user:fcspartakm,2019-02-05], [user:MaximShipko,2019-02-05]. Great work on the organization of events and prizes mailing was done by [user:gKseni,2019-02-05]. Special thanks to the writers of the problems and testers. It is your content that charges the community with life and unites all of us. Thank you for the problems! And now let's summarize...

Full text and comments »

  • Vote: I like it
  • +871
  • Vote: I do not like it

19.
By Errichto, 7 years ago, In English
Bitwise operations 2 — popcount & bitsets Part 1 ([link](https://codeforces.me/blog/entry/73490)) introduces basic bitwise operations. This is part 2 and it's mainly about (in)famous bitsets and example problems. Also, see links to very useful advanced stuff at the bottom. EDIT: here's [video version](https://www.youtube.com/watch?v=jqJ5s077OKo&list=PLl0KD3g-oDOHpWRyyGBUJ9jmul0lUOD80) of this blog (on my Youtube channel). ### Built-in functions In C++, `__builtin_popcount(x)` returns popcount of a number &mdash; the number of ones in the binary representation of $x$. Use `__builtin_popcountll(x)` for long longs. There are also `__builtin_clz` and `__builtin_ctz` (and their long long versions) for counting the number of leading or trailing zeros in a **positive** number. Read more [here](https://www.geeksforgeeks.org/builtin-functions-gcc-compiler/). Now, try to solve these two simple tasks in $O(1)$, then open the spoiler to check the solution: <spoiler summary="Compute the biggest power of 2 that is a divisor o...
Represent adjacency of a vertex in bitmask.

Full text and comments »

  • Vote: I like it
  • +326
  • Vote: I do not like it

20.
By ToxicPie9, 3 years ago, In English
You won't believe how this simple trick defeated the unexplained bug destroying every top LGM ### TL;DR Currently people are discussing a slowdown bug on Codeforces that seems to happen randomly, and can cause code to run 100x slower and get TLE. More details in [user:pajenegod,2024-03-03]'s [blog post](https://codeforces.me/blog/entry/126654). In this article, I present a mitigation: add the following to your code. ~~~~ #include <windows.h> void *operator new(size_t size) { if (void *ptr = HeapAlloc(GetProcessHeap(), 0, size ? size : 1)) return ptr; throw std::bad_alloc{}; } void operator delete(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } ~~~~ <spoiler summary="If you use malloc/free in C++ (you shouldn't), also change them."> ~~~~ void *my_malloc(size_t size) { if (void *ptr = HeapAlloc(GetProcessHeap(), 0, size ? size : 1)) return ptr; throw std::bad_alloc{}; } void my_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } ~~~~ </spoiler> <spoiler summary="If you use aligned new/delete in C++, also change the...

Full text and comments »

  • Vote: I like it
  • +794
  • Vote: I do not like it

21.
By kpw29, 6 years ago, In English
Meet IT Codeforces Round Editorial Thank you very much for taking part in the contest! <spoiler summary="Contest timeline"> - -0:05. Starting the chat with the Questions Answering team: [user:tnowak,2020-11-15] and our beloved coordinator [user:antontrygubO_o,2020-11-15]. We hope that there won't be that many questions :) - -0:01. One minute to go! I hope that everything goes smoothly. I'm so afraid of posting the editorial accidentally that I moved this timeline into another blog... - 0:01. First blood in Div2! Congratulations to [user:majorro,2020-11-15]!. - 0:03. First blood in Div1 as well! Congratulations to [user:Errichto,2020-11-15], your knapsack is ready for a journey to win! - 0:04. [user:Sho10,2020-11-15] first to solve Div2B. Well done! - 0:05. We also have the first question. So far so good... - 0:06. [user:Um_nik,2020-11-15] gets the first pretests pass in Div1B. The cheaters are caught! - 0:09. [user:bandiaoz,2020-11-15] packs the first Knapsack in Div2! A difficulty spike is coming... - 0:12....
A bit of thinking may lead you to the observation that, Are there any items which you can put in the knapsack to fulfill the goal, Binary search is your friend. To determine if the answer is bigger, Let's look at the most significant bit, and group the numbers into two, The operation in the $i$-th turn is equivalent to selecting one element, This is a dynamic programming problem. Recall the DP calculating the, We want to minimize the number of negative numbers as much as we can by, We're only interested in differences between the elements. Is there, What can you say about the values which are the most frequent ones in the

Full text and comments »

  • Vote: I like it
  • +515
  • Vote: I do not like it

22.
By snowysecret, 5 years ago, In English
Editorial for Codeforces Round #761 (Div. 2) Thanks for participating, hope you enjoyed the problems! Implementations for the problems are chosen randomly among testers, and I made some changes to their codes (for example, deleted meaningless comment lines). Please do not hesitate to provide feedback in the comments, so I can improve in setting problems next time. **UPD**: Sorry but there is a checker bug in problem E. All submissions of problem E will be rejudged soon. **UPD2:** Rejudge done, the round remains rated. <spoiler summary="Statistics"> Number of FST for rated participants: - Problem A: $29$ - Problem B: $90$ - Problem C: $12$ - Problem D1: $4$ - Problem D2: $0$ - Problem E: $6$ Number of AK: $22$ Number of clarifications: $85$ </spoiler> [problem:1617A] <spoiler summary="Hint"> When is the lexicographically smallest permutation of $S$ (i.e. the sorted string) not the answer? </spoiler> <spoiler summary="Solution"> If there are no occurrences of `a`, `b` or `c` in $S$, ...
Aim to find an impostor and a crewmate's index in $\frac{n}{3} + c, Any specific algorithm to solve the problem (in Hint 1)? , Assume a tuple (group of $3$) is $0$-majority. There are $4, Consider splitting the $n$ players into groups of $3$ (and query each, Draw out the graph, for $a_i \le 10$. What special property does the, For any two positive integers $x$, $y$ that satisfy $x \ge y$, what is, If you know the index of one crewmate and one impostor, how to find the, The weird constraint, $\frac{n}{3} < k < \frac{2n}{3}$, is crucial, There must exist a solution for $c=1$ under the given constraints, Translate the problem into a graph problem. What feature of the graph, When is the lexicographically smallest permutation of $S$ (i.e. the, You have the index of an impostor and a crewmate now, and around $\frac

Full text and comments »

  • Vote: I like it
  • +425
  • Vote: I do not like it

23.
By cip999, 5 years ago, In English
Editorial of Global Round 15 We hope you liked the problems! Before we go ahead with the editorial, let us make some general comments about this round. Problems A, B, C, D, E, F are "div 2" problems, while problems G, H, I are meant to be solved by Grandmasters. Overall, our goal was to provide a problemset that could be enjoyable for a wide range of participants and such that the winner could solve all the problems. There were three big "jumps" in the difficlty gaps between consecutive problems. Problems A and B are meant to be easy, many contestants have the skills and the techniques to attack them (and, maybe, to solve them). Problems C, D, E, F are gradually harder but the difficulty gap between C and F is not as large as usual (and this is reflected in the score distribution). The same holds for problem G, H, I; the difficulty gap between G and I is relatively small (but there is a big score difference because coding I is much harder). Sadly, we discovered 14 minutes into the round that problem I...
$(k - 1)\left\lceil \frac{n}{k - 1} \right\rceil \ge n$., A *quantum array* is a $0$-$1$ array so that some entries can be both, All such portals must be active., Ask a query with all points. The result is a simple expression in terms, Ask only queries of the form $(di, \, j): 1 \le i \le \lfloor \frac{200, Binary search on the $2$-adic evaluation of the number of points on the, Consider the graph induced by the edges $(j, \, k)$ so that $a_i = b_j, Distinct connected components are independent., For sure, one must permute the $k$ characters by sorting them, For the $t$-th chunk, only consider (among the remaining colors) the, For which values of $d$ is $f(d)$ nicely related to $f(1)$?, How many quantum arrays will this algorithm have to deal with, If a character is not among the $k$ shuffled characters, then it must, If a character is not in the correct position, then it must belong to, If two chords do not intersect, "swapping them" so that they intersect, If we repeat the above-described strategy, we will end up with a, If you are at position $x$, what can you say on the state of portals, It is always convenient to choose $a_i, \, b_i$ so that the color $i, Let $S_i$ be the singers liked by friend $i$. Consider the graph on the, Maybe put in some randomization?, Morally, the problem is equivalent to finding the maximum of an array, Order the candidate intervals (defined as above) by second endpoint, Scan the sorted intervals and always select one if you are allowed to, Such graph contains $n$ vertices and $n$ edges, so it has a cycle, Testing only arrays with $0$ and $1$ is sufficient (why?)., The "superiority" relationship induces a complete directed graph with, The above condition is necessary and sufficient., The perimeter is twice the base plus twice the height. Figure out them, The sum, with the right signs, of the $a_i$ over the vertices of a, The valid orderings have a rigid structure., There can be at most one athlete who is superior to everyone else, There is only one configuration so that all added chords intersect, Try to come up with a greedy algorithm., Try to optimize the obvious quadratic solution., Try to solve the problem under the assumption that initially all, Up to obvious identifications, each connected component has exactly $0, You must compute the time necessary to go from $x_i$ to $x_i$ again

Full text and comments »

  • Vote: I like it
  • +533
  • Vote: I do not like it

24.
By Um_nik, history, 4 years ago, In English
MIT Mystery Hunt Disclaimer: This blog is not about competitive programming; you probably will not learn anything about algorithms and data structures. In other words, it doesn't qualify for [this initiative](https://codeforces.me/blog/entry/110840), but I want to give a link to it anyways because I think it's cool. I love solving problems. No, seriously. I LOVE it. The mindset described in [this blog](https://codeforces.me/blog/entry/91114) is 100% how I feel. But it is not constrained to competitive programming problems. I loved math problems for a much longer time, and physics was somewhere there. But I also love solving puzzles. And playing puzzle games on the computer (well, on consoles). And participating in intellectual games. I am not as good in them as in cp, but it was never about being good for me, I just love the process. And I think that there might be some people with a similar love for puzzles among competitive programmers, this is why I decided to write this blog on CF <s>and no...
here. But the hint was to watch broadcast after hour four, not right after., Around 2 am in the night I thought that we should request a hint. The hint was "Read the flavor, The hint says "What does "output" mean in the context of ICPC problems? You'll need some

Full text and comments »

  • Vote: I like it
  • +356
  • Vote: I do not like it

25.
By -14, history, 4 years ago, In English
ChatGPT passed ABC280D under human coaching [ChatGPT](https://openai.com/blog/chatgpt/) is a NLP model released recently, and I found it unexpectedly strong. Here's the evidence. [The Problem : ABC 280 D](https://atcoder.jp/contests/abc280/tasks/abc280_d) You are given an integer $K$ greater than or equal to $2$. Find the minimum positive integer $N$ such that $N!$ is a multiple of $K$. Here, $N!$ denotes the factorial of $N$. Under the Constraints of this problem, we can prove that such an $N$ always exists. Constraint: $2 \leq K \leq 10 ^ {12}$ [ChatGPT correct submission](https://atcoder.jp/contests/abc280/submissions/37030555) Here are the interactions. ChatGPT spoke Chinese to me (which I didn't figure out how to configure it), so I'd provide some translations here. --- **Human**: (The problem statement with hint to use long long) **ChatGPT**: We can use code to implement the above algorithm. (Code follows) ![ ](/predownloaded/d8/42/d8421bdc886cfeab1543ec0f1076ce94e4809502.png) --- *...
**Human**: (The problem statement with hint to use long long)

Full text and comments »

  • Vote: I like it
  • +509
  • Vote: I do not like it

26.
By Arpa, history, 10 years ago, In English
Codeforces Round #383 editorial Hello again, and hope you have been Joon-Joon of the round :P **I’m preparing harder version of some of the problems (Div.2 A, B, and Div.1 A, D) and I’ll put them on some gym, so if you are interested in harder version of problems please wait for about one week.** You can see and download the problem archives (pretests, **tests**, statements, validator, checker, **solutions**) [here](https://mega.nz/#F!GoB1gCjK!fE_6d5qSSiqt_HMxAmV9GQ). You can see solutions in solutions folder, note that there are several codes there, there is a descriptor for each code (.desc) that shows the verdict of that code. Preparation details: -------------------- On 25 May [user:Sa1378,2016-12-06] came up with problem Div.1 D and other problems authored inchmeal. 9/25/16: Proposal sent to Gleb. 11/12/16: Answer from Gleb: Your proposal has been redirected to Nikolay [user:KAN,2017-06-02]. 11/15/16: Nikolay has replied, and commented about problems, saying some problems are easy, s...

Full text and comments »

  • Vote: I like it
  • +438
  • Vote: I do not like it

27.
By Ari, history, 6 years ago, In English
Codeforces Round #715 Editorial <strike>Note: I can't figure out how to place the tutorials inside spoilers. If someone is familiar with how CF spoilers work and can help I would really appreciate it. For now, be warned that the tutorials are visible by default (but everything else isn't)</strike> **UPD:** I figured out how to use spoilers! Also added implementations for all problems. Thanks for participating in our contest! [problem:1509A] Author: [user:Kuroni,2021-04-13] <br> First solve: [user:cfg0d,2021-04-16] at 00:01:02 <spoiler summary = "Hint"> How can you write the condition that $\frac{a_u + a_v}{2}$ is an integer in a more useful way? Think of the parities. </spoiler> <spoiler summary = "Tutorial"> [tutorial:1509A] </spoiler> <spoiler summary = "Comments from the authors"> ![ ](https://i.imgur.com/voR4hTu.png) </spoiler> [Implementation](https://codeforces.me/contest/1509/submission/113263196) [problem:1509B] Author: [user:Ari,2021-04-13] <br> First solve: [user:bl...
Any permutation can be split into one or more cycles. What can we do, Consider two of the strings. We can obviously achieve our goal using, During the process, we will repeatedly push the same label down until, Either $00\dots 0$ or $11\dots 1$ is a subsequence of each string, Exactly one unassigned edge ends up with a non-zero weight. If we, Find a long common subsequence that has a simple structure. You'll, For each node, the order of the labels of its children stays fixed, How can we solve this problem without the restriction that the xor of, How can we use the previous observation to characterize edges, How can we use the previous observations to identify the state of the, How can you write the condition that $\frac{a_u + a_v}{2}$ is an, How many almost sorted permutations of length $n$ exist? In other, It is always possible to find the sequence. , Leave the xor sum of the weights of the unassigned edges in the, Look at the children of a particular vertex. What can we say about, Start by solving the problem for $q$-encodings only. , There's a simple algorithm that fixes a point and repeatedly moves, Two options — either solve recursively in a greedy fashion or, Use Mo's algorithm on the input intervals to find the relevant edges, Use dynamic programming. , We can get an encoding by including every possible edge. Which of, We need to solve the full version now. For a vertex $u$, how do the, We would like to merge all cycles of the permutation by swapping, What does the previous observation look like from the perspective of, What is the discrepancy of the last stage? How can we make it smaller, What is the general structure of an almost sorted permutation?, When does the solution to the unrestricted problem fail for the real, You can think of the partition as associating to each $M$ character a

Full text and comments »

  • Vote: I like it
  • +413
  • Vote: I do not like it

28.
By DeadlyCritic, history, 6 years ago, In English
Codeforces Round #652 (Div. 2) Editorial ####[A. FashionabLee :](https://codeforces.me/contest/1369/problem/A) Invented by [user:DeadlyCritic,2020-06-16]. <spoiler summary="Brief Solution"> $\mathcal Brief\;\mathcal Solution :$ A $n$-regular convex polygon is beautiful if and only if $n \% 4 = 0$. ($\%$ is the modular arithmetic symbol) </spoiler> <spoiler summary="Complete Proof"> [tutorial:1369A] </spoiler> <spoiler summary="Python solution"> ~~~~~ t = int(input()) for testcase in range(t): n = int(input()) if(n%4 == 0) : print("Yes") else : print("No") ~~~~~ </spoiler> <spoiler summary="C++ solution"> ~~~~~ #include <iostream> using namespace std; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; if(n % 4 == 0){ cout << "YES\n"; } else cout << "NO\n"; } } ~~~~~ </spoiler> ####[B. AccurateLee :](https://codeforces.me/contest/1369/problem/B) Invente...

Full text and comments »

  • Vote: I like it
  • +402
  • Vote: I do not like it

29.
By _Seele_Vollerei_, history, 4 months ago, In English
Report: Contest-Time Solution Hints Linked to NotOnlySuccess I am writing this blog to report a competitive-integrity issue involving the Codeforces user [user:NotOnlySuccess,2026-08-09] and a website associated with their content. The main issue is simple: **problem-specific solution material and hints for an ongoing Codeforces contest were made available before the contest ended.** # 1. Solution material published before the contest ended During [Codeforces Round 1116 (Div. 1, Div. 2)](https://codeforces.me/blog/entry/155668), an article titled [CF Round 1116 (Div. 1+2)](https://mp.weixin.qq.com/s/P3QJqmQFRsLlW9GX_y_8YQ) was published on a WeChat public account at August 10, 2026, 00:37 (UTC +8). The Codeforces contest ended at August 10, 2026, 01:05 (UTC +8). Therefore, the article was publicly available **28 minutes before the contest ended**. ![ ](/predownloaded/e5/8e/e58ea523bd7a61b7bdd20d83d2d16a0672f1cca0.png) The article already contained problem-specific solution material. For readers who do not understand Chinese...
$x \le y \le z$, the answer is $\min(z-x, y)$. This is substantially more than a generichint, A hint does not need to contain complete code or the entire solution to be valuable., A participant in the official Codeforces contest can open the mirror contest, wait until ahint, Calling such information a "heuristic hint" does not change its effect on an ongoing contest., Here is an example of the hint interface:, Regardless of whether one calls this a "hint", an "editorial", or something else, this is problem, This is substantially more than a generic hint such as "try greedy". It gives the key structural

Full text and comments »

  • Vote: I like it
  • +282
  • Vote: I do not like it

30.
By feecIe6418, 4 years ago, In English
Editorial of Codeforces Global Round 21 Thanks for participation! If your solution to D involves any data structures and is not $O(n)$ -- please read the "solution 1". I believe it is very interesting, but to make the difficulty suitable for D we allowed not $O(n)$ solutions. [problem:1696A] <spoiler summary="Hint 1"> How many operations will we perform? <spoiler summary="Answer"> At most one. Why? </spoiler> </spoiler> <spoiler summary="Solution"> Suppose we can only perform exactly one operation. In this case the answer is $S=\max_{1\le i\le n}(a_i\mathrm{\ or\ }z)$. In fact, we can prove that this is the answer. Define $a_i'$ as the value of $a_i$ after some operations. It suffices to prove the answer will never exceed $S$. Note that $z$ will always become a submask of itself after any number of operations, so $a_i$ will always be a submask of $(a_i\mathrm{\ or\ }z)$ after any number of operations. This leads to the conclusion that $a_i'\le (a_i\mathrm{\ or\ }z)$ for all $i$. Thus $\max_{1\le i...
Consider the case when $n=2$. Draw the linear programming on a xOy, Consider the dual. , Find a way to calculate the maximum product that can be turned into, How many operations will we perform?, How to check if the array can be destroyed in $0$ or $1$ operations, Instead of trying to construct the shortest path from $1, Look at the last sample test case. Think of a simple, Suppose the maximum element is $a_k$. Solve recursively, Suppose we aleady know edge $(i,j)$ exists in the tree. What can we, The answer is the sum of $f(i,j)$ over all white cells $(i,j)$. Use, The operation is reversible. (The two operations are reverses of each, The solution does not contain painful casework and deadly implemention, The solution is $O(n)$. We don't need any data, Try to find a middle state, such that we can turn both $a$ and $b$ into, Try to find out the number of operations we do on a specific cell $(i,j, Use data structures to simulate the process. How, Use monotonicity to reduce the complexity. , What kind of problem is this problem?, Write the recurrence formula for $f(i,j)$. What is $f(i,j)$?

Full text and comments »

  • Vote: I like it
  • +332
  • Vote: I do not like it

31.
By duality, 3 years ago, In English
Codeforces Round #884 (Div. 1 + Div. 2) Editorial Video editorials for [B](https://www.youtube.com/watch?v=5nzUni8dFLQ), [C](https://www.youtube.com/watch?v=8mz7gnAJ5QM), and [D](https://www.youtube.com/watch?v=ahnNAwpGwHc) are available on [user:ak2006,2023-07-11]'s channel. ### [problem:1844A] <spoiler summary="Hint 1"> There exists a small $n$ where the second player can win. </spoiler> <spoiler summary="Hint 2"> If $a \ge 2$, then $n = 1$ works. </spoiler> <spoiler summary="Solution"> [tutorial:1844A] </spoiler> <spoiler summary="Implementation"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t,a,b; scanf("%d",&t); while (t--) { scanf("%d %d",&a,&b); printf("%d\n",a+b); } return 0; } ~~~~~ </spoiler> ### [problem:1844B] <spoiler summary="Hint 1"> In order for $(l,r)$ to contribute to the primality, we must have $\operatorname{MEX}(a_l,\dots,a_r) \ge 2$, so there is some value $1$ between indices $l$ and $r$. </spoiler> <spoile...
After solving the equations modulo $2$, we can similarly solve modulo, Consider the set of even-indexed particles and the set of odd-indexed, Consider the smallest positive integer that does not divide $n, Describe, using a graph, all the pairs of characters in $s$ that need, Draw a `/` or `\` for each $2 \times 2$ subgrid, If $a \ge 2$, then $n = 1$ works. , In order for $(l,r)$ to contribute to the primality, we must have, Let $f(a,b) = f(a,b,0)$. Write down not one, but two recurrence, Model the problem as a system of linear equations. , Note that $f(a,b,c) = (a+b+c)f(a,b,c-1)$ (choose the next object of any, Solve the case $c \ge 0$ first. There is a very simple description of, Solve the equations modulo $2$ first, so that the $2x_{\text{lca}(i,i+1, The answer is the sum of some subset of $c_1,\dots,c_n$. Think about, The condition is actually equivalent to ($a_{i-1}-a_{i+1} \le |c|$ or, The intended solution does not do anything like attempt to maintain, The partially formed permutation is composed of several paths and, The problem reduces to checking the $2$-colourability of a graph, There are two approaches that lead to the same conclusion. Approach 1, There exists a small $n$ where the second player can win. , Think of the letters as numbers modulo $3$ and look at, To maximize the number of pairs $(l,r)$ that contain the value $1$, we, To minimize the number of pairs $(l,r)$ where $\operatorname{MEX}(a_l, Try to find a characterization of all great grids. , What is the answer when $c = 0$? , When $c \ge 0$, the answer is the array sorted in nondecreasing order

Full text and comments »

  • Vote: I like it
  • +379
  • Vote: I do not like it

32.
By Errichto, 5 years ago, In English
[GYM] 100 Easy Problems (Bootcamp) Target audience: newbies and pupils (rating up to 1400). Group link: https://codeforces.me/group/yg7WhsFsAp/contests (hit "join" on the right). Hi. Enjoy a series of 8 problem lists for beginners. The example topics are strings, arrays, math, and binary search. You are allowed to discuss anything with others, or just look up solutions online. There are also 3 exams, each recommended for a 2-hour individual virtual participation. Use the displayed order, e.g. take exam 1 after day 3. It all should take you 2 weeks of intense bootcamp-like work (or a few months if you take your time). The problems were originally used two years ago in a Saudi Arabia camp. It's a mix of around 70 existing CF problems and 30 new original problems, mainly prepared by [user:kostka,2021-11-18], with some help from me and [user:mustafabar,2021-11-18]. I asked them for permission to publish everything. I will put hints to some problems in this blog (or in the group? not sure). Expect a few v...
Use prefix sums. Or use sliding window

Full text and comments »

  • Vote: I like it
  • +251
  • Vote: I do not like it

33.
By sevlll777, history, 5 years ago, translation, In English
Codeforces Round #770 (Div. 2) editorial Thank you for participating, we hope you enjoyed the problems! We kindly ask you to rate each of the round's problems in the corresponding spoiler in order to improve the quality of future contests. You can also check video editorials of problems B and C on [user:ak2006,2022-02-06] [Youtube channel](https://www.youtube.com/channel/UCnZ5rC2_JY0EuYMGMiAbISg). All problems were prepared by [user:Alexdat2000,2022-02-02] with the help of coauthors. [Why didn't AI participate](https://codeforces.me/blog/entry/99579?#comment-884764) [problem:1634A]<br> Idea: [user:sevlll777,2022-02-02] <div class="spoiler"> <b class="spoiler-title">Hint 1</b> <div class="spoiler-content" style="display: none;"> What property will the string have after the first operation (regardless of the type of operation)? </div></div> <div class="spoiler"> <b class="spoiler-title">Hint 2</b> <div class="spoiler-content" style="display: none;"> What happens if you apply an operation to a palindrome? ...
Hint 1 , Hint 2 , Hint 3

Full text and comments »

  • Vote: I like it
  • +333
  • Vote: I do not like it

34.
By zscoder, history, 4 years ago, In English
[Contest] Statement Not Found: Season 2 #### Do you think you can solve CP problems without reading the problem statements? Let's find out! On [August 28, 2022 (Sunday) 19:30-22:00 GMT+8](https://www.timeanddate.com/worldclock/fixedtime.html?msg=Statement+Not+Found+-+Season+2&iso=20220828T1930&p1=122&ah=2&am=30), I will hold an unofficial fun contest called Statement Not Found. As you can deduce from the title, there will be no problem statements (except title and samples). Your goal is to collect as many points as possible within 2.5 hours :) Obviously, this round is **unrated**. It is somewhere between April Fools contest and a legitimate contest. The contest will be OI-style, meaning there will be no time penalty. You are allowed to use any resources online to help solve the problems. There will be **12** problems. **Scoring Distribution:** 200-400-700-700-700-800-800-900-1100-1100-1100-1500 (Total: 10000) **Please read all problems** as problem difficulty is very subjective and a 1100-point problem might b...
// is very weird. Why is it in the title? , Google $\frac{691}{2730}$. , Input $1$ is $\frac{1}{6} \pmod{998244353}$. , It's a geometry problem. , Look for factors coming from well-known sequences. , Notorious coincidence. , Output looks like Codeforces titles. , Output seems to contain two pairs of triangles. , Side lengths of triangle , Symmetric Strategy , The title and the fact that the input is represented by $c, We are looking for a word from the grids. , What does $a,b,c$ stand for in math? , You can reinterpret the title as "Parallel Euler Lines

Full text and comments »

  • Vote: I like it
  • +308
  • Vote: I do not like it

35.
By Agnimandur, history, 5 years ago, In English
April Fools Day Contest 2022 With [user:Nickolas,2022-03-29] not writing a contest this year, [user:magnus.hegdahl,2022-03-29] and I have decided to take up this sacred duty :). We would like to invite everyone on Codeforces to the [contest: 1663]. Special thanks to [user:BucketPotato,2022-03-29] for volunteering to test this contest! The 10th April Fools Day Contest will take place on [contest_time:1663]. This is a joke competition in which solving the problem is often easier than figuring out what the actual task is. In this round you'll be given several weird problems and 2 hours to solve them. The contest will use ACM ICPC rules (no hacks, the standings are decided by the number of solved problems and penalty time earned on them), and it will be unrated. You can submit solutions in any language allowed by Codeforces, unless the problem says otherwise. To get an idea of what the contest will look like, you can check out the contests of the past years: [2012](https://codeforces.me/contest/171), [2013](htt...

Full text and comments »

  • Vote: I like it
  • +538
  • Vote: I do not like it

36.
By IgorI, history, 6 years ago, In English
Codeforces Round #696 Editorial Спасибо за участие в раунде! Я надеюсь, что вам понравились задачи. [problem:1474A] <spoiler summary="Hint 1"> Hint $1$: Следует ли всегда делать первую цифру $d$ не равной $0$? Как это можно сделать? </spoiler> <spoiler summary="Hint 2"> Hint $2$: Попробуйте выбрать такое $a$, что $d$ будет состоять ровно из $n$ цифр. </spoiler> <spoiler summary="Editorial"> [tutorial:1474A] </spoiler> <spoiler summary="Solution"> [104840922](https://codeforces.me/contest/1474/submission/104840922) </spoiler> [problem:1474B] <spoiler summary="Hint 1"> Hint $1$: Число имеет $4$ делителей, если оно равно $pq$ или $p^3$ для некоторых простых $p$ и $q$. В первом случае его делители равны $1$, $p$, $q$, $pq$. Во втором случае его делителями являются $1$, $p$, $p^2$, $p^3$. </spoiler> <spoiler summary="Hint 2"> Hint $2$: Вместо поиска числа с хотя бы $4$ делителями, попробуйте найти число с ровно $4$ делителями. </spoiler> <spoiler summary="Hint 3"> Hint $3...
hints. [problem:1474A] Hint $1$: Should we always make first, summary="Hint 1"> Hint $1$: Следует ли всегда делать первую цифру $d$ не равной $0$? Как это можно, Hint $1$: How does $x$ changes after each operation? , Hint $1$: How many operations will robot make in the worst case, Hint $1$: How to solve the promblem if we are not allowed to use a, Hint $1$: Should we always make first digit of $d$ not equal to $0, Hint $1$: Как $x$ меняется после каждой операции? , Hint $1$: Как решить задачу, если нам нельзя использовать, Hint $1$: Сколько операций робот сделает в худшем случае? , Hint $1$: Следует ли всегда делать первую цифру $d$ не равной $0$? Как, Hint $2$: How many times can robot spend $(n - 1)^2$ time on $1, Hint $2$: Instead of finding integer with at least $4$ divisors, find, Hint $2$: Look at the first pile. There is only one way to remove stone, Hint $2$: Suppose, that you know $x$. What pairs of elements can you, Hint $2$: Try to choose such $a$ that $d$ will have $n$ digits, Hint $2$: Вместо поиска числа с хотя бы $4$ делителями, попробуйте, Hint $2$: Попробуйте выбрать такое $a$, что $d$ будет состоять ровно из, Hint $2$: Посмотрите на первую кучку. Есть лишь один способ убрать, Hint $2$: Пусть Вы знаете $x$. Какие элементы можно сейчас выкинуть, Hint $2$: Сколько раз робот может потратить $(n - 1)^2$ секунд на $1, Hint $3$: How many times can robot spend $(n - 2)^2$ time on $1, Hint $3$: If you swap $i$-th and $(i + 1)$-th piles of stones, nothing, Hint $3$: Let $p$ be the smallest prime factor of $a$. Then, $p \geq d, Hint $3$: Если Вы поменяете $i$-th и $(i + 1)$-th кучки камней, ничего, Hint $3$: Пусть $p$ — наименьший простой делитель $a$. Тогда, $p, Hint $3$: Сколько раз робот может потратить $(n - 2)^2$ секунд на $1, Hint $4$: Instead of operation from the statement we can apply the, Hint $4$: Look at the problem from the both sides: from the beginning, Hint $4$: You don't know $x$ only before the first operation and $n, Hint $4$: Вместо операций из условия мы можем применять следующую, Hint $4$: Вы не знаете $x$ только перед первой операцией и $n \leq 1000, Hint $4$: Посмотрите на задачу с двух сторон: с начала $a$ и с конца $a

Full text and comments »

  • Vote: I like it
  • +307
  • Vote: I do not like it

37.
By TheScrasse, history, 5 years ago, In English
[Tutorial] Diameter of a tree and its applications Hello everyone,<br> finding the diameter is one of the most frequent ways to solve problems about trees. In this tutorial we will see how to find a diameter and some of its properties, and we will use them to solve some problems of increasing difficulty.<br> The first part of the tutorial is quite basic, so feel free to skip it and jump to the problems if you already know the concepts. Target: rating $[1400, 2300]$ on CF<br> Prerequisites: basic graph theory, greedy The diameter ------------------ Given an unweighted tree, let's define $\text{dist}(a, b) =$ the number of edges in the simple path $a \rightarrow b$. A diameter of the tree $a \rightarrow b$ is the longest path, i.e., the one that maximizes $\text{dist}(a, b)$ over all pairs of nodes. If there are multiple diameters, let's pick any of them. The same definition is valid for a weighted tree with nonnegative weights (with $\text{dist}(a, b) =$ the sum of the weights of the edges in the simple path $a \rightar...
First, put the shops on any path of (unweighted) length $k$. Can you, How to check fast if a path contains an even number of ramen cups, Once again, choose any two paths and try to "improve" them. , The optimal path lies completely on the (weighted) diameter. , There are two cases to consider:, Try all possible paths in $O(n)$. , You have to find the maximum total weight of two non-intersecting paths

Full text and comments »

  • Vote: I like it
  • +259
  • Vote: I do not like it

38.
By errorgorn, history, 6 years ago, In English
Codeforces Round #723 (Div. 2) Editorial [problem:1526A] ------------------ Setter: [user:antontrygubO_o,2021-05-28] Preparer: [user:errorgorn,2021-05-28] <spoiler summary="Hint 1"> Notice that the array size is even length. Usually in such problems, we would split the array into $2$ equal parts. Can you figure out what those $2$ parts are? </spoiler> <spoiler summary="Hint 2"> We sort the array and split it into the big half and the small half. </spoiler> <spoiler summary="Solution"> The main idea is that we can split the numbers into the two halves, the big half and small half, we can place the bigger half at the odd positions and the smaller half at the even positions. This works because the smallest big number is larger than the biggest small number. Hence, the mean of any two small numbers is smaller than any big number, and the mean of any two big numbers is bigger than any small number. </spoiler> <spoiler summary="Code (C++)"> ```c++ //雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #inc...
$1111=11 \cdot 101$ , All numbers other than $11$ and $111$ are useless. , Find elements $1$ and $2$ in $N+420$ queries. , Read the name of the problem ;) , Speedup dp or use greedy for full solution. , The dp states are position and number of potions drank. , Try dp!

Full text and comments »

  • Vote: I like it
  • +199
  • Vote: I do not like it

39.
By TheScrasse, 3 years ago, In English
Editorial of Codeforces Round 889 (Div. 1 + Div. 2) The official implementations of all the problems are [here](https://drive.google.com/file/d/1stkidhN_ftTOzK4qcMYxkUAlwWWb3AqF/view?usp=sharing). [problem:1855A] Author: [user:Kaey,2023-07-23]<br> Preparation: [user:akifpatel,2023-07-23] <spoiler summary="Hint 1"> What's the most efficient way to make the sad students happy? </spoiler> <spoiler summary="Hint 2"> In most cases, you can make $2$ sad students happy in $1$ move. </spoiler> <spoiler summary="Solution"> Let $s$ be the number of sad students at the beginning. The answer is $\lceil \frac{s}{2} \rceil$. In one move, you can make at most $2$ sad students happy (because you can change the position of at most two students), so you need at least $\lceil \frac{s}{2} \rceil$ moves. In fact, you can make everyone happy in exactly $\lceil \frac{s}{2} \rceil$ moves: - while there are at least $2$ sad students, you can swap them and both of them will be happy; - if there is exactly $1$ sad student left, you ...
Try to generalize Hint 1.

Full text and comments »

  • Vote: I like it
  • +196
  • Vote: I do not like it

40.
By gepardo, history, 6 years ago, translation, In English
Editorial of Codeforces Round #672 (Div. 2) [problem:1420A] <spoiler summary="Hint"> Any array can be sorted using no more than $\frac{n(n-1)}2$ operations. Think or guess when we need exactly $\frac{n(n-1)}2$ operations. </spoiler> <spoiler summary="Solution"> [tutorial:1420A] </spoiler> <spoiler summary="Code in C++ (Wind_Eagle)"> ~~~~~ #include<iostream> using namespace std; int a[1000000+5]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin>>t; while (t--) { int n; cin>>n; for (int i=0; i<n; i++) { cin>>a[i]; } bool can=false; for (int i=1; i<n; i++) { if (a[i]>=a[i-1]) { can=true; break; } } if (can) cout<<"YES"<<'\n'; else cout<<"NO"<<'\n'; } } ~~~~~ </spoiler> [problem:1420B] <spoiler summary="Hint"> Think of a simple criteria when `a...
Join all your observations together and use DP. , Use dynamic programming.

Full text and comments »

  • Vote: I like it
  • +314
  • Vote: I do not like it

41.
By adamant, 12 months ago, In English
Finding all primes up to half a billion in 83 ms Hi everyone! I was itching to apply SIMD in another problem, and this time my attention picked the following problem: --- **[Library Checker &mdash; Enumerate Primes](https://judge.yosupo.jp/problem/enumerate_primes)**. You are given $N$, $A$ and $B$. Find $\pi(N)$, and print all $p_{kA + B} \leq N$. It is guaranteed that $N \leq 5 \cdot 10^8$ and that the total number of primes to print is at most $10^6$. --- After some tweaking, I managed ([#336744](https://judge.yosupo.jp/submission/336744)) to reduce my time consumption in this problem to **83 ms** and memory consumption to **25 MiB**, which makes it a top-1 submission on the Library Checker. For comparison, the top-2 solution ([#148169](https://judge.yosupo.jp/submission/148169)) takes 172 ms and 15 MiB, meaning that what I describe here is a 2x improvement in terms of the running time. We can also compare it to what appears to be the state of the art of sieving, the [primesieve](https://github.com/kimwalisch/...
goes perfectly with vectorization. We, however, still should write them in a way that wouldhint the

Full text and comments »

  • Vote: I like it
  • +375
  • Vote: I do not like it

42.
By Vladithur, history, 4 years ago, In English
Codeforces Round #813 (Div. 2) Editorial Thanks for participating in the round, we hope you liked the problems! <spoiler summary="Solve count predictions (official div. 2)"> Handle | A | B | C | D | E1 | E2 | F --- | --- | --- | --- | --- | --- | --- | --- [user:Vladithur,2022-08-13] | 16K | 8K | 3K | 900 | 500 | 50 | 4 [user:_dlbm17,2022-08-13] | 14K | 9K | 5K | 500 | ? | ? | ? [user:thanhchauns2,2022-08-13] | 14K | 8K | 2K | 1K | 500 | ? | ? [user:QuangBuiCP,2022-08-13] | 14K | 7K | 2K | 1K | 500 | 24 | 5 [user:welleyth,2022-08-13] | 16K | 10K | 4K | 1.5K | 600 | 130 | 2 [user:Kon567889,2022-08-13] | 14K | 10K | 5K | 2K | ? | ? | 5 </spoiler> [problem:1712A] <spoiler summary="Hint"> The smallest possible sum is $1 + 2 + \ldots + k$. </spoiler> <spoiler summary="Tutorial"> [tutorial:1712A] </spoiler> <spoiler summary="Solution"> ~~~~~ #include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define allr(x) (x).rbegin(), (x).rend() #define gsize(x) (int)((x).size()) const ch...
Solve in offline. , The operation only decreases numbers. , The smallest possible sum is $1 + 2 + \ldots + k$. , Think small-to-large merging. , _diameter_ $\le 2 \cdot \min(a_1 \ldots a_n)$

Full text and comments »

  • Vote: I like it
  • +325
  • Vote: I do not like it

43.
By aryanc403, 2 years ago, In English
Codeforces Education Round 170 Discussion Stream (with Hints) [I'm currently live discussing the problems.](https://youtu.be/2x4DX4Wqrpo) I will add problemwise timestamp after the discussion stream, and also format the blog properly. You can join in if something in this blog is unclear or you have more questions. [problem:2025A] <spoiler summary="Idea"> We can do one of the following 2 things - - Either write both strings without using 2nd action - Or we first write longest common prefix string, then use 2nd action and then write the remaining strings. </spoiler> My submission &mdash; [submission:285842091] [problem:2025B] <spoiler summary="Hint 1"> Use pen and paper and write down table C. </spoiler> <spoiler summary="Hint 2"> Table C looks like this - ~~~~~ 1 1 1 1 2 1 1 2 4 1 1 2 4 8 1 1 2 4 8 16 1 ~~~~~ </spoiler> <spoiler summary="Hint 3"> If $k=n$, $C[n][k] = 1$, else $C[n][...
Another important observation is - No of suite 1 cards, If $k=n$, $C[n][k] = 1$, else $C[n][k]=2^k$ , Its never optimal to leave any acquiring point. So x+y will always be, Let first decide if we want to do an operation on xi or yi. , Lets pick a suite and distribute m cards in descending order., Now, lets create a graph with n nodes and q edges. ith, Now, we can first fix the no of extra suite 1 cards (say K) we want to, Selecting xi or yi for each query is equivalent to giving a direction, Sort the array and then use [two pointers](https, Table C looks like this -, Use pen and paper and write down table C. , We can ensure that each ai is either 0 or 1. Do -1 if, Y is essentially minimum possible value of dP when we are assigning all, au will be equal to parity of no of incoming edges on u, ; [submission:285842091] [problem:2025B] Use pen and paper and write down

Full text and comments »

  • Vote: I like it
  • +81
  • Vote: I do not like it

44.
By Dominater069, 2 years ago, In English
How to Solve Questions [Dominater Version] Recently, I got a request asking me to write down my thought process while solving questions. So, here is the promised blog. I would like to thank [user:Iceknight1093,2024-08-30], [user:qwexd,2024-08-30], [user:Sana,2024-08-30], [user:Everule,2024-08-30] and [user:NovusStellachan,2024-08-30] for proof reading and suggesting edits in the blog. Special thanks to [user:satyam343,2024-08-30] for discussing most of the blog with me. <h3> 1. Overview </h3> The blog contains my solutions to $7$ problems in a wide range of ratings, starting from $1200$ all the way upto $2700$. Each problem has a step-by-step solution and you can notice how there are no large jumps in logic, but everything comes naturally. I do not claim that this is always possible in each problem, however I solve majority of CF problems in such a manner. There are certainly other high rated people who will have completely different methods of solving. However, this is about what works for me. There are some meta ...
Reduce the problem to this problem :

Full text and comments »

  • Vote: I like it
  • +263
  • Vote: I do not like it

45.
By -is-this-fft-, history, 4 years ago, In English
[Tutorial] FFT If I was a YouTuber, this would be the place where I fill the entire screen with screenshots of people asking me to make this. Anyway, not so long ago I gave a lecture on FFT and now [user:peltorator,2023-01-11] is giving away [free money](https://codeforces.me/blog/entry/110840), so let's bring this meme to completion. In this blog, I am going to cover the basic theory and (competitive programming related) applications of FFT. There is a long list of generalizations and weird applications and implementation details that make it faster. Maybe at some point I'll write about them. For now, let's stick to the basics. **The problem.** Given two arrays $a$ and $b$, both of length $n$. You want to quickly and efficiently calculate another array $c$ (of length $2n - 1$), defined by the following formula. $$c_k = \displaystyle \sum_{i + j = k} a_i \cdot b_j.$$ Solve it in $O(n \log n)$. First of all, why should you care? Because this kind of expression comes up in combinatorics a...

Full text and comments »

  • Vote: I like it
  • +436
  • Vote: I do not like it

46.
By TheScrasse, history, 6 years ago, In English
Editorial of Codeforces Round #701 (Div. 2) [problem:1485A] Author: [user:TheScrasse,2021-02-07]<br> Preparation: [user:MyK_00L,2021-02-07] <spoiler summary="Hint 1"> Suppose that you can use $x$ operations of type $1$ and $y$ operations of type $2$. Try to reorder the operations in such a way that $a$ becomes the minimum possible. </spoiler> <spoiler summary="Hint 2"> You should use operations of type $2$ first, then moves of type $1$. How many operations do you need in the worst case? ($a = 10^9$, $b = 1$) </spoiler> <spoiler summary="Hint 3"> You need at most $30$ operations. Iterate over the number of operations of type $2$. </spoiler> <spoiler summary="Solution"> Notice how it is never better to increase $b$ after dividing ($\lfloor \frac{a}{b+1} \rfloor \le \lfloor \frac{a}{b} \rfloor$). So we can try to increase $b$ to a certain value and then divide $a$ by $b$ until it is $0$. Being careful as not to do this with $b<2$, the number of times we divide is going to be $O(\log a)$. In particular, i...
Brute force doesn't work (even if you optimize it): there are, Find a dp with time complexity $O(n^2\log n)$. , How many $k$-similar arrays can you make if either $x < a_l$ or $x, How many $k$-similar arrays can you make if none of the previous, What happens if you can't swap coins? , Why isn't the answer $2^{n-1}$? What would you overcount? , You need at most $30$ operations. Iterate over the number of operations

Full text and comments »

  • Vote: I like it
  • +263
  • Vote: I do not like it

47.
By aryanc403, 2 years ago, In English
Codeforces Round 962 Video Editorial (with Hints) [problem:1996A] <spoiler summary="Hint"> Greedily take Cow as long as you can. </spoiler> <spoiler summary="Video editorial"> <iframe width="853" height="480" src="https://www.youtube.com/embed/VIxp7EkV1d8?start=77" title="Codeforces Round 962 Solution Discussion | ABCDEFG | All Problems" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen width="700" height="500"></iframe> </spoiler> [problem:1996B] <spoiler summary="Idea"> Just print all index $A[i*K][j*K]$ </spoiler> <spoiler summary="Video editorial"> <iframe width="853" height="480" src="https://www.youtube.com/embed/VIxp7EkV1d8?start=390" title="Codeforces Round 962 Solution Discussion | ABCDEFG | All Problems" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cros...
Binary search on the value you will add in $k^{th}$ operation, Bruteforce works, now analyse why it works. , Greedily take Cow as long as you can. , Greedy, always take the index with maximum value of $A-i$ , Instead of counting segments inside each range. For each substring, Replace all 0 with -1. Now all segments with equal 0 and 1 have zero, [Binary search FTW](https://codeforces.me/blog/entry/92248) , [Prefix Sum](https://usaco.guide/silver/prefix-sums) , [Sum of Harmonic series](https://mathworld.wolfram.com

Full text and comments »

  • Vote: I like it
  • +70
  • Vote: I do not like it

48.
By aryanc403, 10 days ago, In English
Codeforces Round 1137 Discussion Stream (with Hints) The editorial video for [contest:2289] is now available [here](https://youtu.be/fdB2s_PBKlI). Do check out the [CF Video Editorial Finder](https://codeforces.me/blog/entry/154724) browser extension — it adds links to my video editorials directly from the contest/problems page. You can join in if something in this blog is unclear or if you have more questions. [problem:2289A] <spoiler summary="Hint 1"> What are we really counting here? Focus on the number of odd divisors vs even divisors of $x$. </spoiler> <spoiler summary="Hint 2"> Artem moves first and can choose any parity. He'll pick the parity with more divisors!<br> The second player wins only if the count of odd divisors equals the count of even divisors. </spoiler> <spoiler summary="Hint 3"> Case 1: If $x$ is odd, what can we say about all its divisors?<br> <br> All divisors of an odd number are odd. Artem chooses an odd card, and the second player has no even cards to play. Artem wins immediately. </...
Algorithm: Process elements in increasing order of their values., Alternative approach: Use a monotonic stack to find the nearest smaller, An inversion is a pair $(i, j)$ where $i < j$ but $p[i] > p[j]$., But wait! First check: can we even achieve non-negative values?, Can we actually achieve any element in this range?, Can we optimize the merging?, Case 1: If $x$ is odd, what can we say about all its divisors?, Case 2: If $x \equiv 2 \pmod{4}$ (divisible by 2 but not by 4)., Case 3: If $x \equiv 0 \pmod{4}$ (divisible by 4 or higher power of 2)., Edge case: When the element is at a boundary., How many swaps does bubble sort need?, How to count inversions efficiently?, Key observation: Look at what happens to the prefix array itself!, Let's explore an $O(n^2)$ solution first, then we'll optimize it., Let's trace the same operations in terms of prefix sum differences., Let's trace through what happens when we apply operations on a sample, Look at it from the perspective of position $m$., Notice the pattern? Each element becomes a sum of contiguous original, Now consider match $i$ which has two child matches $u$ and $v$., So for each match $i$ with children $u$ and $v$:, Solution 1: Sliding Window with Frequency Map, Solution 2: Prefix Sum Trick, The given structure is a tournament bracket represented as a tree., What is the latest index in $A$ that $B[i]$ can come from?, Whenever we see subarray sums, we should think about prefix sums!, With the observation that operations swap adjacent prefix sums:

Full text and comments »

  • Vote: I like it
  • +16
  • Vote: I do not like it

49.
By RDDCCD, history, 4 years ago, In English
Editorial of CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) [A. Beautiful Sequence](https://codeforces.me/contest/1810/problem/A) <spoiler summary="Hint"> What is the necessary and sufficient condition? </spoiler> <spoiler summary="Tutorial"> The necessary and sufficient condition for a beautiful sequence is that there exist one $i$, such that $a_{i} \le i$. Just check the sequence for the condition. </spoiler> <spoiler summary="Solution"> ~~~~~ #include<bits/stdc++.h> using namespace std; int a[100005]; void solve() { int n; scanf("%d",&n); for(int i =1;i <= n;i++) scanf("%d",&a[i]); for(int i = 1;i <= n;i++) { if(a[i] <= i) { puts("YES"); return; } } puts("NO"); } int main() { int t;scanf("%d",&t); while(t--) solve(); } ~~~~~ </spoiler> [B. Candies](https://codeforces.me/contest/1810/problem/B) <spoiler summary="Hint"> How the binary representation changes after an operation? </spoiler> <spoiler summary="Tutorial"...
Actually I don't know how to hint. Try to find some rules related to

Full text and comments »

  • Vote: I like it
  • +269
  • Vote: I do not like it

50.
By Proof_by_QED, history, 17 months ago, In English
EPIC Institute of Technology Round Summer 2025 (Codeforces Round 1036, Div. 1 + Div. 2) Editorial Thanks for participation! We hope you loved the contest. #### [problem:2124A] Problem Credits: [user:Lilypad,2025-07-01] <br> <spoiler summary="Hint"> When is there definitely *not* a solution? </spoiler> <spoiler summary="Solution"> First, note that since relative order is preserved no matter which elements are deleted, if $a$ is originally sorted in nondecreasing order, the array cannot be a derangement no matter which elements are deleted. If $a$ is not sorted, we can note that any two elements that form an inversion pair satisfies the requirements. The total runtime is $O(n)$. </spoiler> <spoiler summary="Code"> ``` #include <bits/stdc++.h> using namespace std; void solve(){ int n; cin >> n; vector<int> arr(n); for(auto &x : arr) cin >> x; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(arr[i] > arr[j]){ cout << "YES\n2\n"; cout << arr[i] << " " << a...
Characterize the arrays that we might overcount. , Characterize what a good subsequence is. , Determine which elements you can delete with the operation. , Disregard cost first. Find the maximum sum of prefix minimums, Optimize the DP using some cumulative sums. , Solve the $n=3$ case first. , Take the LCM. Prove its sufficient (optional). , The answer is either $-1$, $1$, or $2$. , When is there definitely *not* a solution? , Write some examples of arrays down.

Full text and comments »

  • Vote: I like it
  • +309
  • Vote: I do not like it

51.
By errorgorn, 6 years ago, In English
Codeforces Global Round 13 Editorial [problem:1491A] ------------------ Setter: [user:syksykCCC,2021-02-28] Prepared by: [user:syksykCCC,2021-02-28] <spoiler summary="Hint 1"> How can we find the largest $k$ such that the $k$-th smallest element of the array is $0$? </spoiler> <spoiler summary="Hint 2"> How can we maintain $k$? </spoiler> <spoiler summary="Solution"> Let's define $cnt$ to represent the number of 1s in the array. For the modifications, if $a_i$ is already $1$ now, then we let $cnt \gets cnt - 1$. Otherwise, let $cnt \gets cnt + 1$. For the querys, just compare $cnt$ with $k$. If $cnt \ge k$, the answer will be $1$. Otherwise, the answer will be $0$. The complexity : $O(n + q)$. </spoiler> <spoiler summary="Code (C++)"> ```c++ #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, q, a[N], cnt; int main() { scanf("%d%d",&n,&q); for(int i = 1; i <= n; ++i) { scanf("%d",a+i); cnt += a[i]; } while(q--) { int opt, x; ...
Focus on converting $01$ into $10$. , How can we maintain $k$? , The complexity is $\mathcal O(n\sqrt{n})$., Think greedily! , Work out the inequalities.

Full text and comments »

  • Vote: I like it
  • +255
  • Vote: I do not like it

52.
By TheScrasse, history, 5 years ago, In English
[Tutorial] Problems about swapping adjacent elements Hello everyone,<br> problems about swapping adjacent elements are quite frequent in CP, but they can be tedious. In this tutorial we will see some easy ideas and use them to solve some problems of increasing difficulty. I tried to put a lot of examples to make the understanding easier.<br> The first part of the tutorial is quite basic, so feel free to skip it and jump to the problems if you already know the concepts. Target: rating $[1400, 2100]$ on CF<br> Prerequisites: greedy, Fenwick tree (or segment tree) Counting inversions ------------------ Let's start from a simple problem. _You are given a permutation $a$ of length $n$. In one move, you can swap two elements in adjacent positions. What's the minimum number of moves required to sort the array?_ #### Claim The result $k$ is equal to the number of inversions, i.e. the pairs $(i, j)$ ($1 \leq i < j \leq n$) such that $a_i > a_j$. #### Proof 1 Let $f(x)$ be the number of inversions after $x$ moves.<br> In one...
Re-read Proof 2 in this tutorial. , Some swaps are useless (which ones?) , When is the answer `-1`? , Which balls can you put at the end?

Full text and comments »

  • Vote: I like it
  • +223
  • Vote: I do not like it

53.
By satyam343, 4 years ago, In English
Codeforces Round #838 (Div. 2) Editorial Thank you for participation! I hope you liked atleast one problem from the set (: We tried hard to have an interesting problemset. It is sad to see people disliking the round only because some problems were hard. Please read the intended solutions to know why we decided to put the problems(especially D) at current positions. [problem:1762A] Idea:[user:satyam_343,2022-12-16] <spoiler summary="Hint 1"> If sum is even, answer is $0$. Otherwise we need to change parity of atleast one element of $a$. </spoiler> <spoiler summary="Hint 2"> It it optimal to change parity of atmost one element. </spoiler> <spoiler summary="Hint 3"> Answer can be atmost $20$, as we need to divide any integer $x$ ($1 \leq x \leq 10^6$) atmost $20$ times to change its parity. </spoiler> <spoiler summary="Solution"> We are assuming initial sum is odd. Suppose $f(x)(1 \leq x \leq 10^6)$ gives the minimum number of operations needed to change parity of $x$. Iterate from $i=1$ to ...
How to prove the claim in hint $2$?, How to prove the result in hint $2$?

Full text and comments »

  • Vote: I like it
  • +240
  • Vote: I do not like it

54.
By Errichto, 5 years ago, In English
3 Hard Interactive Problems Hi. I think these are nice medium-hard interactive problems. I will discuss solutions in a stream today at https://www.twitch.tv/errichto. UPD, recording is here https://youtu.be/9oEihYrAR5kUPD and I added text solutions in this blog. P1. **Mostly A** &mdash; You're given two integers $N$ and $K$ ($N \leq 50\,000$, $K \leq 10$). You need to find a hidden string of length $N$ with lowercase English characters a-z. At most $K$ characters are different than 'a'. You can choose your own string of length $N$ and you will get info YES/NO whether your string is lexicographically smaller than the hidden one. There is no explicit limit on the number of queries. There's still some time limit (say, 2 seconds). Hard version: Minimize the number of queries. <spoiler summary="slow solution"> It seems reasonable to discover characters one by one from left to right. Let's say that we already know the prefix `raay` and we're looking for the fifth character. We can binary search it in $...
As always, use binary search.

Full text and comments »

  • Vote: I like it
  • +235
  • Vote: I do not like it

55.
By chromate00, 22 months ago, In English
Codeforces Round 1000 (Div. 2) — Anti-LLM Evaluation Report As the main problemsetter of [contest:2063], I know that a lot of you were somewhat disappointed to see that it was not a Div.1 contest. Though I am not the one who caused a lack of Div.1 contests, I understand your feeling. So I present to you the great surprise: The **Anti-LLM Evaluation Report** for [contest:2063], the first of its kind on a Div.2! In this blog we discuss about how the round combats against LLMs (especially focusing on OpenAI o1, the greatest of its kind while we prepared and tested the problemset), by looking at the timeline of how the problemset changed. --- So, let us begin with the initial problemset we had when the testing began. (The task names are anonymized, unless they are released to the public before or in the round) In the beginning, we had a problemset that looks like this: - **A' &mdash; B &mdash; C0 &mdash; D' &mdash; E' &mdash; F0** (If you are confused with the meanings, (letter)' means it was not used in the final problemset but exis...
[**I gave you a hint already.**](https://codeforces.me/#:~:text=In%20that%20sense,rewards%20you

Full text and comments »

  • Vote: I like it
  • +587
  • Vote: I do not like it

56.
By aryanc403, 2 years ago, In English
Codeforces Round 966 Discussion Stream (with Hints) [I'm currently live discussion the problems.](https://youtu.be/98gMxTz0nwY) I will add problemwise timestamp after the discussion stream. You can join in if something in this blog is unclear or there are more questions. [problem:2000A] <spoiler summary="Idea"> Split the string such that A is interger formed using first 2 char. Split the string such that B is interger formed using remaining. A should be equal to 10, $2 \le B$, and 3rd char must not be 0. One can use built in string to int functions. [stoll](https://en.cppreference.com/w/cpp/string/basic_string/stol) </spoiler> My submission &mdash; [submission:276111053] [problem:2000B] <spoiler summary="Idea"> Maintain set of seats occupied so far. Then x is valid, if set is empty, or x-1 or x+1 is present in set. </spoiler> My submission &mdash; [submission:276114559] [problem:2000C] <spoiler summary="Hint ...

Full text and comments »

  • Vote: I like it
  • +27
  • Vote: I do not like it

57.
By aryanc403, 2 years ago, In English
Codeforces Round 968 Video Editorial (with Hints) (ABCD1D2E1E2) [Full video](https://youtu.be/9RMg-xKznTw) [problem:2003A] <spoiler summary="Hint 1"> Solve with $K=2$ only. </spoiler> My submission &mdash; [submission:278058173] <spoiler summary="Video Editorial"> <iframe width="853" height="480" src="https://www.youtube.com/embed/9RMg-xKznTw?start=245" title="Codeforces Round 968 Solution Discussion | ABCD1D2E1E2" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> </spoiler> [problem:2003B] <spoiler summary="Hint 1"> Turtle wants to maximise the remaining value, so he should try to remove the smallest values. Similarly Piggy wants to minimise the remaining value, so he should try to remove the largest values. </spoiler> My submission &mdash; [submission:278054761] <spoiler summary="Video Editorial"> <iframe width="853" height="480" src="...
Refer hints of D1. , Refer to hints of E1.

Full text and comments »

  • Vote: I like it
  • +21
  • Vote: I do not like it

58.
By aryanc403, 5 months ago, In English
Codeforces Round 1106 Discussion Stream (with Hints) The editorial video for [contest:2238] is now available [here](https://youtu.be/ZJeKaVFtOuE). Do check out the [CF Video Editorial Finder](https://codeforces.me/blog/entry/154724) browser extension. [problem:2238A] <spoiler summary="Hint 1"> Do we really need to reorder more than once? </spoiler> <spoiler summary="Hint 2"> Any subtraction done after a reorder could have been done before it instead.<br> So optimal strategy is: subtract some elements, then reorder at most once. </spoiler> <spoiler summary="Hint 3"> Compute cost without reordering — check if $a_i \geq b_i$ for all $i$. Cost = $\sum (a_i - b_i)$. </spoiler> <spoiler summary="Hint 4"> Compute cost with reordering — sort both arrays. Pair largest $a_i$ with largest $b_i$, and so on.<br> Check feasibility. Cost = $c + \sum (a_i - b_i)$.<br> <br> Why this pairing? If the largest $b_i$ is 20, at least one $a_i$ must be $\geq 20$. If the second largest is 10, at least two $a_i$ must be $\geq 10$, ...
Answer is $\min$ of both costs. If both are impossible, output $-1, Assume the final string is fixed (all N already replaced). How do we, Do we really need to reorder more than once?

Full text and comments »

  • Vote: I like it
  • +22
  • Vote: I do not like it

59.
By aryanc403, 2 years ago, In English
Codeforces Round 967 Video Editorial (with Hints) [Full video](https://youtu.be/aEJg_fFxYmU) [problem:2001A] <spoiler summary="Hint 1"> Let v be the element that remains when all the elements are equal. What is the minimum no of operations required? </spoiler> <spoiler summary="Hint 2"> Let the number of times v be present in the array is fv. Because we will have to delete all the elements not equal to v, the minimum no of operations required will be n &mdash; fv. </spoiler> <spoiler summary="Hint 3"> It turns out that this minimum is the answer ie we should never delete any element equal to v from the array. </spoiler> <spoiler summary="Hint 4"> Since we want the minimum number of operations required, we should choose the element with the maximum value of fv. </spoiler> My submission &mdash; [submission:277424035] <spoiler summary="Video Editorial"> <iframe width="853" height="480" src="http...
For odd $N$, following pattern works, The answer is -1 when $n$ is even. , The length of the required sequence if no distinct elements in A

Full text and comments »

  • Vote: I like it
  • +23
  • Vote: I do not like it

60.
By fchirica, 13 years ago, In English
Codeforces Round #225 — Editorial [problem:384A] ================== Usually, when you don’t have any idea how to approach a problem, a good try is to take some small examples. So let’s see how it looks for N = 1, 2, 3, 4 and 5. With C I noted the coder and with * I noted an empty cell. ![ ](http://s28.postimg.org/8z1d7k399/New_Bitmap_Image.png) By now you should note that answer is N ^ 2 / 2 when N is even and (N ^ 2 + 1) / 2 when N is odd. Good. Generally, after you find a possible solution by taking examples, you need to prove it, then you can code it. In order to proof it, one needs to do following steps: 1/ prove you can always build a solution having N ^ 2 / 2 (or (N ^ 2 + 1) / 2) pieces. 2/ prove that N ^ 2 / 2 (or (N ^ 2 + 1) / 2) is maximal number – no other bigger solution can be obtained. For proof 1/ imagine you do coloring like in a chess table. ![ ](http://s27.postimg.org/ysqhphx0z/New_Bitmap_Image.png) The key observation is that by placing all coders on black squares of tab...

Full text and comments »

  • Vote: I like it
  • +418
  • Vote: I do not like it

61.
By Artyom123, 5 years ago, translation, In English
Codeforces Global Round 16 Editorial We hope that you enjoyed the contest. Let's get right into the editorial: <spoiler summary="A: Median Maximization"> [problem:1566A] <spoiler summary="First solution"> <spoiler summary="Hint 1"> Which numbers smaller than the median should be taken? </spoiler> <spoiler summary="Hint 2"> Which numbers bigger than the median should be taken? </spoiler> <spoiler summary="Hint 3"> Greedy algorithm. </spoiler> <spoiler summary="Editorial"> Let's consider the array of $n$ elements in non-decreasing order. We can make numbers before the median equal to zero, after that we have $m = \lfloor {\frac{n}{2}} \rfloor + 1$ numbers, which sum should be $n$ and the minimal of them (i.e. median value) should be maximized. To do so, it is enough to make all these numbers equal $\lfloor {\frac{s}{m}} \rfloor$, and then add what's left to the last number ($s \bmod m$). It's easy to see that such array matches all the conditions and it is impossible to make median greater. </s...
Greedy algorithm.

Full text and comments »

  • Vote: I like it
  • +372
  • Vote: I do not like it

62.
By sammyuri, 6 months ago, In English
Spectral::Cup 2026 Round 2 (Codeforces Round 1100, Div. 1 + Div. 2) Editorial Thank you for participating in our round! We hope you enjoyed the problems as much as we enjoyed preparing them. <spoiler summary="Rate the contest!"> <spoiler summary="Quality"> - Absolute Cinema contest - Excellent contest - Good contest - Average contest - Bad contest - Horrible contest </spoiler> <spoiler summary="Difficulty"> - Trivial contest - Easy contest - Average contest - Hard contest - Impossible contest </spoiler> </spoiler> [problem:2229A] Idea by: [user:Intellegent,2026-05-23] Prepared by: [user:Intellegent,2026-05-23] Editorial by: [user:reirugan,2026-05-23] <spoiler summary="Hint 1"> Let $y$ denote the final position of all of the slimes. Then it is optimal to choose $x = y$ for every operation. </spoiler> <spoiler summary="Hint 2"> Let $\mathrm{mn}$ denote the minimum value in $a$, a...
Binary search is your friend. , Try rooting at $n$.

Full text and comments »

  • Vote: I like it
  • +304
  • Vote: I do not like it

63.
By n0sk1ll, 4 years ago, In English
Editorial for Hello 2023 ## [problem:1779A] Author: [user:n0sk1ll,2022-12-27] <spoiler summary="Hint"> What happens when $\texttt{L}$ appears after some $\texttt{R}$ in the string? </spoiler> <spoiler summary="Solution"> Suppose that there exists an index $i$ such that $s_i = \texttt{R}$ and $s_{i+1} = \texttt{L}$. Lamp $i$ illuminates trophies $i+1,i+2,\ldots n$ and lamp $i+1$ illuminates $1,2,\ldots i$. We can conclude that all trophies are illuminated if $\texttt{L}$ appears right after some $\texttt{R}$. So, strings $\texttt{LLRRLL}, \texttt{LRLRLR}, \texttt{RRRLLL}, \ldots$ do not require any operations to be performed on them, since they represent configurations of lamps in which all trophies are already illuminated. Now, we consider the case when such $i$ does not exist and think about how we can use the operation **once**. Notice that if $\texttt{R}$ appears right after some $\texttt{L}$, an operation can be used to transform $\texttt{LR}$ into $\texttt{RL}$, and we have concluded before...
Try a greedy approach. , Try reversing the process.

Full text and comments »

Tutorial of Hello 2023
  • Vote: I like it
  • +356
  • Vote: I do not like it

64.
By aryanc403, 2 years ago, In English
Codeforces Round 970 Video Editorial (with Hints) [I'm currently live discussing the problems.](https://youtu.be/pZlCq4e21Cs) I will add problemwise timestamp after the discussion stream. You can join in if something in this blog is unclear or there are more questions. [problem:2008A] <spoiler summary="Idea"> - No of ones must be even. - If no of ones is zero, then no of twos must be even. These are necessary and sufficient conditions. </spoiler> My submission &mdash; [submission:279068120] <spoiler summary="Video Editorial"> <iframe width="853" height="480" src="https://www.youtube.com/embed/pZlCq4e21Cs?start=130" title="Codeforces Round 970 Solution Discussion | ABCDEFGH" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> </spoiler> [problem:2008B] <spoiler summary="Hint 1"> If it is a square matrix, then N must be a perfect square. </spoiler> <spoiler su...
Lets try to create array greedily. , Solve for $N=2$ first. , Solve for N = even first. , Use only $a_i = a_i - a_j$ operation. , [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm, [Permutation cycle](https://mathworld.wolfram.com/PermutationCycle.html

Full text and comments »

  • Vote: I like it
  • +41
  • Vote: I do not like it

65.
By aryanc403, 7 months ago, In English
Codeforces Round 1096 Discussion Stream (with Hints) [I'm currently live discussing the problems.](https://youtu.be/6iWYjejEfGI) I will add problemwise timestamp after the discussion stream. You can join in if something in this blog is unclear or if you have more questions. [problem:2227A] <spoiler summary="Hint 1"> When do we really need +1 step? </spoiler> <spoiler summary="Hint 2"> To reach 8, we can do 2+2+2+2 But to reach an odd number, we must need +1. Ex 9 = 2+2+2+2+1 </spoiler> <spoiler summary="Hint 3"> Now, if both x and y are odd, we will need two +1 step </spoiler> My submission &mdash; [submission:373070880] [problem:2227B] <spoiler summary="Hint 1"> Chosing substring is red herring, we can chose the complete string. </spoiler> <spoiler summary="Hint 2"> What is the most simple regular bracket string? `(((((((( ))))))` </spoiler> <spoiler summary="Hint 3"> Check if this string is regular bracket sequence or not. </spoiler> My submission &mdash; [submission:3730...
Final configration b is simply sorted array a. , What is the most simple regular bracket string, When do we really need +1 step? , `* * 2 * * * 3 * * * * * *` `* * 2 * * * * * * * 3 * *` `2

Full text and comments »

  • Vote: I like it
  • +12
  • Vote: I do not like it

66.
By aryanc403, 2 years ago, In English
Codeforces Round 973 Solution hints [problem:2013A] <spoiler summary="Idea"> In each second, we will blend $\min(x, c)$ fruits. So time taken is $\displaystyle \left \lceil \frac{n}{\min(x, c)} \right \rceil$ </spoiler> Submission &mdash; [submission:282005858] [problem:2013B] <spoiler summary="Hint 1"> $n$ is the winner. $n-1$ will lose only against $n$. </spoiler> <spoiler summary="Hint 2"> For others, if we make them first against $n-1$ and atlast we have $n-1$ and $n$ fight, their score will be added. </spoiler> <spoiler summary="Hint 3"> So the final answer will be $A_1+A_2+....+A_{n-2}+A_{n}-A{n-2}$ </spoiler> Submission &mdash; [submission:282011553] [problem:2013C] <spoiler summary="Hint 1"> Let's say we know some string $s$ is a substring of $t$. How can we extend it to find char just after this? </spoiler> <spoiler summary="Hint 2"> The idea is to query for $s0$ and $s1$; if one of them returns true, add that char to s and continue again. </spoiler> <spoiler s...
Roughly, the following is the pseudo code -

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

67.
By aryanc403, 2 years ago, In English
Codeforces Round 972 Video Editorial (With hints) Checkout [Codeforces Month of Blog Posts Pt. II (Win $500+!)](https://codeforces.me/blog/entry/133806) [Full video](https://youtu.be/-62rIr88JLU) [problem:2005A] <spoiler summary="Hint 1"> Lets fix the count of aeiou $C_a,C_e,C_i,C_o,C_u$ What is the minimum number of subsequence palindromes? </spoiler> <spoiler summary="Hint 2"> No of palindromes that consist of only a is $2^{C_a}-1$ and similarly for eiou. So lowerbound on no of palindrome is $2^{C_a}+2^{C_e}+2^{C_i}+2^{C_o}+2^{C_u}-5$ Does there exists a permutation where this lowerbound is achievable? </spoiler> <spoiler summary="Hint 3"> This lowerbound is achieved on strings of form aaaaaaaaaeeeeeeeeeeiiiiiiiiiioooooooooouuuuuuuuu </spoiler> <spoiler summary="Hint 4"> How to find optimal values of $C_a,C_e,C_i,C_o,C_u$? </spoiler> <spoiler summary="Hint 5"> In optimal answer $|C_x-C_y| \le 1$. You can try to prove it using [exchange argumen...

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it

68.
By TheScrasse, history, 5 years ago, In English
[Tutorial] Product Trick Hello everyone,<br> in this tutorial we will see a trick that can be useful in combinatorics and/or DP tasks. In particular, you can use it when the statement says something similar to "the score of an array is the product of its elements, find the sum of the scores over all the possible arrays". Prerequisites: basic combinatorics and DP The trick ------------------ The trick is very simple. "The score of an array $a$ is $\prod_{i=1}^n a_i$" can be rephrased as "if there are $n$ boxes, and the $i$-th box contains $a_i$ distinguishable balls, the score of $a$ is equal to the number of ways to color a ball for each box". This is quite obvious, but it can be extremely powerful. Let's see some problems that are trivialized by this trick. [Dwango Programming Contest 6th, problem C](https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_c) (rating: 2618) ------------------ <spoiler summary="Hint 1"> You have to output the sum of the happiness over all po...
An example of transition (with formulas) is in Hint 4.

Full text and comments »

  • Vote: I like it
  • +217
  • Vote: I do not like it

69.
By Um_nik, 8 years ago, In English
How to read problem statements But [user:Um_nik,2018-10-26], we all know how to read, we have our whooping 2 month of experience! Oh, my sweet summer child, my experiments show that many people with kinda cool achievements like medals on ROI don't know how to read statements. But don't worry, I'll teach you. Well, probably you won't understand anything, because you didn't try to understand anything in your life, you expect all hard work to be done for you by someone else. Let's start! Basic rules ================== - The result of reading the statement is usually pure math model. If story helps to build correct understanding, you can keep it, but still try to discard as many unnecessary details as possible. - Imagine you want to tell the problem to someone else. What parts you want to tell? (According to my PM, this rule won't help you). - Shorter = better. - Simpler = better. - Limitations are part of problem statement. Especially small limitations, because for small data you can try all the possib...

Full text and comments »

  • Vote: I like it
  • +381
  • Vote: I do not like it

70.
By aryanc403, 22 months ago, In English
Codeforces Round 1003 Discussion Stream (with Hints) [Original blog](https://aryanc403.com/editorial/codeforces-round-1003/) [I'm currently live discussing the problems.](https://www.twitch.tv/aryanc403) I will add problemwise timestamp after the discussion stream. You can join in if something in this blog is unclear or if you have more questions. VOD: [Twitch](https://www.twitch.tv/videos/2376873914) and [YouTube](https://youtu.be/I78mJIx4JQ0) [problem:2065A] <spoiler summary="Idea"> Find the length n of the string, and then print first n-2 chars and then i. </spoiler> My submission &mdash; [submission:305152340] [problem:2065B] <spoiler summary="Hint 1"> Let n be the length of the string. Answer is either 1 or n </spoiler> <spoiler summary="Hint 2"> If there exists adjacent 2 equal chars, we can reduce the string to length 1. The idea is we remove these 2 equal chars, and then replace them with one nearby char, thereby ensuring that we still have 2 adjacent eq...
Length 2 paths are just edges.

Full text and comments »

  • Vote: I like it
  • +11
  • Vote: I do not like it