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.

Position

Last visit:  9 months ago
Registered:  9 years ago
2.
By Rhodoks, history, 4 years ago, In English
Codeforces Round #810 Editorial Sorry for the late editorial. May this editorial help you. If you have questions, feel free to ask. [problem:1711A] <spoiler summary="hint1."> The minimal weight is at least $1$ since $1$ divides any integer (so $1$ divides $p_1$). </spoiler> <spoiler summary="solution"> Since $k+1$ does not divide $k$, a permutation with weight equal to $1$ is: $[n,1,2,\cdots,n-1]$. </spoiler> <spoiler summary="code"> ~~~~~ #include <bits/stdc++.h> using namespace std; void work() { int n; cin>>n; cout<<n<<' '; for (int i=1;i<n;i++) cout<<i<<' '; cout<<endl; } int main() { int casenum=1; cin>>casenum; for (int testcase=1;testcase<=casenum;testcase++) work(); return 0; } ~~~~~ </spoiler> [problem:1711B] <spoiler summary="hint1."> See the party as a graph. </spoiler> <spoiler summary="hint2."> Divide the vertices into two categories according to their degrees' parity. </spoiler> <spoiler summary="solution"> Let's consider ...
Let's call position $j$ a key position if it is the center position, Supposing you know an invalid position $j$ where $a_j>m$, what are the, The maximum can always be achieved in the center position of one day's, center position of one day's rain. $a_i$ is a piecewise, Now, consider an invalid position $j$; erasing the $i$-th day's rain will make it valid if and only, We say that a position $j$ is valid if $a_j\le m$.

Full text and comments »

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

3.
By Radewoosh, history, 8 years ago, In English
Blogewoosh #1 Hello, codeforces! The community wants so the community gets it! :D Here it is, my very first blog about tasks and algorithms. At the beginning I've decided to post my entries on codeforces, maybe I'll switch to something different if it becomes uncomfortable. To pour the first blood I decided to choose a task from one of the old ONTAK camps. Task's name is "different words" ([you can submit here](https://szkopul.edu.pl/problemset/problem/wTy-sxQCIKry0Ml-6RvM0L78/site/?key=statement)). The statement goes as follows: You are given $n$ words ($2 \leq n \leq 50\,000$), every of length exactly $5$ characters. Each character can be a lowercase letter, an uppercase letter, a digit, a comma... basically, it can be any character with ASCII code between $48$ and $122$ (let's say that $k$ is the number of possible characters). A task is to find all pairs of indexes of words which are $\textbf{really different}$. Two words are $\textbf{really different}$ if they differ at all $5$ corres...
corresponding position in the second word there should be a different character — for eachposition we, if they'd have this same character at some position, then this character would change into this, ones to characters. We should assign them to pairs $(character, position)$. Then everything will go, they'd have this same character at some position, then this character would change into this same

Full text and comments »

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

4.
By TLE, history, 8 years ago, In English
Linear Recurrence and Berlekamp-Massey Algorithm **#IjustWantContribution** It seems there isn't any blog about Berlekamp-Massey Algorithm around here, so I decided to go on a try. :P Acknowledgement: Hats off to matthew99 for introducing this algorithm. #### What is 'linear recurrence'? Assuming there is a (probably infinity) sequence $a_0,a_1...a_{n-1}$, we call this sequence satisfies a linear recurrence relation $p_1,p_2...p_m$, iff $\forall i \geq m,~a_i=\sum_{j=1}^m a_{i-j}p_j$. (Obviously, if $m\geq n$ any $p$ can do :P) #### How to calculate k-th term of a linear recurrence? For a polynomial $f(x)=\sum_{i=0}^{t} c_ix^i$, we define $G(f)=\sum_{i=0}^{t} c_ia_i$. Obviously $G$ satisfies $G(f)\pm G(g) =G(f \pm g)$. Because $a_i=\sum_{j=1}^m a_{i-j}p_j$, if we let $f(x)=x^m-\sum_{j=1}^m x^{m-j}p_j$, then $G(f)=0$. Also $G(fx),G(fx^2)...=0$. So $G(fg)=0$ (g is any polynomial). What we want is $G(x^k)$. Because $G(f\lfloor x^k/f\rfloor)=0$, then $G(x^k)=G(x^k \bmod f)$. [cut] We can calculate $x^k \b...
sequence at current position $t$ (from 1 to n). If we got $a_t$, then it's still good, go on. Assume, )$ time. Let's define the value of a relation sequence $p_1,p_2...p_m$ evaluated atposition $t, ; //lf: the position of ls (t') //ld: delta of ls (v') int lf,ld; for(int i=0;i, If this is not first non-zero position, we have run into this situation before. Let's say $s=\{s_1, Let's define the value of a relation sequence $p_1,p_2...p_m$ evaluated at position $t$: $\sum_{j=1, Scan from left to right, we find $1$. It's first non-zero position, so we can only make it $\{0\}$.

Full text and comments »

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

5.
By Error_Yuan, history, 3 years ago, In English
Goodbye 74TrAkToR + Problem A~E: The problems themselves are good and typical A~E. Indeed I like problem D. The pretest for A is a bit weak, and it's not a big problem yet. + Problem F: The problem has an origin. :) See the link: [click](https://www.luogu.com.cn/problem/P9394). The problem in contest is only a weakened version of the one in Luogu. + Problem G: It's said that our great coordinator had not proved the time complexity of the intended solution is correct :) If the authors did, please share it in the editorial. (although this problem is completely beyond my ability :) ) + Problem H: Oh dear [user:74TrAkToR,2023-12-30], could you please OEIS the sequence before you use the "several-integer-input" problem in rounds next time? Anyone who copied the first example and opened [https://oeis.org/A286331](https://oeis.org/A286331) could quickly get the formula. And the problem itself is not so hard imo. Anyway, it should not be used in contest, especially for the last problem. For me pers...
participate in this round, and a *2500 occurred for position Div1B/Div2D. Yet another difficulty disorder, /blog/entry/117337). I didn't participate in this round, and a *2500 occurred forposition Div1B/Div2D

Full text and comments »

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

6.
By antontrygubO_o, 6 years ago, In English
Some thoughts on recent discussions Hello everyone! I finally decided to write some response/explain my view after all recent discussions of my problems and rounds I coordinate, and I would like to make a few points. **1.** After some recent contests there were a lot of comments saying that Data structure problems should appear as easy problems (say, D2A-D2D in a Div2 of $6$ problems) ![ ](https://i.imgur.com/fmA8zgE.png) ![ ](https://i.imgur.com/m4pJLv6.png) ![ ](https://i.imgur.com/JsryG77.png) I don't think I agree with this. To begin with, I don't think that having Data Structure problem is a requirement for a good contest at all, not just in first few positions. ![ ](https://i.imgur.com/VWAOgxg.png) However, for positions D2A-D2D, I just don't see a way to properly include data structure problems. Take some Data Structure problem, it consists from two parts: <ul> <li> Knowing/implementing the Data Structure </li> <li> Actually thinking about the problem, and how this Data Structure...
* People who support my position , > People who support my position * [user:MikeMirzayanov,2020-07-12] for great systems

Full text and comments »

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

7.
By tourist, 3 years ago, translation, In English
Code Weekend #1 <div align="right" margin="20px"> <img align="right" src="/predownloaded/72/f1/72f1f31badb1452243838a0fc2553c04accff164.jpeg" alt="logo" width="300px" height="300px" margin="20px"/></div> Hello everyone! We, the [RGBTeam](https://clist.by/team/Romka,tourist,%E2%88%A83886090/) ([user:qwerty787788,2024-05-21], [user:Romka,2024-05-21] and [user:tourist,2024-05-21]), are huge fans of heuristic programming competitions and are quite saddened by the fact that they are becoming less and less frequent each year. One day, we decided to organize our own competition :) Despite the fact that such ideas often remain just ideas, this time we have a serious mindset, and now we want to invite you all to participate in the first — and hopefully not last — **[Code Weekend #1!](https://codeweekend.dev)** The competition will be held in a format quite similar to ICFPC/Google Hashcode — there will be one problem and several dozen tests for it. You will need to submit just an output according to t...
"given a chess position, find the best move," the basic version may only include pawns, bishops, and, problem is "given a chess position, find the best move," the basic version may only include pawns

Full text and comments »

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

8.
By -is-this-fft-, history, 5 years ago, In English
Self-deception: maybe why you're still grey after practicing every day I generally don't like to give much advice on "how to practice", but recently I have been thinking a lot about this and I realized that there is something that I believe affects a lot of people (though it is admittedly hard to tell) that barely gets talked about: self-deception. Self-deception is a devious thing. It can be very hard to detect, yet can be fatal to improvement. This blog is mainly directed to greys, greens and cyans that can't get out of these categories. Most examples are given with that in mind. That being said, I believe others have something to think about as well. This is my first blog on such "psychological issues" and I don't know if I'll ever make another one. It's certainly a difficult topic to write about because for most of the blog, the message is "your practice is not as good as you think it is" or even "you aren't as good as you think you are" which can of course be a hard thing to hear. Thus, I have to somehow be very gentle while getting the poin...
based on the position in the contest (like "Div.1 D") used to only show one problem. Sadly, they don't

Full text and comments »

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

9.
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...
, your position in the standings makes no difference. I can feel awful after winning a contest if I, Unless there are prizes involved, your position in the standings makes no difference. I can feel

Full text and comments »

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

10.
By -is-this-fft-, history, 5 years ago, In English
[Tutorial] Collection of little techniques #### Introduction There are a number of "small" algorithms and facts that come up again and again in problems. I feel like there I have had to explain them many times, partly because there are no blogs about them. On the other hand, writing a blog about them is also weird because there is not that much to be said. To settle these things "once and for all", I decided to write my own list about about common "small tricks" that don't really warrant a full tutorial because they can be adequately explained in a paragraph or two and there often isn't really anything to add except for padding. This blog is partly inspired by [user:adamant,2022-03-15]'s [blog](48417) from a few years ago. At first, I wanted to mimic adamant's blog structure exactly, but I found myself wanting to write longer paragraphs and using just bolded sentences as section headers got messy. Still, each section is short enough that it would not make much sense to write separate blogs about each of these things. A...
$, we associate every position in the array $\mathrm{dp}[v]$ with a descendant of $v$. The array

Full text and comments »

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

11.
By HosseinYousefi, 12 years ago, In English
C++ Tricks I see lots of programmers write code like this one: ~~~~~ pair<int, int> p; vector<int> v; // ... p = make_pair(3, 4); v.push_back(4); v.push_back(5); ~~~~~ while you can just do this: ~~~~~ pair<int, int> p; vector<int> v; // ... p = {3, 4}; v = {4, 5}; ~~~~~ [cut] [This](http://codeforces.me/blog/entry/10124) is a great C++11 tutorial for those who want to know more about C++11. #### 1. Assign value by a pair of {} to a container I see lots of programmers write code like this one: ~~~~~ pair<int, int> p; // ... p = make_pair(3, 4); ~~~~~ while you can just do this: ~~~~~ pair<int, int> p; // ... p = {3, 4}; ~~~~~ even a more complex `pair` ~~~~~ pair<int, pair<char, long long> > p; // ... p = {3, {'a', 8ll}}; ~~~~~ What about `vector`, `deque`, `set` and other containers? ~~~~~ vector<int> v; v = {1, 2, 5, 2}; for (auto i: v) cout << i << ' '; cout << '\n'; // prints "1 2 5 2" deque<vector<pair<in...
This function returns number of leading 0-bits of x which starts from most significant bitposition, position. x is `unsigned int` and like previous function this function with suffix 'l' gets a `unsigned

Full text and comments »

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

12.
By Tony2_CF, history, 11 months ago, In English
The Time Complexity Lower Bound for Segment Tree Beats is log^2 Original Post: https://jiry-2.blog.uoj.ac/blog/1404 The following content is translated by Gemini 2.5 Pro. ## Part 1: Introduction to the Hacking Method ### How to Map the Hack Sequence to a Segment Tree First, we are given a Hack sequence of length $len$. After $O(1)$ range addition operations and $\Theta(\log len)$ global $\text{chkmax}$ operations, this sequence becomes a cyclic shift (rotation) of the original sequence. Since a cyclic shift does not affect our range addition and global $\text{chkmax}$ operations (we can simply shift the indices for the range addition accordingly), we can consider the sequence as unchanged. If we have such a sequence, let $len=n^{\frac{1}{3}}$, and place such a sequence at intervals of $n^{\frac{2}{3}}$. Each sequence corresponds exactly to a segment tree interval. A subtree of size $n^{\frac{2}{3}}$ contains exactly one such segment tree interval. For the Hack sequence, the range addition operations are performed one by one on eac...
+b_n$. The subsequent segments all satisfy $x_1=a_n$, which is precisely the cuttingposition. The

Full text and comments »

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

13.
By PinkieRabbit_buster, 3 years ago, In English
PinkieRabbit Cheated in Div. 1 Contest on Apr 27 I am writing to report an incident of cheating by PinkieRabbit during the recent contest 1965 on Codeforces. **PinkieRabbit asked help about problem D from others during the contest,** which is definitely against the contest rules. I have attached the evidence of the cheating behavior in the appendix, please read it. This evidence clearly shows the communications PinkieRabbit had with another person during the contest. It is a contest recording video published after contest by himself. As a former fan of PinkieRabbit, after seeing this video, I was shocked by how dishonest PinkieRabbit was. I believe such actions undermine the integrity of the competition and the platform as a whole. [user:win114514,2024-05-05] cheated by grouping up in contest 1905, finally punished by skipping. Therefore, I respectfully request that Codeforces take appropriate action against PinkieRabbit to maintain the fairness of the contests on Codeforces. He only cheated in one problem this round, so I sugg...
that, —— this is deleted —— then so that the killed (deleted) position is these, on this is

Full text and comments »

14.
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"; } } ...
On the other hand, suppose $A_r\le MT_{r,K}$. Let $v$ be the minimum position such that $A_r\le MT_, To speed this up, we use a segment tree to store the value of $dp_{i - 1, p}$ at position $p$. To, \limits_{i = k}^n v_i$. We can use a segment tree where position $p$ of the segment tree stores

Full text and comments »

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

15.
By GlebsHP, history, 4 years ago, In English
Nebius Welcome Round (Div. 1 + Div. 2, rated, t-shirts!) Hello, Codeforces! [user:Zlobober,2023-03-09] and I are glad to invite you to compete in Nebius Welcome Round (Div. 1 + Div. 2) that will start on [contest_time:1804]. The round will be rated for everyone and will feature 8 problems that you will have 2 hours to solve. I feel really thrilled and excited about this round as this is the first time I put so much effort in a Codeforces contest since I quit being a round coordinator in December 2016 (wow, that was so long ago)! We conduct this round to have some fun and we also hope to find some great candidates to join Nebius team. Solving 5+ problems in our round will be a good result and will count as one of the coding interviews. Apart from that top 25 contestants and 25 random contestants placed 26-200 will receive a branded Nebius t-shirt! <img style="float: right; margin: 0 1em 0.5em 1em; width: 400px;" src="/predownloaded/40/37/403770e78d9c8962d0bc0c20a9e1c45d0e3c5df9.png"> Some information about Nebius. I have join...

Full text and comments »

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

16.
By neal, 8 years ago, In English
Blowing up unordered_map, and how to stop getting hacked on it C++ has always had the convenient data structures `std::set` and `std::map`, which are tree data structures whose operations take $O(\log n)$ time. With C++11, we finally received a hash set and hash map in `std::unordered_set` and `std::unordered_map`. Unfortunately, I've seen a lot of people on Codeforces get hacked or fail system tests when using these. In this post I'll explain how it's possible to break these data structures and what you can do in order to continue using your favorite hash maps without worrying about being hacked [cut] . So how are they hackable? We always assume hash maps are $O(1)$ per operation (insert, erase, access, etc.). But this depends on a key assumption, which is that each item _only runs into $O(1)$ collisions on average_. If our input data is completely random, this is a reasonable assumption. But this is no longer a safe bet when the input isn't random, especially so if someone is adversarially designing inputs to our code (a.k.a. hacking ph...
mods by a prime number, and the result is used as the appropriate position in the hash table.

Full text and comments »

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

17.
By zscoder, history, 7 years ago, In English
[Tutorial] Generating Functions in Competitive Programming (Part 2) Welcome to Part 2 of my tutorial on generating functions. The [first part](https://codeforces.me/blog/entry/77468) focused on introducing generating functions to those without any background in generating functions. In this post, I will demonstrate a few applications of generating functions in CP problems. Let us start with some relatively straightforward examples. Note: Unless stated otherwise, all computations are done modulo a convenient prime (usually $998244353$). Also, $[n]$ denotes the set $\\{1,2,...,n\\}$. ### Blatant Applications in Counting Problems **Problem.** [AGC 005 Problem F](https://atcoder.jp/contests/agc005/tasks/agc005_f) You have a tree $T$ with $n$ vertices. For a subset $S$ of vertices, let $f(S)$ denote the minimum number of vertices in a subtree of $T$ which contains all vertices in $S$. For all $1 \le k \le n$, find the sum of $f(S)$ over all subsets $S$ with $|S| = k$. Constraints: $n \le 2 \cdot 10^{5}$. <spoiler summary="Solution"> First, ...
Note that for position $j$ to contribute to the answer, the prefix $p_{1}$, $p_{2}$, ..., $p_{j, Now, let's do some double counting. Fix a position $1 \le j \le n$. Can we calculate how many times

Full text and comments »

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

18.
By SlavicG, 5 years ago, In English
How to use Codeforces [GUIDE] I see a lot of newcomers struggling to use the website to it's fullest, so I decided to write a blog that has all important information about how to use Codeforces in a single place. I will update it with time, so feel free to write your suggestions/questions in case I missed something and I will be glad to add it to the post! I would like to thank [user:_Vanilla_,2022-02-05] and [user:mesanu,2022-02-05] for helping me write the blog, and [user:Monogon,2022-02-05], [user:down,2022-02-05] and [user:AlperenT,2022-02-05] for proofreading and giving suggestions. #### Navigating through pages ![ ](https://media.discordapp.net/attachments/705371983650619454/928235498487570442/bandicam_2022-01-05_12-36-00-134.jpg?width=991&height=110) It's possible to navigate through most pages of Codeforces using the bar on the top, I will talk about what each tab does more in depth below: #### The Help Page The help page contains the answer to a lot of questions about Codeforces, such as rati...
position in the contest, it’s time limit, memory limit, input/output format, samples and problem notes.

Full text and comments »

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

19.
By 300iq, 5 years ago, In English
Invitation to Good Bye 2021: 2022 is NEAR Hello Codeforces! We have a pleasure to invite you to [Good Bye 2021](https://codeforces.me/contests/1616), which will take place on [contest_time:1616]. You will have **2 hours** to solve the problems. The round will be rated for participants of both divisions. The problems for this round were prepared by [user:300iq,2021-12-29], with the help of excellent coordinators [user:KAN,2021-12-29] and [user:74TrAkToR,2021-12-29]. We would like to thank all the testers, who made this round possible: [user:gamegame,2021-12-29], [user:thenymphsofdelphi,2021-12-29], [user:ko_osaga,2021-12-29], [user:golions,2021-12-29], [user:Ashishgup,2021-12-29], [user:izban,2021-12-29], [user:prabowo,2021-12-29], [user:74TrAkToR,2021-12-29], [user:Devil,2021-12-29], [user:manish.17,2021-12-29], [user:Discombobulated,2021-12-29], [user:minhcool,2021-12-29], [user:AlFlen,2021-12-29], [user:Utkarsh.25dec,2021-12-29], [user:NemanjaSo2005,2021-12-29], [user:wxhtzdy,2021-12-29], [user:ajit,2021-12-29], [...

Full text and comments »

Announcement of Good Bye 2021: 2022 is NEAR
  • Vote: I like it
  • +625
  • Vote: I do not like it

20.
By -is-this-fft-, history, 4 years ago, In English
On "is this greedy or DP", forcing and rubber bands #### Introduction When it comes to "problem-solving techniques", there are roughly 3 levels: 1. Concrete algorithms (Kruskal's algorithm, Li-Chao tree, fast Fourier transform) 2. General patterns (dynamic programming, greedy, square-root decomposition) 3. Meta-strategies ("how do I even go about solving this problem?") There is some grey area, but in general this classification works well. [Many tutorials](https://codeforces.me/catalog) have been written about ideas that fall into 1 or 2. But very little has been written about the third category. On the catalog, I think the only blogs that really qualify are [this](62730) and [this](20548). There is also [this](92248?#comment-809401) valuable comment. As to why there is so little written, I think I can identify two reasons. - Most strong contestants don't really consciously think about these. After solving a problem with FFT, it's hard not to know you used FFT. If you used DP, even if you did it without thinki...

Full text and comments »

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

21.
By ko_osaga, history, 4 years ago, In English
[Tutorial] On Range LIS Queries, Part 1 Hello, Codeforces! At some point of life you want to make a new data structure problem with short statement and genius solution. LIS (Longest Increasing Subsequence) is a classic problem with beautiful solution, so you come up with the following problem: * Given a sequence $A$ of length $N$ and Q queries $1 \le i \le j \le N$, compute the length of Longest Increasing Subsequence of $A[i], A[i + 1], \ldots, A[j]$. But on the other hand this looks impossible to solve, and you just give up the idea. I always thought that the above problem is unsolved (and might be impossible), but very recently I learned that such queries are **solvable** in only $O(N \log^2 N + Q \log N)$ time, not involving any sqrts! The [original paper](https://arxiv.org/abs/0707.3619) describes this technique as *semi-local string comparison*. The paper is incredibly long and uses tons of scary math terminology, but I think I found a relatively easier way to describe this technique, which I will show in t...
P_{i_{2}} \boxdot \ldots \boxdot P_{i_{k-1}}$ correctly denotes the position of seaweeds after $k - 1, permutation $P$ where $P(i)$ stores the final position of $i$-th seaweed from the beginning. Let's say, )$-th position., * In the beginning, there is $i$-th seaweed in $i$-th position. * For each $1 \le x \le k$, we

Full text and comments »

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

22.
By Phantasmagorias, history, 5 years ago, In English
Codeforces Round #745 Editorial I'm very sorry about all the inconvenience, and I would like to bear the blame. Much thanks to those who help me prepare this round. It's not their fault. And much thanks to your participation. [problem:1581A] ------------------ idea: [user:interlude,2021-09-30] preparation: [user:CQXYM,2021-09-30] tutorial: [user:CQXYM,2021-09-30] Assume a permutation $p$, and $\sum_{i=2}^{2n}[p_{i-1}<p_i]=k$. Assume a permutaion $q$, satisfying $\forall 1 \leqslant i \leqslant 2n, q_i=2n-p_i$. We can know that $\forall 2 \leqslant i \leqslant 2n,[p_{i-1}<p_i]+[q_{i-1}<q_i]=1$. Thus,$\sum_{i=2}^{2n}[q_{i-1}<q_i]=2n-1-k$, and either $p$ should be counted or $q$ should be counted. All in all, the half of all the permutaions would be counted in the answer. Thus, the answer is $\frac{1}{2}(2n)!$. The time complexity is $O(\sum n)$. If you precalulate the factors, then the complexity will be $O(t+n)$. ----- <spoiler summary="solution"> ~~~~~ #include<stdio.h> int f[100001]; int m...
and the same start position in the block. It's fine to use an array to record this. Number of, enumerate the position of the bigest number in the permutaion. We call the position is $a$. The, }{2} \rceil$. Consider that cut the cycle to a sequence at the first position $p$ satisfying $\max

Full text and comments »

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

23.
By Um_nik, history, 14 months ago, In English
One-letter variables Complete shitpost, don't take it seriously. We were discussing `#define int long long` and I suggested defining it to one letter if you want to save on typing so desperately. [user:jeroenodb,2025-10-11] said that those are reserved for variables, which prompted me to think, "Is there a letter I don't standardly use for some particular purpose?" Then I compiled the following list, and then I thought, "Well, I already wrote it, let's put it on cf", so here we are. ~~~~~ a - array, but also all sorts of stuff b - second array c - third array / count d - delta / divisor e - event / edge f - flag g - graph / second flag h - third iterator / third flag / height i - iterator j - second iterator k - third input size / some parameter (i know, those are all parameters, but for some reason k is parameter) l - left m - number of edges / second input size n - input size o - ??? p - permutation / position q - number of queries / query / second permutation / second position r - r...
- permutation / position q - number of queries / query / second permutation / secondposition r, size n - input size o - ??? p - permutation / position q - number of queries / query / second

Full text and comments »

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

24.
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;...
$j$ categories that have appeared at least once (if adding the variable at position $i+1$ brings, variablesin in the front position of $p$ to be less than $0.5$, and $\ge 1$ condition limits variables in

Full text and comments »

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

25.
By FieryPhoenix, 7 years ago, In English
Codeforces Round #638 (Div. 2) Editorial [problem:1348A] <spoiler summary="Tutorial"> [tutorial:1348A] </spoiler> <spoiler summary="Solution"> ~~~~~ #include <bits/stdc++.h> using namespace std; void solve(){ int N; cin>>N; //note: 1<<X means 2^X //we put largest coin in first pile int sum1=(1<<N), sum2=0; //we put n/2-1 smallest coins in first pile for (int i=1;i<N/2;i++) sum1+=(1<<i); //we put remaining n/2 coins in second pile for (int i=N/2;i<N;i++) sum2+=(1<<i); cout<<sum1-sum2<<endl; } int main(){ int t; cin>>t; while (t--) solve(); } ~~~~~ </spoiler> [problem:1348B] <spoiler summary="Tutorial"> [tutorial:1348B] </spoiler> <spoiler summary="Solution"> ~~~~~ #include <bits/stdc++.h> using namespace std; void solve(){ int N,K; cin>>N>>K; set<int>s; for (int i=0;i<N;i++){ int a; cin>>a; s.insert(a); } //if more than K distinct numbers, print -1 if (s.size()>K){ cout<<-1<<endl; return; ...
int N; int a[200005],b[200005]; int label[200005]; //the label of the person at i-thposition in

Full text and comments »

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

26.
By -is-this-fft-, history, 2 years ago, In English
Things you should know before you discuss cheating Cheating has been discussed a lot lately. I'm writing a blog post about it with actual data (mainly, I want to know if there is an actual increase). However, in the many discussions that have ensued both here and on Discord servers, I noticed several recurring misconceptions. I wrote a section to debunk them and it grew kind of long, long enough to be a post in itself. So while my scripts are running, we can treat this as a kind of teaser. ### Things you should know before you write a comment about cheating Vocabulary: - _To plagiarize_ [means](https://dictionary.cambridge.org/dictionary/english/plagiarize) to use someone else's work while passing it off as yours. It refers to the act itself, **not** to its detection or punishment. "jrandomcoder plagiarized all of his solutions in round 987" is a meaningful statement. "jrandomcoder cheated in round 987 but he still hasn't gotten plagiarized, I request [user:MikeMirzayanov,2024-08-16] to look into this" is not. - _Plague_ is a...
been in a position where I put in a lot of work into something. And then people who don't even look

Full text and comments »

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

27.
By Sharon, history, 8 years ago, In English
I am removing my contest proposal from Codeforces I am removing my contest proposal from Codeforces. Note: This is a serious blog post. Also, the opinions presented in this blog are my own and not of my friend [user:BiIIy,2018-12-26] who wrote the contest with me. Today I have removed my contest proposal from Codeforces. I should probably have done this a long time ago. The proposal was made in February, but the problems were written and finished by March, and that is when I opened the contest proposal for review and messaged [user:KAN,2018-12-26]. It is currently December and no progress or development has been made regarding my contest proposal since, so I will be removing it. I have multiple reasons for removing my contest proposal: - I have no motivation to host an online contest anymore. - I am involved in problem setting with two other high school programming contests in my university, and I write, host, and judge another contest for local high schools. - I have forgotten that I “was in the queue” for writing a...
your contest for review, you should be able to see your position in the queue. This way you can see

Full text and comments »

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

28.
By awoo, history, 7 years ago, translation, In English
Educational Codeforces Round 87 Editorial [problem:1354A] Idea: [user:BledDest,2020-05-18] <spoiler summary="Tutorial"> [tutorial:1354A] </spoiler> <spoiler summary="Solution (pikmike)"> ~~~~~ t = int(input()) for _ in range(t): a, b, c, d = map(int, input().split()) if b >= a: print(b) continue if c <= d: print(-1) continue a -= b dif = c - d print(b + (a + dif - 1) // dif * c) ~~~~~ </spoiler> [problem:1354B] Idea: [user:BledDest,2020-05-18] <spoiler summary="Tutorial"> [tutorial:1354B] </spoiler> <spoiler summary="Solution (BledDest)"> ~~~~~ #include<bits/stdc++.h> using namespace std; char buf[200043]; int main() { int t; scanf("%d", &t); for(int i = 0; i < t; i++) { scanf("%s", buf); string s = buf; int ans = int(1e9); int n = s.size(); vector<pair<char, int> > c; for(auto x : s) { if(c.empty() || c.back().first != x) c.push_back(make_pair(x, 1)); else c.back().second++; } int m = c.size(); for...
for (int i = 0; i < N; i++) for (int position = 0; position < N; position, inline void solve() { //check first position mt19937 rnd(lst ^ (n * 1024 + k)); for(int q = 0

Full text and comments »

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

29.
By brunomont, 6 months ago, In English
Chinese Postman Problem: How I Ran a 180 km Ultramarathon Through Every Street in My City Hello, Codeforces! A couple of years ago, a friend of mine told me that two cyclists had passed through every single street in the center region of the city I live in (Belo Horizonte, southeastern Brazil), on the [third try](https://www.strava.com/activities/1030665876/overview). <spoiler summary="First try"> After ~160 km, they had not completed 1/3 of the goal. [Strava link](https://www.strava.com/activities/976021527). <img src="/predownloaded/8a/53/8a53829f7d78e88808a3ff751b64406ec2fc0efd.png" style="width: 600.0px;max-width: 100.0%;max-height: 100.0%;"> </spoiler> <spoiler summary="Second try"> They were better prepared, but one of the guys was run over by a car (no big injuries). [Strava link](https://www.strava.com/activities/999450285). <img src="/predownloaded/85/8f/858fdcdcfda93cd1d9c7c59db7dbfad9e63d6ea2.png" style="width: 600.0px;max-width: 100.0%;max-height: 100.0%;"> </spoiler> <center> <img src="/predownloaded/8d/5c/8d5cfb677a361654105e49f36f214c35...
include $C'$, inserting $C'$ in the corresponding position of vertex $x$ in $C$.

Full text and comments »

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

30.
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...
easier tasks than to make hard tasks. Position C required us more effort than position F required us, not like it (probably it was too hard for its position), and we swapped it back to C0. C' was not, tasks on the position. But somehow, very surprisingly, it was **not solved** by o1. I am still, '. A lot of testers felt A' a bit too hard for its position, and we had to find a new one. Luckily, - At this point, most people struggled on E'. We decided that it is not a good fit for theposition, - The first task to get swapped was A'. A lot of testers felt A' a bit too hard for itsposition

Full text and comments »

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

31.
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

32.
By sdnr1, history, 8 years ago, In English
[Tutorial] Searching Binary Indexed Tree in O(log(N)) using Binary Lifting **NOTE** : Knowledge of Binary Indexed Trees is a prerequisite. ## Problem Statement Assume we need to solve the following problem. We have an array, $A$ of length $N$ with only non-negative values. We want to perform the following operations on this array: 1. Update value at a given position 2. Compute prefix sum of $A$ upto $i, i \leq N$ 3. Search for a prefix sum (something like a `lower_bound` in the prefix sums array of $A$) [cut] <br> ## Basic Solution Seeing such a problem we might think of using a Binary Indexed Tree (BIT) and implementing a binary search for type $3$ operation. Its easy to see that binary search is possible here because prefix sums array is monotonic (only non-negative values in $A$). The only issue with this is that binary search in a BIT has time complexity of $O(log^2(N))$ (other operations can be done in $O(log(N))$). Even though this is naive, here is how to do it: <spoiler summary="Implementation"> `int sum(pos)` -> comput...
exercise for the readers. **HINT** : Each position in `bit` stores sum of a power of 2 elements, size of the array. Then we check that if we lift `pos` to the new position, then the value of sum, 1. Update value at a given position, We are trying to find `pos`, which is the position of lower bound of `v` in prefix sums array, position 2. Compute prefix sum of $A$ upto $i, i \leq N$ 3. Search for a prefix sum (something like, return pos + 1; // +1 because 'pos' will have position of largest value less than 'v' } ~~~~~

Full text and comments »

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

33.
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....

Full text and comments »

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

34.
By KAN, 9 years ago, translation, In English
Codeforces Round #476 (Div. 2) [Thanks, Telegram!] Hi everyone! <img src="/predownloaded/bf/c1/bfc15c5c56f3e421cc2799e5e1e0273cac1e3605.jpg" alt="digital resistance" title="digital resistance" style="float:right; margin: 0 1em 1em 1em; width:30%"/> Tomorrow, [on the April 25-th, 2018 at 17:35 UTC](http://www.timeanddate.com/worldclock/fixedtime.html?day=25&month=4&year=2018&hour=20&min=35&sec=0&p1=166) we are holding [contest:965]! The round will be rated for the second division participants, members with higher rating can take part out of competition. I give the floor to [user:MikeMirzayanov,2018-04-24] to announce the round: _This round opens a series of thanks-rounds to those who significantly supported Codeforces in the crowdfunding campaign for the 8th anniversary. Although Telegram is not explicitly present on the list of donators, for us this is the first and most important friend. We express our gratitude to Telegram and personally to Pavel Durov for the constant support and send regards from programming contest com...
declared in our country, I admire and express support for Pavel's principled position on protecting

Full text and comments »

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

35.
By Dominater069, 2 years ago, In English
Analyzing how good O1-Mini actually is I would like to thank [user:redpanda,2024-09-13] and [user:qmk,2024-09-13] for their great help in writing and reviewing this blog. They are also the users who queried O1-mini for all the following problems. We tried O1-mini on several problems, from a variety of sources. Let's list the results first. **Note** : - Some of the WA verdicts here actually means that the AI just "stopped thinking" which means the AI thought for a long enough time without any useable results so it ran into an error. - All ratings mentioned are Codeforces ratings, the Atcoder ratings have been converted to codeforces rating. To measure the approximate codeforces rating of the atcoder problems mentioned here, you can use https://kenkoooo.com/atcoder/#/table/ + https://silverfoxxxy.github.io/rating-converter. <h4> D2ABs </h4> - [problem:1762B] [<a class="rated-user user-gray" title="Gray">1100</a>] <a class="rated-user user-green" title="Green AC">AC</a> - [problem:1998B] [<a class="rated-...

Full text and comments »

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

36.
By -is-this-fft-, 5 years ago, In English
[Tutorial] Proving the inverse Ackermann complexity of Union-Find #### Introduction Most of us are familiar with the union-find data structure and the two optimizations one can do on it: _union by rank_ and _path compression_. Most tutorials will introduce these methods and state that if both optimizations are used, the complexity will be $\mathcal{O}((n + m) \alpha(n))$. Here, $n$ and $m$ are the number of vertices and queries respectively. What is $\alpha$? Generally, we are told that $\alpha$ is some mysterious function that grows very slowly: $\alpha(N) < 5$ where $N$ is the number of subsets of particles in the observable universe and whatnot. What it is is usually not clarified very much. And there is typically no proof (or intuition and other such justifications) as to why the complexity is like that: usually we're told that the complexity analysis is quite long and complicated. At the time of writing, both [cp-algorithms](https://cp-algorithms.com/data_structures/disjoint_set_union.html) and [Wikipedia](https://bit.ly/3EvnzrI) are like th...
We have now declared several restrictions on the position $a_{i, j}$ of the $j$-th checkline of

Full text and comments »

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

37.
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...
$. There are 3 cases depending on the position of $A_j$ relative to $A_i,A_k$:, One option would be remembering the last position of each integer using STL `map<>`/`set<>` data

Full text and comments »

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

38.
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...
Suppose you have found a valid $y$. Shift it one position to the right, - We maintain a segment tree. The $i$-th position of the segment tree contains information about, position $i$, and perform the operation on it. What happens during the operation?

Full text and comments »

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

39.
By okwedook, 6 years ago, translation, In English
Codeforces Round #703 (Div. 2) Editorial [problem:1486A] <spoiler summary="Hint1"> What's the lower bound for the amount of blocks for the answer to be $\texttt{YES}$? </spoiler> <spoiler summary="Hint2"> Check the predicate for every prefix. </spoiler> <spoiler summary="Solution"> Let's consider the smallest amount of blocks we need to make the first $i$ heights ascending. As heights are non-negative and ascending the heights should look like $0, 1, 2, 3, ..., i - 1$, so the minimum sum is $\frac{(i - 1) \cdot i}{2}$. It turns out that this is the only requirement. If it's not the case for every prefix the answer is $\texttt{NO}$ because we can't make some prefix ascending. Otherwise the answer is $\texttt{YES}$ because you can move the blocks right till there is at least $i$ blocks in the $i$-th stack and this would make the heights ascending. </spoiler> Solution using C++: [submission:107892022]<br> Solution using Python: [submission:107892053] [problem:1486B] <spoiler summary="Hint1"> Is proble...
How to solve the problem if the second maximum element is at position $1, $ is obviously the position of the maximum element. Now we need to use binary search to find such $m, position $i$ choose the minimum prefix sum amongst positions $0, 1, ..., i - k$, which can be done using

Full text and comments »

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

40.
By neal, 6 years ago, In English
Unofficial Editorial for Educational Round 95 (Div. 2) Here are my approaches to the problems today: #### [problem:1418A] Since the second trade is the only way to get coal, we clearly need to perform the second trade $k$ times. So how many times do we need to do the first trade? We can see that in order to end up with enough sticks and coal by the end, we need to obtain $ky + k$ sticks ($ky$ to convert to coal and $k$ to save as sticks). Since the first trade really just gives us $x - 1$ new sticks each time, we'll need to make $\displaystyle \left \lceil \frac{ky + k - 1}{x - 1} \right \rceil$ first trades ([reference to floor and ceiling functions](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions) for anyone unfamiliar). For implementation details, note that for positive integers $a$ and $b$, $\displaystyle \left \lceil \frac{a}{b} \right \rceil = \left \lfloor \frac{a + b - 1}{b} \right \rfloor$. Code: [submission:92851684] #### [problem:1418B] We can think about the problem as follows: we want to order the $a_i$ to...
gaps in a multiset. Then when we add/erase a position $x_i$, we only have to adjust three gaps: $x_{i

Full text and comments »

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

41.
By Errichto, 8 years ago, In English
ROI 2018 in GYM Hi. On Wednesday at [9:05 CET / 8:05 UCT](https://www.timeanddate.com/worldclock/fixedtime.html?day=27&month=3&year=2019&hour=11&min=5&sec=0&p1=166) you can participate in the GYM version of the finals of 2017-2018 Russian Olympiad in Informatics (ROI), Day 1. And on Thursday there will be day 2, same time. Links to GYM contets: [day1](https://codeforces.me/gym/102147) and [day2](https://codeforces.me/gym/102154). 5 hours, 4 problems, IOI-style scoring with subtasks. Statements will be available in three languages: English, Russian, Polish. We wanted to use those problems in a camp in Warsaw so we had to import the problems to some system anyway. Then why not Polygon+Codeforces and thus allowing everybody to participate? Huge thanks to [user:MikeMirzayanov,2019-03-25] for helping me with using GYM. And credits to problem authors: [user:Andreikkaa,2019-05-21] for Radium, [user:Endagorion,2019-05-21] for Viruses, [user:pashka,2019-05-21] for Innophone, Георгий Корнее...
One of possible solutions is greedy. Let $i$ be the position of, To get 80 points, we can insert each element to its position in, element is the number of operations required to move an element from position $i$ toposition $n$. The, from bit $k-1$. If there are two numbers with 1 on that position, we finish and the answer is NO, one by one. For each of remaining $N-1$ cell, maintain the position of the strongest safe virus, , maintain the position of the strongest safe virus. When a new safe virus appears (because we moved to, The remaining issue is that maybe we first move one element from position $1$ to position $n$, then

Full text and comments »

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

42.
By Radewoosh, history, 5 years ago, In English
My own algorithm — offline incremental strongly connected components in O(m*log(m)) Hello Codeforces! As all of you know, there are so many known algorithms named after people who invented them &mdash; from the easiest ones, like Dijkstra, to the harder ones, like Berlekamp–Massey algorithm. These algorithms were innovative when they were invented, so of course, it's good that they are named after their inventors. But, today, I've seen a blog about the solution to the problem "compute LCS of two strings in time $O((n + k) \cdot \log(k))$, where $n$ is the sum of lengths of the strings, and $k$ is the number of pairs of matching positions in them". To be honest, it a bit pissed me off that even this algorithm is named after its creators. Is it ok to name the solution to every possible problem after its author? I won't judge it. Anyway, I want my very own Radecki algorithm, so let me give it a try. If anyone has ever heard about it &mdash; it's cool. Let me know, and it'll be just another helpful blog on Codeforces. Let's imagine the following problem: there is...

Full text and comments »

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

43.
By Intellegent, 7 months ago, In English
Spectral::Cup 2026 Round 2 (Codeforces Round 1100, Div. 1 + Div. 2) <center> <img src="https://i.imgur.com/lPGWfOR.png" style="width: 300.0px;max-width: 100.0%;max-height: 100.0%;"></center> <center> <h1> Greetings Codeforces! </h1> </center> [user:sammyuri,2026-05-18], [user:myst-6,2026-05-18] and I are absolutely chuffed to bits to invite you all to have a go at Codeforces Round ${12}_{10}$ ([contest:2229]), kicking off at [contest_time:2229]. There will be **9** absolute cinema problems for you to solve over the course of **3 hours**, some problems will have multiple parts. This round will be combined for Division 1 and Division 2 and will be rated for everyone. I’d like to raise a glass to the following brilliant minds for making this whole thing possible: - [user:dominater069,2026-05-18] for splendid coordination. - [user:um_nik,2026-05-18] for preliminary review. - The fine assembly of testers: [user:arvindf232,2026-05-18], [user:evenimage,2026-05-18], [user:geothermal,2026-05-18], [user:sana,2026-05-18], [user:wansur,20...
class="rated-user user-legendary" href="https://codeforces.me/profile/" style="background-position

Full text and comments »

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

44.
By DrSwad, history, 7 years ago, In English
A Beautiful Technique for Some XOR Related Problems ## Inspiration I'm very excited about this blog, as it took me quite a lot of effort and scavenging through the internet to completely grasp the concept of this technique(That's probably because I have almost zero knowledge in Linear Algebra or I'm just plain dumb). So I feel like I genuinely conquered a challenge, and I really want to share it with someone. But there's no way my CP friends circle will believe it, they'll think I'm just trying to show off :P So here I am, sharing it on CF. I also created a [personal blog](https://drschwad.github.io/), so that if I ever feel like sharing something again(not only about CP), I can write a blog there. I also added this same post [there](https://drschwad.github.io/2019-08-06-z2-space-xor-trick/), you can read it there if you prefer dark theme. I'll be pleased to hear any thoughts on the blog or if I can improve it in some way ^\_^ ## Introduction Since it concerns Linear Algebra, there needs to be a lot of formal stuff going on ...
first position with a set bit, let it be the last position with a set bit., . Refer to this point as $P(0, 1).$ Then, the position vector of $2$ will be $\overrightarrow{OP}$ where, An interesting thing happens here, if we add the two position vectors, the corresponding, position vectors that consists of $d$ coordinates, all coordinates being elements of $\mathbb{Z\_2}.$ For

Full text and comments »

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

45.
By Geothermal, history, 7 months ago, In English
My Solutions to Spectral::Cup 2026 Round 1 (CF Round 1094) Since the editorial for today's Div. 1 hasn't been published yet, I thought I'd share solution sketches. Some of these won't include all of the specific details, but hopefully they should communicate the main ideas. (I didn't compete officially, but I got AC on all of the problems using the below approaches, so I'm fairly confident in correctness.) Feel free to leave questions below and I'll respond if I have time. ## A &mdash; A Wonderful Contest If any problem has $100$ subtasks, the answer is yes: we can achieve an arbitrary score by solving some of the other problems fully and by solving the right number of subtasks of the $100$-subtask problem. Otherwise, there is no way to achieve a score of 1, so the answer is no. ## B &mdash; Artistic Balance Tree Note that each of the reversal operations swaps odd positions with odd positions and even positions with even positions, as $u-i$ and $u+i$ differ by $2i$ and thus have the same parity. Thus, when we are to mark an od...
$s_i - s_j$ to the summation, where $s_k$ is the sum of the suffix of $a$ starting atposition $k, should place $1$ at the position $i$ such that the sum of $a_i, \cdots, a_n$ is minimized, and so on., there are only $n+1$ such arrays in total (the zero array and all arrays with $1$ in oneposition, we are to mark an odd index, we can only mark an element originally at an odd position, and vise

Full text and comments »

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

46.
By galen_colin, 6 years ago, In English
Hybrid Tutorial #-1: Heavy-Light Decomposition **[Here](https://www.youtube.com/watch?v=_G_LMuLWMaI&list=PLDjGkpToBsYDx4GWu2u87sTqt6ICELz-T) is a playlist of all hybrid tutorials I've done.** # "Intro" _Timestamp: [00:00](https://youtu.be/_G_LMuLWMaI)_ Hi! Definitely not inspired by [this comment](https://codeforces.me/blog/entry/81086?#comment-675431), I've decided to try something that seems relatively novel &mdash; combining a blog and video tutorial into one, in a "hybrid" fashion. Both should be usable independently, but they will have the same "flow" and structure so you can reference both for concepts that are harder to grasp, and the two will supplement each other. The goal of these is to be **complete** &mdash; beneficial for both video and blog lovers, as well as full of enough information that anyone without much of an idea of what the concept is should be able to fully understand. There will be code as well, however, I very highly recommend not looking at it, but rather working out the implementation for yours...
simply a wrapper for the update function in my segment tree, and that call to it sets theposition, * Compute the XOR of values on the subarray from $l$ to $r$ * Update the value atposition $i$ to, position in the array represents the edge going up from the vertex at that position (the value at the root

Full text and comments »

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

47.
By antontrygubO_o, 7 years ago, In English
Background of Good Bye 2019 Hi there! The recent Good Bye 2019 was very important event for us, and thanks for all the positive feedback we got, especially from [user:Radewoosh,2020-01-01]! As a follow-up, we would like to share some background on its preparation. ### **Problems:** **A**: This one was the hardest to come up with. We wanted it to be super easy but still to include some idea, and this is like the $10$th version of the problem. **B**: Initially there was another problem at this position. However, it turned out to be too hard for B (one orange couldn’t do it during the testing), and people didn’t like it in general, so we came up with another task. **C**: Funny, but we didn’t know that it’s always possible to make array good with adding at most $1$ element before the contest. **D**: This problem was created just 3 days before the contest to make it more balanced :O. We are glad that the contest did turn out to be well-balanced. **E**: Initially we wanted this problem to be at positi...
**B**: Initially there was another problem at this position. However, it turned out to be too hard, **E**: Initially we wanted this problem to be at position C, but the coordinator told us it was too, **G**: Before there was another problem at this position, but [this](https://codeforces.me/contest

Full text and comments »

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

48.
By Vladithur, 2 years ago, In English
EPIC Institute of Technology Round Summer 2024 (Div. 1 + Div. 2) <a href="https://epic-institute.io/"><img alt="EPIC" src="https://assets.codeforces.com/images/deltix/2_logo.gif" style="float:right; height: 154px; padding-left: 35px; padding-right: 73px; padding-top: 41px; padding-bottom: 33px;"/></a> Hi, Codeforces! We are pleased to invite you to [contest:1987], which will be held on [contest_time:1987]. You will be given **8 problems**, two of which are divided into two subtasks, and you will have **3 hours** to solve them. The round will be rated for **everyone**. At least one of the problems will be interactive, so please read the [guide for interactive problems](https://codeforces.me/blog/entry/45307) if you are not familiar with it. We would like to thank: - [user:errorgorn,2024-06-27] for coordinating the round. - [user:Geothermal,2024-06-27], [user:turmax,2024-06-27], [user:noimi,2024-06-27], [user:SomethingNew,2024-06-27], [user:feecIe6418,2024-06-27], [user:Endagorion,2024-06-27], [user:glebustim,2024-06-27], [user:zelibo...
diploma and the best students will be offered to join, either as an intern or a full-timeposition, one

Full text and comments »

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

49.
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...
If a character is not in the correct position, then it must belong to, If you are at position $x$, what can you say on the state of portals, be already in the correct position., not touch elements which are already in the correct position! Fun fact: this problem appears again

Full text and comments »

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

50.
By Endagorion, 12 years ago, In English
Codeforces Round #300 Editorial (+challenges) As usual, a challenge comes with every problem. I tried not to repeat the mistakes of my previous editorials and made sure that all challenges have a solution =) (except for the _italics_ parts that are open questions, at least for me). Go ahead and discuss them in the comments! General questions about problems and clarification requests are welcomed too. **UPD**: I added codes of my solutions for all the problems. I didn't try to make them readable, but I believe most part of them should be clear. Feel free to ask questions. [problem:538A] Let me first clarify the statement (I really wish I didn't have to do that but it seems many participants had trouble with the correct understanding). You had to erase exactly one substring from the given string so that the rest part would form the word `CODEFORCES`. The (somewhat vague) wording `some substring` in the English translation may be the case many people thought that many substrings can be erased; still, it is beyond my understa...
recreate the position with all the pieces in the same places. If a field was not attacked in the initial

Full text and comments »

Tutorial of Codeforces Round 300
  • Vote: I like it
  • +312
  • Vote: I do not like it

51.
By maomao90, history, 5 years ago, In English
Tutorial on SIMD vectorisation to speed up brute force I decided to write a blog on this as I was doing a problem on our local judge and I decided to try to speed up my brute force code. However, it was quite difficult to find resources on SIMD vectorisation, so I decided to try to compile some of the resources I found to hopefully allow more people to learn <s>to scam brute force solutions</s> Thanks to ~iloveioi,2022-01-02 and ~jamessngg,2022-01-02 for proofreading. Introduction ================== SIMD stands for single instruction, multiple data. SIMD allows us to give vector instructions which will allow the code to run faster. Vector instructions are instructions that handle short (length 2-16) vectors of integers / floats / characters in a parallel way by making use of the extra bits of space to do operations simultaneously. The most common form of vectorisation is making use of pragmas such as ~~~~~ #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") ~~~~~ This form of vecto...
load the integers to the correct position and store the result after multiplication using, This function blends 2 vectors together by using the mask. If position $i$ of the mask is $0, imm8 is an 8-bit mask that represents which value is at which position. The position of the first, position $x$. Otherwise, $f(x)$ is the sum of the minimum $|k|$ value of all type 1 snakes atposition, position, and then use `_mm_and_epi32` to combine type 1 and type 2 snakes. Using `_mm_blendv_epi8

Full text and comments »

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

52.
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...
its current label to the correct position. When does it work?

Full text and comments »

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

53.
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...
get it read next. At first position of a descending array it needs to be maximal value. Similarly to, value val only to range [x, y]. When you query a position pos, let’s see if algorithm handles it, 2/ what’s current value of an element from position pos., I’ll show firstly how to do for ascending sorting. At position 1 it needs to be minimal element, What’s subtree of node 6? elements of discover from position begin[6] to end[6]. In this case, from, When you need to answer a query about position pos, you output A[1] + A[2] + ... + A[pos].

Full text and comments »

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

54.
By Radewoosh, history, 8 years ago, In English
Blogewoosh #7 Hello, codeforces! Long time no see, right? So maybe it's a good idea to try to return to my blogs slowly. This time the blog will be about a trick, which usually isn't necessary to solve a task, but can be useful to make implementation much more comfortable. Let's look at [this](https://codeforces.me/contest/932/problem/F) problem. It is about some DP on a tree in which we have to use convex hull trick to improve the complexity. The task requires merging two convex hulls with "smaller to bigger" trick. I recommend you to read the statement before reading the rest of the blog (and the [editorial](https://codeforces.me/blog/entry/57796) if you don't know how to solve it). [cut] $ $ So, how to merge two convex hulls? If we keep them in something like the set from C++, then we can just take every element from the smaller one and try to add it to the bigger one. Unfortunately, adding one element in this way requires some ifology and care. It's hard to implement it, especiall...

Full text and comments »

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

55.
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...
We will always pass through the position of the maximum element in the, Consider a position $i$ that $a_i=n$. Assume $i\ne 1$ and $i\ne n$. For a segment that passes $i, Let $j_0$ be the position of the minimum element in $[i+1,r_i]$. Obviously $j_0$ is directly

Full text and comments »

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

56.
By Geothermal, history, 6 years ago, In English
AtCoder Beginner Contest 172 English Solutions #A &mdash; Calc Just directly print the given sum. Time Complexity: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc172/submissions/14750143) --- #B &mdash; Minor Change The answer is simply the number of positions $i$ for which $S[i] \neq T[i]$. This is because we must make a move fixing each of those position, and each move can only make $S[i] = T[i]$ for one new position. Thus, we can iterate through the positions and count those where $S$ and $T$ differ, printing the total as our answer. Time Complexity: $O(|S|)$. [Click here for my submission.](https://atcoder.jp/contests/abc172/submissions/14750027) --- #C &mdash; Tsundoku We apply two pointers. Iterate over the number of books to be read from desk A in decreasing order, starting with the greatest number of those books we could read without exceeding $K$ minutes. Maintain the sum of all books to be read from desk A. Then, while we can do so without exceeding $K$ minutes, add ...
$B$ where there is no position $i$ such that $B_i = i$., because we must make a move fixing each of those position, and each move can only make $S[i] = T[i]$ for, must make a move fixing each of those position, and each move can only make $S[i] = T[i]$ for one new, one bit in position $2$, one bit in position $1$, and two bits in position $0$, but the total of, us to add two $1$s at position $b$ and forces us to do so. If we add a bit to both numbers, we add

Full text and comments »

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

57.
By antontrygubO_o, 7 years ago, In English
Are subtasks evil? Everything in this blog is only my opinion, motivated by the recent round. If you disagree with it, let's discuss in the comments! It's always hard to prepare a balanced problem set, and when the contest turns out to be unbalanced, an army of angry coders will destroy you in the comments section. But how can setters make Codeforces contests balanced? Before, authors usually had to spend more time coming up with new problems which would close a too large gap between some $2$ problems. But now we have an easier solution! Any time there is a big difficulty gap in a contest, add subtasks to it! [View](https://codeforces.me/blog/entry/67810?#comment-520212) on subtasks by [user:MikeMirzayanov,2019-11-24]: Subtasks became really widely used in Codeforces contests recently. I looked at last $30$ contests rated for Div1 users. In turns out that: Rounds $30 - 21$ had only $1$ subtasks in total, Rounds $20 - 11$ had $3$ subtasks in total, The last $10$ rounds already had $7...

Full text and comments »

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

58.
By Monogon, 4 years ago, In English
[Tutorial] Supporting Priority-Queue-like Undoing on DS _Good morning!_ In this blog, I will present an online algorithm that can perform priority-queue-like undoing on a data structure, given a few assumptions. I will also present and solve a generalization of that problem. For context, I highly recommend reading this blog that shows how to solve the easier problem of queue-like undoing. That blog gave me the inspiration for the trick I will describe here, but I will still try to write this blog so that it can be understood without it. Thank you [user:Noam527,2023-01-08] for introducing such a great trick to the competitive programming community. [[Tutorial] Supporting Queue-like Undoing on DS](https://codeforces.me/blog/entry/83467) Acknowledgment ----------------- Huge thanks go to [user:peltorator,2023-02-20] for hosting a [blog contest](https://codeforces.me/blog/entry/110840). His generous prize of $300 got many people to write blogs on new, interesting ideas, and it was one of the main reasons I wrote this blog. I'm...

Full text and comments »

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

59.
By Monogon, history, 6 years ago, In English
[Tutorial] Voronoi Diagram and Delaunay Triangulation in O(n log n) with Fortune's Algorithm What's a Voronoi Diagram? ------------------ Given a set $S$ of $n$ points in the 2D plane, the Voronoi diagram is a partition of the plane into regions. The region associated with a point $p\in S$ contains precisely the points $q$ such that $q$ is closer to $p$ than any other point in $S$. In other words, a point $q$ belongs to the region of its nearest neighbor. <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Euclidean_Voronoi_diagram.svg/1024px-Euclidean_Voronoi_diagram.svg.png" width="300px" height="auto"/> The Voronoi diagram can be represented by the planar graph of boundaries between regions. A vertex in this graph is where three or more segments meet (or a point at infinity), and an edge is a segment connecting two of these vertices. The way the regions were defined, we see that a segment contains the points equidistant to two points in $S$, so it is part of their perpendicular bisector. Similarly, a Voronoi vertex is equidistant to three or more v...
arc, and the position of the sweep-line. struct arc { mutable pt p, q; mutable int id = 0

Full text and comments »

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

60.
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...
Consider the character at position $i$ in string $s$. We define $C_i$ as, The dp states are position and number of potions drank. , Now, suppose that position $i$ is not drunk. We can assume that there are no $k$ ($k, Observation: If the position of $b$ is less than the position of $y$ in the suffix array, $x$ must

Full text and comments »

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

61.
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; ...
are fixed in position, and the REDs move around anticlockwise., not able to put a position in $t$ as bits cannot move back, or there are not enough bits in $s$ to, s into a position in t and squish the most significant bits., since it was too hard for its position.) , vector across the belt of NONREDs, and then for each RED, binary search the earliestposition where, ///find the RED at that position, if any int red = A.redHere; if(red == -1) continue

Full text and comments »

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

62.
By -Morass-, history, 9 years ago, In English
Problem Topics Good Day to you! I've been asked to make some topic-wise list of problems I've solved. Even though I couldn't involve all problems, I've tried to involve at least "few" problems at each topic I thought up (I'm sorry if I forgot about something "easy"). I've alredy made such list once anyway I've tried to include more problems now &mdash; so here it is: <spoiler summary="aho"> http://www.spoj.com/problems/ADAJOBS/ URI 2226 (5) //[NICE][NUMBERS][DP] http://www.spoj.com/problems/SUB_PROB/en/ http://codeforces.me/contest/696/problem/D 8 http://www.spoj.com/problems/AHOCUR/ 5 //Aho-Corassic + DP https://www.codechef.com/problems/LYRC (5) //Sample aho-brute-force http://codeforces.me/problemset/problem/346/B //Proposed by [user:bradyawn,2019-08-03] </spoiler> <spoiler summary="automat"> 6861 [LA] //CYK UVA 10679 //Suffix Automat http://www.spoj.com/problems/STRMATCH/ //Suffix Automat &mdash; trie might do too http://www.spoj.com/problems/NSUBST...
http://codeforces.me/contest/112/problem/D (4) //[NICE] Last-position [FACTOR]

Full text and comments »

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

63.
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 ...
some casework on the position of the central maxima, we can conclude that in the allowed interval $1, - **Condition $x$** : Let $p_1$ be the position of $x$ a non-leaf node, and $p_2$, $p_3$ be the

Full text and comments »

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

64.
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...
its final position in the reversed string? (Treat equal characters as distinguishable values, of occurrences in the string. Otherwise, can you calculate the optimal final position of each, relative position of equal characters? Which characters should be located in symmetrical positions (i.e, $a^{-1}$ (a permutation such that $(a^{-1})_{a_x} = x$, i.e. $(a^{-1})_x$ is equal to theposition, ), (4, 12), (6, 7), (9, 11)$. The character in position $5$ should go in the center of the final, - $res := res + \text{range_sum}(a_j + 1, n)$ - add $1$ in the position $a_j$ of the Fenwick tree, - $res := res + \text{range_sum}(x_j + 1, y_j - 1)$ - add $1$ in the position $y_j$ of the Fenwick

Full text and comments »

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

65.
By Al.Cash, 12 years ago, In English
Efficient and easy segment trees This is my first attempt at writing something useful, so your suggestions are welcome. Most participants of programming contests are familiar with segment trees to some degree, especially having read this articles http://codeforces.me/blog/entry/15890, http://e-maxx.ru/algo/segment_tree (Russian only). If you're not &mdash; don't go there yet. I advise to read them after this article for the sake of examples, and to compare implementations and choose the one you like more (will be kinda obvious). Segment tree with single element modifications ================== Let's start with a brief explanation of segment trees. They are used when we have an array, perform some changes and queries on continuous segments. In the first example we'll consider 2 operations: 1. modify one element in the array; 2. find the sum of elements on some segment. [cut] . ### Perfect binary tree I like to visualize a segment tree in the following way: [image link](http://i.imgur.com/GGBmcEP....
1. add a value to all elements in some interval; 2. compute an element at some position., void modify(int p, int value) { // set value at position p for (t[p += n] = value; p > 1; p

Full text and comments »

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

66.
By Endagorion, history, 6 years ago, In English
Codeforces Global Round 8: editorial Thank you for waiting! I hope you've enjoyed the problems. Let me know what you think in the comments! **UPD**: I almost forgot but here are some notes, as well as challenges for all problems. For a lot of them I don't have a solution and would be happy to hear your ideas. [tutorial:1368A] <spoiler summary="Challenge (awful)"> Find a closed formula for the answer. For simplicity assume $a \leq b$, </spoiler> [tutorial:1368B] <spoiler summary="Challenge (?)"> As mentioned above, the problem is not that easy in general case when there are a lot of repeated letters. Still, is it possible to do? Any solution faster than brute-force would be interesting, or even some ideas or observations. </spoiler> <spoiler summary="Notes"> I find it much harder to create a good easy problem than a good hard problem. This position in paricular gave me a lot of trouble, we had to scratch three or four other versions. Not to say the result is very inspiring, but the previous ones were...
problem. This position in paricular gave me a lot of trouble, we had to scratch three or four other

Full text and comments »

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

67.
By orz, history, 3 years ago, In English
C++20 is back In contests and in the custom invocation, after a pause, one can again find GNU G++20 64-bit. However, the [slowdown issue](https://codeforces.me/blog/entry/126654) because of which the language disappeared persists, there are still snippets of code that can slow down the execution on Codeforces servers by a factor of 100 or so. So what is the official position of Codeforces headquarters and of our community on that? 1. Are there general methods of constructing testcases that can exploit this GCC/Windows bug and therefore slow down solutions (like there are [anti-hash tests](https://codeforces.me/blog/entry/62393) for solutions using `unordered_set`)? Are there methods that slow down both contest mode and custom invocation mode (since [submission:249807302] is only slow in the contest mode whereas [submission:253289473] is only slow in the custom invocation)? 2. If so, should we expect such tests in future contests, will such methods be used during the test preparation in co...
So what is the official position of Codeforces headquarters and of our community on that?

Full text and comments »

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

68.
By errorgorn, 5 years ago, In English
On Div2ABs 2 years ago, [user:antontrygubO_o,2022-04-27] wrote [a blog](https://codeforces.me/blog/entry/75163) about div2ABs where he expressed his opinions that d2ABs should not be about "here is a statement, please implement what is written there". Thanks to him, the quality of d2ABs (and problem quality in general) have certainly improved. However, I still believe that there still quite large differences between how coordinators/problemsetters view d2ABs and how the intended participants view them. From the survey made by [user:kpw29,2022-04-27], we can see that most people agree that most people agree that we should **primarily** consider the target audience when proposing a task. I too think if a task is boring to div 1 contestants, we should not think of that as a reason to immediately disqualify a problem from being a d2A. ![ ](https://codeforces.me/predownloaded/70/b5/70b515da85a4dc3b362cf4eb0963dbd1fb642819.png) I think when people judge the interesting-ness of d2As, they try...
thumb to determine the correct position of a easy problem?

Full text and comments »

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

69.
By -is-this-fft-, history, 19 months ago, In English
Run-twice (aka communication) problems with Polygon and testlib.h ### Introduction _Run-twice_ problems (also called _multipass_ or _communication_ problems) are problems in which your program is executed twice. Here are some examples: - [problem:2054A] from the TON marathon. - Problems D, G and K from [Universal Cup Season 2 Stage 5](https://assets.ucup.ac/statements/statements-2-5.pdf). - All problems from [Universal Cup Season 2 Stage 16](https://assets.ucup.ac/statements/statements-2-16.pdf). - [Flash](https://boi2019.eio.ee/wp-content/uploads/2019/04/flash.en_.pdf) from BOI 2019 (this one is actually more complicated, but the premise is the same &mdash; there are multiple instances of your program which cannot share data except through the interactor. As you can see, there are many ways this format can be used, but the common themes are encoding/decoding, compression/decompression, constructing a bijection and similar ideas. The general principle is that you have to implement two functions and the second function has to somehow use t...
In the second run, you can start from the card at position $x$ and trace that cycle. In at most $n, position of the card to turn over. The interactor will reply with a single integer $y$ — the

Full text and comments »

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

70.
By ko_osaga, history, 4 years ago, In English
SMAWK algorithm as an alternative for D&C optimization Yesterday I participated in a local contest involving a problem about Monge arrays. I could've wrote some d&c optimization, but I got bored of typing it so I copypasted [user:maroonrk,2023-01-01]'s SMAWK implementation to solve it. Today, I somehow got curious about the actual algorithm, so here it goes. ## 1. Definition I assume that the reader is aware of the concept of D&C Optimization and Monge arrays. The goal of SMAWK is to compute the row optima (ex. row minima or maxima...) in a $n \times m$ **totally monotone** matrix. By *totally monotone*, it means the following: **Def: Monotone.** The matrix is monotone if the position of row optima is non-decreasing. **Def: Totally Monotone (TM).** The matrix is totally monotone if every $2 \times 2$ submatrix is monotone. Totally monotone matrices are monotone (proof easy but nontrivial), but not vice versa. The latter is a stronger condition. Note that Divide and Conquer Optimization works on a monotone matrix, therefore ...
the optimal position for row $i$. We have $opt(2k-1) \le opt(2k) \le opt(2k+1)$, so brute-force all, **Def: Monotone.** The matrix is monotone if the position of row optima is non-decreasing.

Full text and comments »

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

71.
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"...

Full text and comments »

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

72.
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 ...
block $x+1$, if the block $x$ is in position $i$ and the block $x+1$ is in position $j$., time does block $x$ disappear? It may be convenient to put a fake "static" block inposition $m+1, $ has reached position $m+1$. , , if the block $x$ is in position $i$ and the block $x+1$ is in position $j$. , In one move, you can make at most $2$ sad students happy (because you can change theposition of at

Full text and comments »

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

73.
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 $...
possible pair and ask about its current position. The expected number of queries is $O(\log N, P3. **Moving Car** — A car on an infinite line starts at unknown position $X$ and unknown

Full text and comments »

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

74.
By Temirulan, history, 2 months ago, In English
DeepInfra Intro <img alt="DeepInfra" src="/predownloaded/80/6a/806a52f0517e36b6ecaa4f88c4b5343630932ca5.jpg" style="float:right; height:145px; margin:6px; max-width:40%;" /> **Hello Codeforces!** We’re excited to welcome you to the upcoming <a href="https://codeforces.me/contest/2271">DeepInfra Round 1</a> &#x1F680; At <a href="https://deepinfra.com/"><b>DeepInfra</b></a>, we’re building high-performance AI infrastructure that makes running the world’s best AI models fast, reliable, and accessible. We operate across the entire inference stack — from GPUs all the way to the API — and we care deeply about performance, efficiency, and solving hard engineering problems. <img src="/predownloaded/61/0d/610dcb234b4c8e315f7b431d6498002f842fcefe.jpg" alt="Image" style="max-width:100%; height:auto;"> Our team had great experience with being part of Codeforces and competitive programming community &mdash; [user:PERNEKHAN,2026-09-30], [user:yessenzhar,2026-09-30], [user:Zharaskh...

Full text and comments »

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

75.
By TheScrasse, history, 2 years ago, In English
Editorial of Codeforces Round 975 (Div. 1, Div. 2) All the Polygon materials (including the official implementations of all the problems) are [here](https://drive.google.com/file/d/1zWk5N_iF3TWbzzab5IAIza78_FohSZtP/view?usp=sharing). [problem:2019A] Author: [user:TheScrasse,2024-09-27]<br> Preparation: [user:TheScrasse,2024-09-27] <spoiler summary="Hint 1"> Can you reach the score $\max(a) + \lceil n/2 \rceil$? </spoiler> <spoiler summary="Hint 2"> Can you reach the score $\max(a) + \lceil n/2 \rceil - 1$? </spoiler> <spoiler summary="Solution"> The maximum red element is $\leq \max(a)$, and the maximum number of red elements is $\lceil n/2 \rceil$. Can you reach the score $\max(a) + \lceil n/2 \rceil$? - If $n$ is even, you always can, by either choosing all the elements in even positions or all the elements in odd positions (at least one of these choices contains $\max(a)$). - If $n$ is odd, you can if and only if there is one occurrence of $\max(a)$ in an odd position. Otherwise, you can choose even position...
can if and only if there is one occurrence of $\max(a)$ in an odd position. Otherwise, you can, that position (in the previous solution) is a suffix max., - set bit in position $p$ to `0`; - find the nearest `1` to the left of position $p$.

Full text and comments »

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

76.
By Zlobober, history, 8 months ago, In English
Nebius – Early Talents Hello, Codeforces! &#128075; ###We’re Nebius. <img style="float: right; margin: 0 1em 0.5em 1em; width: 400px;" src="/predownloaded/ac/09/ac09bf11e4b164fa4f62fcb418970a71dadb577a.jpg" alt="NEBIUS color page"> You might remember our [Welcome Round](https://codeforces.me/blog/entry/113702) a few years ago, and we're back with another round! We invite you to take part in our Second round on Codeforces: [**Nebius Round 2** (Codeforces Round 1088, Div. 1 + Div. 2)](https://codeforces.me/contest/2211). Join us on [contest_time:2211] and test your skills by solving problems! In the meantime, we want to share something big. We’re launching our first [**Early Talent Program**](https://nebius.com/early-talent-program?utm_source=codeforces&utm_medium=job_board&utm_campaign=Early_Talent_Program) for students and recent grads. Quick intro. I used to coordinate Codeforces rounds back in 2014–2015, did IOI/ICPC, and was pretty active here in the 2010s. Now I’m a Direc...

Full text and comments »

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

77.
By Geothermal, history, 7 years ago, In English
AtCoder Beginner Contest 139 English Solutions #A &mdash; Tenki This is a fairly simple task--just iterate over all positions in the strings and count the ones where S[i] = T[i]. Runtime: $O(|S|)$. [Click here for my submission.](https://atcoder.jp/contests/abc139/submissions/7247680) --- #B &mdash; Power Socket Note that we already have one socket, so we need to fill $B-1$ more sockets. Additionally, each new outlet we add will take up one socket and add $A$ sockets, resulting in a net addition of $A-1$ sockets. We thus need to create at least $B-1$ sockets where each outlet gives us $A-1$ sockets, making our answer $\lceil \frac{B-1}{A-1} \rceil$. Since most programming languages use floor division, we can also express this as $\lfloor \frac{A+B-3}{A-1} \rfloor$. Runtime: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc139/submissions/7249379) --- #C &mdash; Lower We essentially use two pointers. Maintain the starting position at zero. Then, while the next position isn't hi...
from starting positions that are higher than the previous position. The reason this gives us the best, We essentially use two pointers. Maintain the starting position at zero. Then, while the next

Full text and comments »

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

78.
By Um_nik, history, 11 years ago, translation, In English
Codeforces Round #315 Editorial [problem:569A] Suppose we have downloaded $S$ seconds of the song and press the 'play' button. Let's find how many seconds will be downloaded when we will be forced to play the song once more. $\frac{x}{q} = \frac{x-S}{q-1}$. Hence $x=qS$. Solution: let's multiply $S$ by $q$ while $S<T$. The answer is the amount of operations. Complexity &mdash; $O(\log T)$ [problem:569B] Let's look at the problem from another side: how many numbers can we leave unchanged to get permutation? It is obvious: these numbers must be from $1$ to $n$ and they are must be pairwise distinct. This condition is necessary and sufficient. This problem can be solved with greedy algorithm. If me meet the number we have never met before and this number is between $1$ and $n$, we will leave this number unchanged. To implement this we can use array where we will mark used numbers. After that we will look over the array again and allocate numbers that weren't used. Complexity &mdash; $O(n)$. ...
Let suppose that we stand at position $r$ (and $prevIndex[r] = -1$). Now we want to find such, [r])) $. $countSkip$ we can calculate while iterates position $l$, $countBetween(x, y) = max(0, position (this is simply calculating while processing array $c$) and position ($prevIndex[pos, position there is two mutually exclusive options (vowel or consonant) and the rules are consequences

Full text and comments »

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

79.
By TheScrasse, 14 months ago, In English
Editorial of Codeforces Round 1053 (Div. 1, Div. 2) [problem:2151A] Author: [user:TheScrasse,2025-09-21]<br> Preparation: [user:TheScrasse,2025-09-21] <spoiler summary="Hint 1"> There are two types of subarrays. </spoiler> <spoiler summary="Hint 2"> If there exists $a_i \geq a_{i+1}$, how many times can the subarray appear? </spoiler> <spoiler summary="Solution"> - If there exists an $i$ such that $a_i \geq a_{i+1}$, we have $a_i = k$ for some $k$, $a_{i+1} = 1$. The subarray $[k, 1]$ appears only once on the blackboard (when James writes $1, \ldots, k$ and then $1, \ldots, k+1$). Since $a_1, a_2, \ldots, a_m$ contains $[k, 1]$, it must appear at most once as well, but the statement guarantees that it appears at least once, so the answer is $1$. - Otherwise, the array $a_1, a_2, \ldots, a_m$ can be rewritten as $l, l+1, \ldots, r$, and it appears when James writes $1, \ldots, r$, then when James writes $1, \ldots, r+1$, ..., then when James writes $1, \ldots, n$ (so $n-r+1$ times in total). Complexity: $O(n)$ </...
Find a characterization for when a position array $p$ is possible. It, So the position visited by person $i$ after $i-2$ commands is the same position visited by person

Full text and comments »

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

80.
By null_awe, 2 years ago, In English
Codeforces Global Round 26 Editorial Thank you for participating! We put a lot of effort into this contest. Special thanks to [user:TheScrasse,2024-06-08] for contributing to these problems. <spoiler summary="Rating Predictions"> | Person | A | B | C1 | C2 | D | E | F | G | H | |--------------------------------------------|------|------|------|------|------|------|------|------|------| | [user:null_awe,2024-06-08] | 800 | 1000 | 1200 | 1700 | 2200 | 2400 | 2500 | 2900 | 3400 | | [user:buffering,2024-06-08] | 800 | 1000 | 1300 | 1800 | 2300 | 2400 | 2600 | 3100 | 3500 | | [user:redpanda,2024-06-08] | 800 | 1100 | 1200 | 1800 | | | | | | | [user:thescrasse,2024-06-08] | 800 | 1000 | 1200 | 1600 | 2200 | 2500 | 2500 | 3100 | 3400 | | [user:bronze_coder,2024-06-08] | 800 | 1000 | 1600 | 1800 | 2400 | | | 2700 | 3500 | | [user:awesomeguy856,20...
, then move the divider by $1$ position in any direction., We only need to pick it once. How can we calculate the final value for every position we can pick

Full text and comments »

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

81.
By AndreyPavlov, history, 4 years ago, translation, In English
Codeforces Round #846 (Div. 2) — Tutorial [problem:1780A] Idea: [user:AndreyPavlov,2023-01-24] <br> Preparation: [user:AndreyPavlov,2023-01-24] <br> Editorialist: [user:AndreyPavlov,2023-01-24] <spoiler summary="Tutorial"> Note that there are two variants of which numbers to take to make their amount odd: $3$ odd number; $2$ even and $1$ odd. Let’s save all indices of even and odd numbers into two arrays, and check both cases. </spoiler> <spoiler summary="Implementation (Python)"> ~~~~~ def solve(): n = int(input()) a = list(map(int, input().split())) odd, even = [], [] for i in range(n): if a[i] % 2 == 0: even.append(i + 1) else: odd.append(i + 1) if len(odd) >= 1 and len(even) >= 2: print("YES") print(odd[0], even[0], even[1]) elif len(odd) >= 3: print("YES") print(odd[0], odd[1], odd[2]) else: print("NO") t = int(input()) for test in range(t): solve() ~~~~~ </spoiler...
. One in position $i$ means that the substrings length $k$ starting at $suf_i$ and $suf_{i + 1}$ are, To move from position $i$ to position $i+1$, update the values of $cnt$ and $s$ by adding the

Full text and comments »

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

82.
By plagues, 3 months ago, In English
The most outrageous cheating in the history of Huawei Challenge ![ ](/predownloaded/e4/f0/e4f0838fd7d6c43c6a92c2655748800519c78bd3.jpg) I am writing this because I believe that prohibited collaboration occurred during this Challenge and affected the prize positions. To state my personal conclusion plainly: I believe this is cheating, not merely a collection of innocent coincidences. The final positions relevant to the accounts discussed in this post were: | Rank | Handle | Final score | Result of my public-data review | |---:|---|---:|---| | 2 | [user:IceKylin,2026-08-28] | 16808.628 | Historical team with [user:candy0014,2026-08-28] named “IceKylin 0339 team”; all-time runtime/score leads with [user:candy0014,2026-08-28] and [user:Retired_Zhisheng,2026-08-28] | | 3 | [user:mahiro_zcy,2026-08-28] | 16757.390 | Repeated all-time runtime/score correlation with [user:mojo__hugo,2026-08-28]; repeated timing correlation with [user:Zinc-acetate,2026-08-28]; weak close event with [user:Mango2011,2026-08-28] | | 4 | [user:Zinc-acetate,2026-08-...
## My position

Full text and comments »

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

83.
By RP-1, history, 23 months ago, In English
Changing your rank to lower one is mainstream above 1579 <spoiler summary="Disclaimer"> All data presented is actual as of 2024/12/28, that is, before Good Bye 2024. Also, since Ratings page only shows active users, I decided not to count any others. I apologize to anyone I have not included. </spoiler> Looking at the top-10 users and Recent Actions bar right now, two things become apparent: 1. Since LGMs cannot change their rank to a higher one, more people in, say, top-100 have changed their rank to a lower one than to a higher one. 2. Codeforces-wide, more people have changed their rank to a higher one than a lower one. So there has to be an exact cut-off point, above which the same number of people have changed their rank to either side. I decided to do some scraping to find out exactly where it is. Lo and behold: <img src="https://github.com/maslinnik/cf-magic/blob/master/images/by_position.png?raw=true" alt="Rank changes (leaderboard position)"> Of the top 15k users, about tenth changed their rank to a higher ...
think that the orange curve becomes linear over time? I don't know. I'm certainly in noposition to try, ="Rank changes (leaderboard position)">

Full text and comments »

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

84.
By SanguineChameleon, 19 months ago, In English
Neowise Labs Contest 1 (Codeforces Round 1018, Div. 1 + Div. 2) Editorial [Sorry about problem H.](https://codeforces.me/blog/entry/142069) Thank you for understanding, and we hope you enjoyed the rest of the problems :D --- <h3>[problem:2096A]</h3> Idea: [user:SanguineChameleon,2025-04-20] <br> <spoiler summary="Step 1"> Create your own test cases and solve them! What can you observe? </spoiler> <spoiler summary="Step 2"> What is the length of the $n$-th stick? <spoiler summary="Answer"> - If $s_{n - 1} = \texttt{<}$, then $a_n = 1$, because the $n$-th stick must be shorter than all the other sticks. - If $s_{n - 1} = \texttt{>}$, then $a_n = n$, because the $n$-th stick must be longer than all the other sticks. </spoiler> </spoiler> <spoiler summary="Step 3"> Can we do something similar for the remaining sticks? <spoiler summary="Answer"> Yes! Remove the $n$-th stick, and then solve for the remaining $n - 1$ sticks. We can make similar observations about the $(n - 1)$-th stick. Then, remove the $(n - 1)$-th st...
Let $p$ be the ($0$-indexed) position of the least significant bit of, Suppose the treasure is buried at position $(s, t)$., Suppose the matrix does not satisfy the Horizontal Condition, so there is a position $(i, j)$ such, The intersection of these two lines is the position of the treasure.

Full text and comments »

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

85.
By Endagorion, 12 years ago, translation, In English
Codeforces Round #283: editorial (with bonuses!) Each problem comes with a challenge &mdash; a bonus task somehow related to the problem; you may tackle at the challenges for fun and practice, also feel free to discuss them at the comments. =) [problem:496A] For every option of removing an element we run through the remaining elements and find the maximal difference between adjacent ones; print the smallest found answer. The solution has complexity $O(n^2)$. It can be noticed that after removing an element the difficulty either stays the same or becomes equal to the difference between the neighbours of the removed element (whatever is larger); thus, the difficulty for every option of removing an element can be found in $O(1)$, for the total complexity of $O(n)$. Any of these solutions (or even less efficient ones) could pass the tests. **Challenge**: suppose we now have to remove exactly $k$ arbitrary elements (but the first and the last elements have to stay in their places). How small the maximal difference between adjacen...
next set as follows: find $t$-th $1$ and $t$-th $2$ after position $k$. If $t$-th $1$ occurs earlier

Full text and comments »

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

86.
By PrinceOfPersia, 12 years ago, In English
Codeforces Round #299 Editorial ### [problem:535A] First of all check if $n$ is one of the values $0, 10, 11, …, 19$. Then, let’s have array $x[]$ = {"", "", "twenty", "thirty", …, "ninety"} and $y[]$ = {"", "one", …, "nine"}. ![ ](http://espresso.codeforces.com/d5f38500e79e3e89be0519dc22736124c000bada.png) Let $a = \frac{n}{10}$ and $b = n\ modulo\ 10$. If $n$ is not one of the values above, then if $a=0$, print $y[b]$, else if $b=0$ print $x[a]$ otherwise print $x[a]$-$y[b]$. Time complexity: $O(1)$ [Code](http://ideone.com/mytb2L) by [user:SoroushE,2015-04-02] [Another Code](http://ideone.com/CqgNe5) by [user:PrinceOfPersia,2015-04-05] [Another Code](http://ideone.com/dqiMNL) by [user:Haghani,2015-04-08] [Python Code](http://ideone.com/6tZmNF) by [user:Zlobober,2015-04-04] ### [problem:535B] Sol1: Consider $n$ has $x$ digits, $f(i) = $ decimal representation of binary string $i$, $m$ is a binary string of size $x$ and its $i-th$ digit is 0 if and only if the $i-th$ digit of $...
uniquely). If there is no parados in covered positions (a position should have more than one value), then

Full text and comments »

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

87.
By awoo, history, 6 years ago, translation, In English
Educational Codeforces Round 91 Editorial [problem:1380A] Idea: [user:BledDest,2020-07-12] <spoiler summary="Tutorial"> [tutorial:1380A] </spoiler> <spoiler summary="Solution (Ne0n25)"> ~~~~~ #include <bits/stdc++.h> using namespace std; const int N = 1000; int n; int a[N]; void solve() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i < n - 1; ++i) { if (a[i] > a[i - 1] && a[i] > a[i + 1]) { cout << "YES" << endl; cout << i << ' ' << i + 1 << ' ' << i + 2 << endl; return; } } cout << "NO" << endl; } int main() { int T; cin >> T; while (T--) solve(); } ~~~~~ </spoiler> [problem:1380B] Idea: [user:adedalic,2020-07-12] <spoiler summary="Tutorial"> [tutorial:1380B] </spoiler> <spoiler summary="Solution (adedalic)"> ~~~~~ fun main() { val winBy = mapOf('R' to 'P', 'S' to 'R', 'P' to 'S') repeat(readLine()!!.toInt()) { val s = readLine()!! val maxCnt = s.groupingBy { it }.eachCount().maxBy ...

Full text and comments »

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

88.
By employed, 2 months ago, In English
DeepInfra Round 1 (Codeforces Round 1126, Div. 1 + Div. 2) Hello, Codeforces! We are excited to invite you to [contest:2271], which will take place on [contest_time:2271]! **Note the unusual start time of the round**. You will have **3 hours** to solve **8 problems**, one of which is divided into subtasks. The problems were prepared by [user:employed,2026-10-03] and reviewed carefully by [user:nifeshe,2026-10-03]. We have put a lot of care into creating and testing this problemset, and we hope you will enjoy solving the problems as much as we enjoyed preparing them! A huge thank you to everyone who helped bring this round to life: - [user:nifeshe,2026-10-03] for coordinating the round and being funny, cool, and smart! - [user:dominater069,2026-10-03] for the early review of the problems. - [user:Evenimage,2026-10-03], [user:akslolcoding,2026-10-03], [user:apracadabra,2026-10-03], [user:Euclid73,2026-10-03], [user:linearspace,2026-10-03], [user:Mohammad_Hacker,2026-10-03], [user:naneosmic,2026-10-03], [user:nik_exists,2026-10-0...

Full text and comments »

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

89.
By tourist, 16 years ago, translation, In English
Codeforces Beta Round #17 Tutorial <a href="http://codeforces.me/blog/entry/447">Contest discussion</a><br><b><br>Problem A. Noldbach problem<br><br></b>To solve this problem you were to find prime numbers in range $[2..N]$. The constraints were pretty small, so you could do that in any way - using the Sieve of Eratosthenes or simply looping over all possible divisors of a number.<br>Take every pair of neighboring prime numbers and check if their sum increased by $1$ is a prime number too. Count the number of these pairs, compare it to $K$ and output the result.<br><br><b>Problem B. Hierarchy</b><br>[cut]<br>Note that if employee, except one, has exactly one supervisor, then our hierarchy will be tree-like for sure.<br>For each employee consider all applications in which he appears as a subordinate. If for more than one employee there are no such applications at all, it's obvious that $-1$ is the answer. In other case, for each employee find such an application with minimal cost and add these costs to get the answer.<br...
short, this algorithm find the maximal length of a subpalindrome with its center either atposition $i, position $i$ of $A$ in order to put letter $a$ at positions $j..k$ of $B$ (again, using problem

Full text and comments »

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

90.
By awoo, history, 4 years ago, translation, In English
Educational Codeforces Round 145 Editorial [problem:1809A] Idea: [user:BledDest,2023-03-24] <spoiler summary="Tutorial"> [tutorial:1809A] </spoiler> <spoiler summary="Solution (Neon)"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tc; cin >> tc; while (tc--) { string s; cin >> s; vector<int> cnt(10); for (auto c : s) ++cnt[c - '0']; int mx = *max_element(cnt.begin(), cnt.end()); if (mx == 4) cout << -1; else if (mx == 3) cout << 6; else cout << 4; cout << '\n'; } } ~~~~~ </spoiler> [problem:1809B] Idea: [user:BledDest,2023-03-24] <spoiler summary="Tutorial"> [tutorial:1809B] </spoiler> <spoiler summary="Solution 1 (adedalic)"> ~~~~~ fun main() { repeat(readln().toInt()) { val n = readln().toLong() var l = (-1).toLong() var r = 1e9.toLong() while (r - l > 1) { val mid = (l + r) / 2 if (mid * mid >=...
++) { // first choice: put a[i] on the first position // then we put all which conflict, // second choice: put a[i] on any other position dp[i + 1] = add(dp[i + 1], mul(dp[i], i)); }

Full text and comments »

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

91.
By cry, 4 years ago, In English
Codeforces Round 887 (Div 1, Div 2) Tutorial We hope you enjoyed these problems :) This contest has been in the works for almost a year. <spoiler summary = "About the Authors"> This round was mostly made possible by problemsetters from the [CerealCodes](https://www.cerealcodes.org/) initiative! CerealCodes is an organization based in the United States dedicated to running high quality competitive programming contests. You can check out our previous contest [here](https://codeforces.me/gym/103886). </spoiler> **UPD: D1D Editorial have been updated** **UPD 2: D1D Editorial now has images by [user:EmeraldBlock,2023-08-01]. As an apology gift for being so slow, the image generator is programmatic and available [here](https://artofproblemsolving.com/texer/codeforces).** #### [problem:1853A] Problem Credits: [user:buffering,2023-06-02] Analysis: [user:buffering,2023-06-02] <spoiler summary="Hint 1"> To make $a$ not sorted, we just need to pick one index $i$ so $a_i > a_{i + 1}$. How do we do this? </spoiler...
If $x$ is between $a_i$ and $a_{i+1}$, it will move to a new position, $ insertions, we will check the position that $1$ will end up at., . Take a look at each number $x$ before some day. If it isn't deleted on that day, what newposition, //position, value void insert(int a, ll b){ if(!rt){ rt = newnode(a, b

Full text and comments »

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

92.
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...
used, in order to quickly say if a new position is available. An example of cells in one diagonal are

Full text and comments »

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

93.
By brunomont, 6 years ago, In English
[Tutorial] Range minimum query in O(1) with linear time construction <spoiler summary="TL; DR"> Build a sparse table over blocks of size $b = 30 \geq \log{n}$. Now we only need to answer queries of size smaller than $b$. For that, simulate a minqueue of size $b$ over the array, and store a mask of the elements that are currently active in the minqueue. Let $\text{mask[r]}$ be the minqueue mask when the simulation is at position $\text{r}$. Now we can see that, if $r-l+1 \leq b$, then `query(l, r) = r - most_significant_set_bit(mask[r] & ((1<<(r-l+1))-1))`. ~~~~~ template<typename T> struct rmq { vector<T> v; int n; static const int b = 30; vector<int> mask, t; int op(int x, int y) { return v[x] < v[y] ? x : y; } int msb(int x) { return __builtin_clz(1)-__builtin_clz(x); } int small(int r, int sz = b) { return r-msb(mask[r]&((1<<sz)-1)); } rmq(const vector<T>& v_) : v(v_), n(v.size()), mask(n), t(n) { for (int i = 0, at = 0; i < n; mask[i++] = at |= 1) { at = (at<<1)&((1<<b)-1); while (at and op(i, i-msb(at&-at)) == i) at ...
think of the position $\text{5}$ as "important". Position $\text{4}$, though, is not important, Let's consider queries ending at the same position $r$. Take the following array $A$ and $r = 6$., position $r$, lets change it to represent position $r+1$. Obviously, a position that was not important

Full text and comments »

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

94.
By Vladithur, history, 4 years ago, In English
Codeforces Round #842 (Div. 2) Editorial Hope you liked the problems! <spoiler summary="(from thanhchauns2) Before the round starts"> This is my second contest on Codeforces, inspiring coordination has been done for the last several months, cannot wait until the third round is released! <spoiler summary="Testers' predictions"> <table> <tr style ="background-color:#D3D3D3"> <th>Tester</th> <th>A</th> <th>B</th> <th>C</th> <th>D</th> <th>E</th> <th>F</th> </tr> <tr> <td>[user:xiaoziya,2022-12-13]</td> <td>900</td> <td>1000</td> <td>1400</td> <td>1800</td> <td>2100</td> <td>3000</td> </tr> <tr> <td>[user:feecle6418,2022-12-13]</td> <td>900</td> <td>1200</td> <td>1400</td> <td>1700</td> <td>2200</td> <td>2900</td> </tr> <tr> <td>[user:cadmiumky,2022-12-13]</td> <td>800</td> <td>1100</td> <td>1550</td> <td>1900</td> <td>2200</td> <td>-</td> </tr> <tr> <t...
If the smallest $n$ elements are all in position from $1$ to $2n, - For each way to choose these positions, there are $n!$ ways to choose the position for the, /// Storing position of each a[i] vector > b(n + 1); for (int i = 1; i <= n, If the largest $n$ elements are all in position from $n + 1$ to $3n$, we do the same calculation., ```cpp /// Storing position of each a[i] vector > b(n + 1); for (int i

Full text and comments »

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

95.
By reirugan, 17 months ago, In English
Codeforces Round 1034 (Div. 3) Editorial I hope you all enjoyed the contest! <spoiler summary="Rating Predictions"> | Predictor | A | B | C | D | E | F | G | |------------------------------------|--------|--------|--------|--------|--------|--------|--------| | [user:AksLolCoding,2025-07-01] | 800 | 900 | 1000 | 1500 | 1500 | 1800 | 1700 | | [user:__baozii__,2025-07-01] | 800 | 800 | 1200 | 1500 | 1500 | 1600 | 1900 | | [user:DivinePunishment,2025-07-01] | 800 | 900 | 1100 | 1400 | 1500 | 1600 | 1900 | | [user:Edeeva,2025-07-01] | 800 | 800 | 1000 | 1200 | 1600 | 1800 | 2200 | | [user:efishel,2025-07-01] | 800 | 800 | 1000 | 1200 | 1400 | 1500 | 1900 | | [user:-firefly-,2025-07-01] | 800 | 800 | 900 | 1400 | 1500 | 1700 | 2000 | | [user:hashman,2025-07-01] | 800 | 900 | 1100 | 1600 | 1500 | 1800 | ...
any arbitrary existing one in $s$, say, the one in the third position. Now, he would like to choose a

Full text and comments »

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

96.
By Geothermal, history, 7 years ago, In English
AtCoder Beginner Contest 136 English Solutions #A &mdash; Transfer First, we compute the resulting amount of water in Cup 1. Observe that this is equal to $min(A, B+C)$. Let this value be $D$. Then, the amount transferred from Cup 2 to Cup 1 is simply $D - A$, so the amount remaining in Cup 2 is $C - D + A$. Time complexity: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc136/submissions/6682058) --- #B &mdash; Uneven Numbers There are several efficient ways to approach this problem. One is to simply to count the one-, three-, and five-digit numbers less than or equal to $N$. However, because of the small maximum on $N$, a more naive approach works. Simply iterate over every value from $1$ to $N$, count its digits, and add one to the answer if the count is odd. (We can count a number's digits by repeatedly adding one to the count and dividing the number by ten until it reaches zero.) Time complexity: $O(N \log N)$. Note that $O(\log N)$ is possible with the more efficient approach. ...
that one of these two characters must be in an odd position (based on its position in the original

Full text and comments »

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

97.
By MikeMirzayanov, 11 years ago, translation, In English
The Second Revolution of Colors and Titles Over the last several months the Codeforces team has been looking anxiously at the inflation in the rating caused by both an influx of new users and the imperfect calculating formulas. In the end it lead to noticeable shifts in colors and titles. For example, getting red in 2015 became much easier than in 2013. We conducted a [survey about the way to introduce the color bounds](/blog/entry/20629). We are happy to announce the updated colors and titles! A summary of the main changes goes like that: * a new color: greenish-blue color or cyan &mdash; just like the name implies, this color takes its place between green and blue, now the participants of the second division will be better differentiated; * all the colors shift upwards along the rating scale &mdash; see the table below. Now reaching the top positions will be harder; * the legendary grandmaster &mdash; the new title and color for those who reached the sky high rating 2900. The cold colors (gray, green, cyan an...

Full text and comments »

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

98.
By ZhouShang2003, 2 years ago, In English
Pinely Round 4 (Div. 1 + Div. 2) Editorial ## [1991A &mdash; Maximize the Last Element](https://codeforces.me/contest/1991/problem/A) <spoiler summary="Hint"> Consider the parity of the position. </spoiler> <spoiler summary="Solution"> The answer is the maximum value of the elements at odd indices. **Proof** <ol> <li>Any element at an odd index can be preserved until the end.<br><br> Since each element at an odd index has an even number of elements on both sides, pairs of adjacent elements can be removed from left to right until only the element at the odd index remains. For example, if you want to keep the element at the $i$-th position, you can remove the elements at positions $1$ and $2$, $3$ and $4$, and so on, until the elements at positions $i-2$ and $i-1$ are removed. Then, continue removing elements at positions $i+1$ and $i+2$, and so on, until the elements at positions $n-1$ and $n$ are removed. Therefore, any element at an odd index can be preserved through this method.<br><br> </li> <li>No ...
Consider the parity of the position. , be split, or they must split out at least one winning position. Winning positions can be split into, call $x$ a winning position; otherwise, it is a losing position. We first determine whether an odd, example, if you want to keep the element at the $i$-th position, you can remove the elements at, $ positions. In this case, if someone splits a winning position into a losing position, the number of, A number is called a good position if it can be split into two winning positions; otherwise, it is

Full text and comments »

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

99.
By __baozii__, history, 5 months ago, In English
Spectral::Cup 2026 Round 3 (Codeforces Round 1110, Div. 1 + Div. 2) Hello Codeforces! I am glad to invite you to participate in [contest:2245], which will start on [contest_time:2245]. You will be given **2 hours and 30 minutes** to solve **8** problems, where **one problem** will be split into subtasks. Also, there is **at least one** interactive problem, so you are recommended to read the [guide](https://codeforces.me/blog/entry/45307) to interactive problems if you have not encountered them before. Note that **hacks will be disabled** for problems A to D. All problems are authored and prepared by myself. Note the [rule restricting the use of AI](https://codeforces.me/blog/entry/133941). If you are caught breaking this rule, you will be thrown into [user:SSerxhs,2026-07-09]'s basement. For your own well-being, I suggest adhering to the rules. I would like to thank the following people for helping make this round possible! - [user:SSerxhs,2026-07-09] for his/her satisfactory coordination. - [user:Alexdat2000,2026-07-12] for trans...
The final round is also your last chance to improve your position in the overall standings. Your

Full text and comments »

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

100.
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...
Let $y$ denote the final position of all of the slimes. Then it is, chose the earliest match, say between $t_i$ and $t_{i + 1}$ (we matched with a laterposition for $t_{i

Full text and comments »

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

101.
By bicsi, history, 4 weeks ago, In English
Optimal Incremental MST in 20 lines of code Hello Codeforces! Some of you might know `BottleneckTree.h` from [my KACTL fork](https://github.com/bicsi/kactl/blob/master/content/graph/BottleneckTree.h) (although it's a little obscure for an ICPC notebook; oh well). [user:freak93,2026-11-05] and I wrote it in 2021. The header says the complexity is "probably $O(\log n)$ amortized". It all started from a 2020 solution by [user:RestingRajarshi,2026-11-05] (more on that at the end). After about 6 years of on-and-off thinking about it, and with the help of Claude, we finally have an answer: it's not :). There are inputs where it takes $\Omega(\sqrt n)$ per operation. The good news is that a small change in the main loop fixes it, and this time we have a proof. We wrote a paper about it: [Incremental Minimum Spanning Trees on a Napkin](https://arxiv.org/abs/2611.05713). I think the structure is super elegant and short enough to be useful in contests, so I'm writing a blog about it. Prerequisites: none, really. It helps to know ...

Full text and comments »

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

102.
By Nanako, 4 years ago, In English
Good Bye 2022 -- Editorial ## [problem:1770A] Idea by [user:m_99,2022-12-30] <spoiler summary="Hint 1"> Exactly $n$ items out of of $a_1,\ldots,a_n,b_1,\ldots,b_m$ will remain on the whiteboard at the end. </spoiler> <spoiler summary="Hint 2"> $b_m$ will always remain on the board at the end. </spoiler> <spoiler summary="Hint 3"> Consider the case where $n=2$ and $m=2$. As we mentioned in hint 2, $b_2$ will always be written, but what about $b_1$? </spoiler> </details> <spoiler summary="Solution"> This problem can be solved naturally with a greedy algorithm &mdash; for $i = 1, 2, \dots, m$, we use $b_i$ to replace the minimal value among the current $a_1, a_2, \dots, a_n$. The time complexity is $O(nm)$ for each test case. Alternatively, we can first add $b_m$ to our final sum. For the remaining $(n+m-1)$ integers, we can freely pick $(n - 1)$ out of them and add it to our final sum. This is because if we want a certain $a_i$ to remain on the board at the end, we simply do not touch i...
Considering the above idea, we can find that only the `)` before the farthest specialposition may, We define a position as a *special position* if and only if the number corresponding to this

Full text and comments »

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

103.
By AlexLuchianov, 5 years ago, In English
[Tutorial]Using Segment Trees to solve Dynamic Programming problems Both segment trees and dynamic programming are common topics in competitive programming. Sometimes, they even appear together. In this blog, we will mostly use segment trees as a black-box. As such, it is not necessary (though it is highly recommended) to know segment trees to understand this blog. Let's begin. ###Longest Increasing Subsequence(LIS) _"You are given an array $v$ containing $N$ integers. Your task is to determine the longest increasing subsequence in the array, i.e., the longest subsequence where every element is larger than the previous one._ _A subsequence is a sequence that can be derived from the array by deleting some elements without changing the order of the remaining elements."_ This problem is most often solved using binary search. There are countless tutorials about this method, so I will not discuss it in detail. However, there exists a more general way to solve it using segment trees. Since we only care about the order of the elements and not a...
- We decide to not select the $i$-th position: $dp(i, i) = \max_{j < i} dp(i - 1, j) + f(i, i, - We decide to not select the $i$-th position: $dp(i, i) = \max_{j < i} dp(i - 1, j) - p_i $., - We decide to select the $i$-th position: $dp(i, j) = dp(i - 1, j) $., - We decide to select the $i$-th position: $dp(i, j) = dp(i - 1, j) + f(i, j)$., Let's define LR-diagonals as diagonals that go from an upper-left position towards a lower-right, position its _profit_ if we paint over it. We define the _profit_ of a position as the number of

Full text and comments »

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

104.
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...
(a[i] - b[i]))$. This completes the dp. We can reconstruct the solution by storing theposition

Full text and comments »

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

105.
By awoo, history, 5 years ago, translation, In English
Educational Codeforces Round 123 [Rated for Div. 2] Hello Codeforces! On [contest_time:1644] [contest:1644] will start. Series of Educational Rounds continue being held as [Harbour.Space University](https://harbour.space/) initiative! You can read the details about the cooperation between [Harbour.Space University](https://harbour.space/) and Codeforces in the <a href="http://codeforces.me/blog/entry/51208">blog post</a>. This round will be **rated for the participants with rating lower than 2100**. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally. You will be given **6 or 7 problems** and **2 hours** to solve them. The problems were invented and prepared by Adilbek [user:adedalic,2022-02-21] Dalabaev, Vladimir [user:vovuh,2022-02-21] Petrov, Ivan [user:BledDest,2022-02-21] Androsov, Mak...

Full text and comments »

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

106.
By cry, 2 years ago, In English
Codeforces Round 979 Editorial Below is a timeline of the changes made to the round from start to finish. I hope this can depict what setting a contest is actually like for aspiring problemsetters. Please give me feedback about this in the comments. What else about the round would you like to know? Was this helpful? <spoiler summary="Round Timeline"> To denote problems, I will use quotes to denote the number of problems proposed for that postion so far (e.g. A' represents the first A proposed for the round, A'' represents second A proposed, etc). If the problem is in the final set, then it will be **bolded**. For dates, I will use the american standard notation (mm/dd). Also, I will not go in detail about why problems were rejected/unused because they might appear in the future. 8/11: [contest:1998] has just concluded and [user:sum,2024-10-18] has shipped himself off to college and won't have time due to <s>attending frat parties</s> his studies. I invite [user:vgoofficial,2024-10-18] to problemset with m...
position $i$ to position $j$ (WLOG, assume $i < j$) if there is no such $k$ such that $i \leq k < j

Full text and comments »

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

107.
By Misuki, 2 years ago, In English
Editorial of Codeforces Round 967 (Div. 2) Except hints/solutions, I try to add a "general idea" section discuss about some general strategy and standard ideas used to solve the problem, hope you would like it :) [problem:2001A] idea & solution: [user:Misuki,2024-08-20] <spoiler summary="Hint 1"> What's the most obvious lower bound of the answer? </spoiler> <spoiler summary="Hint 2"> Is the lower bound achievable? </spoiler> <spoiler summary="General idea"> One standard way to solve optimization problem is to make observation on lower(upper) bound of the answer and prove such bound is achievable, it's useful in lot of problems. </spoiler> <spoiler summary="Solution"> Let $x$ be one of the most frequent elements in $a$, then the answer must be at least $(n - \text{frequency of } x)$, and this lower bound is always achievable by keep erasing a non-$x$ element from $a$, and we can prove it's always possible to do so. proof: If all elements of $a$ are $x$, we are done. Otherwise, let $y$ denote ...
Does the position of first leaf being popped really matters? , Fix the position of first and second leaf being popped, what's the, Fix the position of first leaf being popped, do we really need to

Full text and comments »

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

108.
By nik_exists, 3 months ago, In English
Codeforces Round 1119 (Div. 3) Editorial Thank y'all so much for participating! [problem:2259A] <spoiler summary="Solution"> [tutorial:2259A] </spoiler> <spoiler summary="Code"> ```cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int ans = 0; for (int i = 0; i < n / k; i++) { bool has_non_nhoj_farm = false; for (int j = i * k; j < (i + 1) * k; j++) { if (s[j] == '0') has_non_nhoj_farm = true; } ans += !has_non_nhoj_farm; } cout << ans << "\n"; } } ``` </spoiler> <spoiler summary="Difficulty"> Too hard A bit on the harder side Good difficulty Easy Too easy </spoiler> <spoiler summary="Quality"> Amazing [likes:A2, ...
separate them into 3 categories: the position is forced to be a treasure, the position has no undestroyed

Full text and comments »

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

109.
By employed, history, 2 months ago, In English
Editorial of DeepInfra Round 1 (Codeforces Round 1126, Div. 1 + Div. 2) thanks to [user:nifeshe,2026-10-10] for making my life easier with templates [problem:2271A] <spoiler summary = "Hints"> <spoiler summary = "Hint 1"> After performing $z$ operations, the robot's $x$-coordinate is exactly $z$. </spoiler> <spoiler summary = "Hint 2"> After completing any operation, the $x$-coordinate and $y$-coordinate always have the same parity. </spoiler> <spoiler summary = "Hint 3"> Try to find a construction to reach any point $(x,y)$ where $y\le x$ and $x$ and $y$ have the same parity. </spoiler> </spoiler> <spoiler summary = "Solution"> Notice that after performing $z$ operations, the robot's $x$-coordinate will be exactly $z$, while its $y$-coordinate cannot exceed $z$. We will first consider the case $b\le a$, then handle the special case $b=a+1$. Notice that the robot can reach any point $(x,y)$ where $0\le y\le x$ and $x$ and $y$ have the same parity in exactly $x$ operations. To do so, we can first move up until reaching $y$...
After finding a position $pos$ with maximum $f(pos)$, try using binary, these two positions, there must be a position where $f(s)=k$., First, notice that when we increase $s$ by $1$, we remove the position $s$ and add theposition $s, Let $mx$ be the maximum value we find, and let $pos$ be a position where $f(pos)=mx$., To see why, consider any starting position $s$:, We can find such a position using binary search!, Why? Any new good pair that spans this position remains good if we decrease its value even further.

Full text and comments »

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

110.
By Geothermal, history, 7 years ago, In English
AtCoder Beginner Contest 135 English Solutions #A &mdash; Harmony Without loss of generality, let $A < B$. Then, we have three cases: - $K$ is less than $A$. This gives $A - K = B - K$, which gives $A = B$, which is false. - $K$ is greater than $B$. This gives $K - A = K - B$, which is also false. - $K$ is between $A$ and $B$. This gives $K - A = B - K$, which gives $2K = A+B$. Thus, we must have $2K=A+B$. If $A+B$ is odd, there is thus no solution. If $A+B$ is even, our answer is $\frac{A+B}{2}$. It is easy to verify that this number is indeed between $A$ and $B$. Runtime: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc135/submissions/6560205) --- #B &mdash; 0 or 1 Swap Let $K$ be the number of positions $i$ at which $p_i \neq i$ (using 1-indexing). If $K = 0$, the answer is yes, as we can simply leave the permutation as is. If $K = 2$, the answer is also yes: swap the two misplaced elements. (Notice that we can never have $K = 1$, as if any element is put in the wrong posi...
the wrong position, the element that was meant to be in that position must also be misplaced.), We now reformulate this as a graph problem. Notice that if we start a copy of $T$ inposition $i

Full text and comments »

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

111.
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...
- if after step $2$ the coin on node $i$ is red, the previous position of the red coin is fixed

Full text and comments »

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

112.
By djm03178, 3 years ago, In English
Can we upgrade contest divisions? Often these days it feels like the problems are too hard for their positions but it's almost never the other way. I'm not saying these problems are fundamentally bad &mdash; it's good to confront them to improve our problem solving skills &mdash; but it's not very healthy in a contest's perspective. Let me bring up some examples: **Example 1.** Yesterday's contest, [contest:1973], had no official all solves. Most of Grandmasters, and even LGMs suffered from the difficulty of problem F. Less than 1% of the official participants were able to solve any of the harder half of problems of the contest. **Example 2.** [contest:1971], had the hardest problem [problem:1971H] that requires knowledge of 2-SAT. Only a very few official participants were able to solve it even though the topic was pretty well-known, just because the subject's level itself is too high. I think this is one of the harder topics even for the last problem of Div. 3, but it appeared on a Div. 4 contest. **Examp...

Full text and comments »

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

113.
By Geothermal, history, 7 years ago, In English
AtCoder Beginner Contest 140 English Solutions #A &mdash; Password We have $N$ choices for each of the three characters in our password. This gives us a total of $N \cdot N \cdot N = N^3$ possible passwords. We can thus print $N \cdot N \cdot N$ as our answer. Runtime: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc140/submissions/7380201) --- #B &mdash; Buffet We can solve this with a brute-force simulation, simply implementing the procedure given in the problem. Iterate over the dishes in the order specified by array $A$, and when we eat dish $i$, add $B[i]$ to our answer, plus $C[i-1]$ if we just ate dish $i-1$. Note that since we'll eat every dish once, we could also just add the sum of array $B$ to our answer as we read it in, iterating over $A$ only to add values from $C$ where necessary. My solution implements this approach. Runtime: $O(N)$. [Click here for my submission.](https://atcoder.jp/contests/abc140/submissions/7383059) --- #C &mdash; Maximal Value We're giv...
subarrays become invalid occur when we leave the array--that is, one position before the start of the array, ways our subarray could contain exactly one larger number: it could contain position $a$, but not

Full text and comments »

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

114.
By Geothermal, history, 7 years ago, In English
A Concise Solution to Problem E from Round #642 Since yesterday's Div. 3 round, I've received several PMs asking me to explain my solution to problem E ([link here](https://codeforces.me/contest/1353/problem/E)). As far as I'm aware, it's one of the simplest solutions submitted from an implementation standpoint; the code is relatively short and only one line involves nontrivial logic. So, I figured it might be more efficient to just post a writeup publicly. (As an aside, this is not something I do often; I am unable to respond to most PMs I receive asking for problem explanations. I'm writing this post because I received multiple requests related specifically to my solution for this particular problem, and because I happened to have the time. Generally, though, PMing me over Codeforces is unfortunately not an especially efficient way to get help with problems.) I'll try to outline my thought process as I worked through the problem, since I think solving E within three minutes was probably the biggest single contributing facto...
, if we have a string such that the last `1` is at position $i-K$, then we can create a string such

Full text and comments »

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

115.
By eugenechka.boyko.2_0-0, 19 months ago, translation, In English
Codeforces Round 1022 Editorial #### [problem:2108A] Author: [user: eugenechka.boyko.2_0-0,2025-04-30] <spoiler summary="Solution"> Let’s start with $p = [1, 2, 3, …, n]$. For this $p$, $f(p) = 0$. Let’s move $n$ to the beginning one position at a time. It’s easy to see that we increase the answer by $2$ at each step. Now, let’s move $n - 1$ to position $2$, then $n - 2$ to position $3$, and so on, until we reach $p = [n, n - 1, …, 2, 1]$. For this $p$, $f(p) = \lfloor \frac{n^2}{2} \rfloor$. While doing this, we obtained every even value from $0$ to $\lfloor \frac{n^2}{2} \rfloor$, since we were adding $+2$ at each step. Let’s prove that we can’t get any other values. First of all, it’s easy to see that we can’t obtain a value less than $0$ or greater than $\lfloor \frac{n^2}{2} \rfloor$. Second, we can only obtain even values, because each swap changes the answer by an even number. So the answer is $\lfloor \frac{n^2}{4} \rfloor + 1$ Time complexity : $\text{O}(1)$. </s...
third position). Let's discard the elements in these positions:, 1. The resulting height at the $i$-th position will be $r'_i$., Now, let’s move $n - 1$ to position $2$, then $n - 2$ to position $3$, and so on, until we reach $p, position where the elements in the permutations differ. Let it be the second position. Note all the

Full text and comments »

116.
By galen_colin, 3 years ago, In English
WF23 Luxor _(Long blog ahead. Reader discretion advised.)_ I feel we have a rather interesting WF story (note: we did the 47th finals, as the University of Maryland, <b><i>as 2 people</i></b>... explained below), so I figured I'd tell it. Exposition ---------- It actually starts way before WF, too. Our teams were decided on (some form of) merit based on an internal qualifier. My team for the regional and NAC (North America superregional) ended up as {me, [user:Navick,2024-04-24], [user:mr.banana,2024-04-24]}. We did [fairly](https://nasouth22d1.kattis.com/contests/nasouth22d1/standings) [well](https://nac.icpc.global/wp-content/uploads/2023/06/NAC23-scoreboard.pdf) in those. However, for WF, my two teammates only had single-entry visas for the US, meaning that if they left, they couldn't come back into our country. So they couldn't really go with me... Luckily, in such situations, ICPC lets you just replace your teammates. So we held another internal qualifier, and ended up with two ...
shame, but in our position there was nothing that any of us could do about it. ICPC did seemingly try

Full text and comments »

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

117.
By TheScrasse, 12 months ago, In English
Codeforces Round 1066 (Div. 1 + Div. 2) Editorial [problem:2157A] Author: [user:TheScrasse,2025-11-22]<br> Preparation: [user:TheScrasse,2025-11-22] <spoiler summary="Hint 1"> Each value $x$ is independent of the others; only its own frequency matters. </spoiler> <spoiler summary="Hint 2"> In a balanced array, value $x$ must appear either $0$ times or **exactly** $x$ times. </spoiler> <spoiler summary="Solution"> - Each value $x$ is independent of the others; only its own frequency matters. In particular, for each value, find its frequency $f[x]$. - In a balanced array, value $x$ must appear either $0$ times or **exactly** $x$ times. Specifically, if it appears $< x$ times at the beginning, you have to delete all its occurrences, otherwise you should keep $x$ occurrences. Specifically, for each $x$, add $f[x]$ to the answer if $f[x] < x$, else add $f[x] - x$. Complexity: $O(n)$ time. Slower solutions (e.g., $O(n^2)$) are allowed. </spoiler> <spoiler summary = "Code"> [submission:350380351] </spoiler> [...
the position in the whole array, instead of the position only considering such elements) also works

Full text and comments »

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

118.
By TooNewbie, 9 years ago, In English
[Tutorial] Invariants and Monovariants Hello Codeforces! Some months ago I wrote tutorial about [basics of recurrent sequences](http://codeforces.me/blog/entry/54154). This blog, my second tutorial is about mine another favorite topic &mdash; Invariants and Monovariants. These are useful concepts which will help you solving problems, especially, constructive ones. Even if you are not familiar with this topics, I'm sure that you solved problems with use of invariants and monovariants without knowing it, continue reading, you will understand my point :) There will be hard problems which are based on old IMO problems, so I will try my best to explain solutions of examples. So, what are Invariants and Monovariants? An invariant is a quantity that doesn't change. A monovariant is a quantity that changes monotically (that is, non-decreasing or non-increasing). Seems simple, yes? Let's start with a few easy examples which you will better understand its point. I suggest you to try solving problems by your own before reading ...
**Solution 0.2:** This problem is a little trickier. Let the first position of card of $i$ be $a_i

Full text and comments »

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

119.
By meooow, 8 years ago, In English
[Tutorial] Convex Hull Trick — Geometry being useful ### The problem Let us consider the problem where we need to quickly calculate the following over some set $S$ of $j$ for some value $x$. $$\max_{j \in S} \{m_j \cdot x + c_j\}$$ Additionally, insertion of new $j$ into $S$ must also be efficient. This will most likely be encountered with DP problems. For example, the recent problem [problem:1083E] from Round #526 has the following DP formulation after sorting the rectangles by $x$. $$f(i) = x_i \cdot y_i - a_i + \max_{1 \le j < i}\{-x_j \cdot y_i + f(j)\}$$ The problem requires quick calculation of the above define maximum for each index $i$. How can this be done? ### The idea Notice the special form of $m_j \cdot x + c_j$. This is identical to the equation of a straight line with slope $m_j$ and Y-intercept $c_j$. So the problem is equivalent to being given a set of lines and asked for the maximum $y$ value any of those lines can give at a particular $x$. If you draw a bunch of straight lines on a plane, you'll...

Full text and comments »

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

120.
By wuhudsm, history, 3 years ago, In English
My ultra-short problemset which can be read in 60s (Last updated time:$2023/8/31,14$ problems) Hi guys,here I'd like to share some of my problems(will continue to be updated, depending on your feedback). All the problems are created by myself. They contain my aesthetic of problems: the neater,the better. Interest and educational significance are also important. You can find the editorial for all the problems in the link,so I will only write down some interesting points under the statement. Let's go :) #### [1.Increasing and Decreasing](https://mirror.codeforces.com/contest/1864/problem/A) Construct an array $a$ consisting of $n$ integers which satisfies the following conditions: - $a_1=x,a_n=y$; - $a$ is **strictly** increasing; - if we denote $b_i=a_{i+1}-a_{i}$ for $1 \leq i \leq n-1$, then $b$ is **strictly** decreasing. <spoiler summary="Constraint"> $1 \le x < y \le 1000,3 \le n \le 1000$ </spoiler> <spoiler summary="Difficulty"> DIV2A </spoiler> <spoiler summary="Point"> One of the easi...
- The plate at position $1$ will move to position $2$; - The plate at position $2$ will move to

Full text and comments »

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

121.
By ecnerwala, 11 years ago, In English
8VC Venture Cup 2016 — Final Round Editorial ###[problem:635A] We can iterate over each possible rectangle and count the number of violists enclosed. This can be optimized with rectangular prefix sums, though the simple brute force is sufficient for this problem. Runtime: $O(n^6)$ ###[problem:634A] Notice that, as we move the empty pedestal around the circle, we cyclically permute the statues (and the empty pedestal can be anywhere). Thus, we can reach one state from another if and only if, after removing the empty pedestal, they are cyclic shifts of each other. The starting and ending configurations are permutations, so we can check this in linear time. Runtime: $O(n)$ ###[problem:627A] For any two integers $a$ and $b$, we have $s = a + b = (a \oplus b) + (a \& b) * 2$, where $a \oplus b$ is the xor and $a \& b$ is the bitwise AND. This is because $\oplus$ is non-carrying binary addition. Thus, we can find $a \& b = (s - x) / 2$ (if this is not an integer, there are no solutions). Now, for each bit, we ha...
Now, to check satisfiability, we can greedily first move the empty pedestal from its startposition

Full text and comments »

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

122.
By ACGN, history, 2 years ago, In English
Codeforces Round 987 (Div. 2) Editorial <spoiler summary="A little backstory about the round (ACGN)">The Highschool CPers (HSCP) Discord server was created in April 2022 by [user:pwned,2024-11-14], which over time grew into a close-knit community of highschool competitive programmers. I joined in the same month of its creation, and in the next month I approached [user:pwned,2024-11-14] about the possibility of setting a contest. Thus the HSCP round concept was born. Over the next month or so, the initial problems were born; the current problems A and F were produced in June-July 2022. We had several problem ideas by then, enough to set a div.2 round. However, as I was going to be busy in my 5th year of high school, and may not be that responsive to coordinators, the contest was in the ownership of [user:pwned,2024-11-14], who needed to wait until he reached master in order to propose the set on Codeforces. However, this step took almost 1.5 years as he would stay at candidate master for 57 consecutive contests, eve...

Full text and comments »

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

123.
By thenymphsofdelphi, 4 years ago, In English
Codeforces Round #873 (Div. 1 & 2) Editorial ## [problem:1828A] Idea: [user:thenymphsofdelphi,2023-05-14] <br> Preparation: [user:Mike4235,2023-05-14] <spoiler summary="Hint 1"> Remember the sum of the first $n$ positive integers? </spoiler> <spoiler summary="Hint 2"> Every positive integer is divisible by $1$. </spoiler> <spoiler summary="Solution"> Consider the array $a = \left[1, 2, \ldots, n\right]$ that satisfies the second condition. It has the sum of $1 + 2 + \dots + n = \frac{n(n+1)}{2}$. One solution is to notice that if we double every element $(a=\left[2, 4, 6, \ldots, 2n\right])$, the sum becomes $\frac{n(n+1)}{2} \times 2 = n(n + 1)$, which is divisible by $n$. Another solution is to increase the value of $a_1$ until the sum becomes divisible by $n$. This works because every integer is divisible by $1$, and we only need to increase $a_1$ by at most $n$. Time complexity: $\mathcal{O}(n)$ </spoiler> <spoiler summary="Implementation 1"> ```c++ #include <bits/stdc++.h> using namespace s...
Try to calculate the contribution of each position. , $ be the last position satisfying $p_j>p_k$ or $p_jposition, Consider a position $i$ ($1\le i\le n$), let's count how many triplets $(l, k, r)$ satisfy

Full text and comments »

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

124.
By ko_osaga, history, 4 years ago, In English
Random notes on Lyndon decomposition I recently solved some problems that involved the concept of Lyndon decomposition. Honestly, most of them were too hard to understand for me. I'm just trying to think out loud about things I've read, so I can learn ideas or better takes from smarter people? Note that I will omit almost all proofs as I can't do that. I believe all unproven claims below are facts, but it is always great to have doubts about anything. ## 1. Lyndon decomposition, definition, and algorithms Partly copy-pasted from [this link.](https://cp-algorithms.com/string/lyndon_factorization.html#lyndon-factorization_1) A string is called simple (or a Lyndon word), if it is strictly smaller than any of its own nontrivial suffixes. Examples of simple strings are $a, b, ab, aab, abb, abcd, abac$. It can be shown that a string is simple, if and only if it is strictly smaller than all its nontrivial cyclic shifts. As a corollary, it can be observed that simple words are never periodic (it is not a repetition o...
reverse each substring from that respective position., rotating at the respective position. This suffix can be found with Lyndon decomposition. Therefore we

Full text and comments »

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

125.
By I_love_tigersugar, 7 years ago, In English
Codeforces Round #601 Editorial [problem:1255A] Author: [user:UncleGrandpa925,2019-11-20]. Prepared by [user:UncleGrandpa925,2019-11-20] <spoiler summary="Tutorial"> [tutorial:1255A] </spoiler> [problem:1255B] Author: [user:prof.PVH,2019-11-20] ft. [user:MikeMirzayanov,2019-11-20]. Prepared by [user:UncleGrandpa925,2019-11-20] <spoiler summary="Tutorial"> #### Modelize the problem We modelize the problem as graph, where each fridge is a vertex and each chain is an edge between two vertexes. The problem is now equivalent to: Given a graph with $n$ vertexes, each vertex has a value $a_i \ge 0$. We have to add $m$ edges to the graph such that each vertex is connected to at least two different vertexes and the total cost of edges added is minimum. The cost of an edge is the sum of value of its two end-points. #### Observe some basic properties of graph Now, each edge added will increase the sum of degree of all vertexes by 2. So adding m edges will make the sum of degree equal to $2 \times m$. ...
- First, in each segment, let $A$ be the array of all position with 1, then the position that we

Full text and comments »

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

126.
By oolimry, history, 6 years ago, In English
Codeforces Raif Round 1 Editorial [problem:1428A] ------------------ Setter: [user:bensonlzl,2020-10-17] Prepared by: [user:errorgorn,2020-10-17] <spoiler summary="Hint 1"> Consider when $x_1=x_2$ </spoiler> <spoiler summary="Hint 2"> Consider when $x_1 \ne x_2$ </spoiler> <spoiler summary="Solution"> We consider 2 cases. The first is that the starting and ending point lie on an axis-aligned line. In this case, we simply pull the box in 1 direction, and the time needed is the distance between the 2 points as we need 1 second to decrease the distance by 1. The second is that they do not lie on any axis-aligned line. Wabbit can pull the box horizontally (left or right depends on the relative values of $x_1$ and $x_2$) for $|x_1-x_2|$ seconds, take 2 seconds to move either above or below the box, then take another $|y_1-y_2|$ seconds to move the box to $(x_2,y_2)$. </spoiler> <spoiler summary="Code (C++)"> ```c++ #include <bits/stdc++.h> using namespace std; int main(){ ios_base::...
// the initial starting position of ring 0 // to be position 0 relpos[0] = 0;, increase, we are certain that there was another arc at that position, so we shift arc 0 left. We now, this position int relpos[105] = {}; // Array to store the final relative positions, We move arc 0 left to check if any arc is at position $x-1$.

Full text and comments »

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

127.
By icecuber, 7 years ago, In English
CSES DP section editorial Edit: More dp tasks have been added to CSES since this blog was created. For solutions to those problems, check out [user:UnexpectedValue,2023-02-14]'s blog [here](https://codeforces.me/blog/entry/111675). I'm using bottom-up implementations and pull dp when possible. Pull dp is when we calculate each dp entry as a function of previously calculated dp entries. This is the way used in recursion / memoization. The other alternative would be push dp, where we update future dp entries using the current dp entry. I think [CSES](https://cses.fi/problemset/list/) is a nice collection of important CP problems, and would like it to have editorials. Without editorials users will get stuck on problems, and give up without learning the solution. I think this slows down learning significantly compared to solving problems with editorials. Therefore, I encourage others who want to contribute, to write editorials for other sections of CSES. Feel free to point out mistakes. ## Dice Combin...
Naively locating the position x with a for loop gives complexity $O(n^2)$. However, dp is always an, When we are at some position with a `.`, we came either from the left or top. So the number of ways

Full text and comments »

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

128.
By 244mhq, 7 years ago, translation, In English
Editorial of Codeforces Round #572 Codes have been added! We've added challenges(mostly not hard) to some tasks. Feel free to share solutions and ask any questions in comments! Keanu Reeves ---------- If the string is good, then answer it's itself. Otherwise, there are at least two strings in answer, and we can print substring without its last symbol and its last symbol separately. Complexity $O(n)$. [code](https://pastebin.com/Dc0gtG9n) Number circle ---------- Let's suppose that array is sorted. First of all, if $a_n \ge a_{n - 1} + a_{n - 2}$, than the answer is &mdash; NO (because otherwise $a_{n}$ is not smaller than sum of the neighbors). We claim, that in all other cases answer is &mdash; YES. One of the possible constructions (if the array is already sorted) is: $a_{n - 2}, a_{n}, a_{n - 1}, a_{n - 4}, a_{n - 5}, \ldots ,a_1$ It's easy to see, that all numbers except $a_n$ will have at least one neighbor which is not smaller than itself. Complexity $O(nlog(n))$. [code](https://past...
$bits[t' + b_i] = bits[t + b_i]$, if at position $s - 1$ in binary notation $t + b_i$ was 0

Full text and comments »

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

129.
By Gellyfish, 18 months ago, In English
Codeforces Round 1028 (Div.1, Div.2) Editorial You could tell people didn't seem to like the match very much. I'm sorry I screwed up again ¯\\_(ツ)_/¯ If you're interested, I'd like to share some thoughts I have about this contest. <spoiler summary="sad story"> This time I've been trying my best to make the problems use more varied algorithms instead of just dp problems, but sadly [problem:2115C] was much harder than expected. But it seems like people are complaining more about the narrow time limit, centered on [problem:2116C] and [problem:2115C]. No one realized this before the contest, because none of the tester's code is get TLE except the wrong time complexity. I actually don't see a problem with the Time Limit of [problem:2116C]. Some of you may be puzzled, but let me try to explain this: - The intended solution is $O(\sum n \max(a) + \max(a)^2)$ and does not contain $\log \max(a)$. Computing $\gcd(x, y)$ is not $O(1)$, if you don't preprocess, then it's not unusual to actually get a TLE. - I believe the v...
At the end of each round, we rebuild the sequence. Specifically, for each position in the sequence

Full text and comments »

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

130.
By AquaMoon, 4 years ago, In English
Polynomial Round 2022 (Div. 1 + Div. 2, Rated, Prizes!) Hello, Codeforces! <img alt="Polynomial" src="https://codeforces.me/predownloaded/31/39/3139af7f9a6628da7d4b7ce4353a192cf59ee3f5.png" style="float:right;height: 250px; margin: 10px; max-width:50%;"/> Winter holiday is coming! And we are excited to invite you to our third round, [contest:1774], which will be held on [contest_time:1774]. You are given **8 problems** and **2.5 hours** to solve them. All problems were written and prepared by [user:Ecrade_,2022-12-14], [user:Little09,2022-12-14], [user:ChthollyNotaSeniorious,2022-12-14], [user:DataStructures,2022-12-14], [user:Cirno_9baka,2022-12-14], [user:mejiamejia,2022-12-14] and me. And thanks to [user:dorijanlendvaj,2022-12-14], [user:gisp_zjz,2022-12-14], [user:gamegame,2022-12-14], [user:triple__a,2022-12-14], [user:Chenyu_Qiu,2022-12-14], [user:Suiseiseki,2022-07-25], [user:q-w-q-w-q,2022-12-14], [user:leukocyte,2022-12-14], [user:waaitg,2022-12-14], [user:Kubic,2022-12-14], [user:LHQing,2022-12-14], [user:zrmpaul...

Full text and comments »

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

131.
By brunomont, history, 5 years ago, In English
[Tutorial] Dynamic Suffix Arrays Hello, Codeforces! In this blog I will describe yet another <s>useless</s> unconventional data structure. This time, I will show how to maintain an extended suffix array (suffix array, inverse of suffix array, and $lcp$ array) while being able to add or remove some character at the <b>beginning</b> of the string in $\mathcal{O}(\log n)$ amortized time. It can be used to <s>overkill</s> solve problem M from [2020-2021 ACM-ICPC Latin American Regionals](https://codeforces.me/gym/103185), which my team couldn't solve during the contest. I learned it from [here](https://oi-wiki.org/string/suffix-bst/) (Chinese), but it is not shown how to maintain the $lcp$ array. Here is the whole code of the data structure. To read this blog, I recommend you ignore this code for now, but use it if you have questions about helper functions, constructors, etc, since I will pass over some implementation details in the explanations. <spoiler summary="Full code"> ~~~~~ struct dyn_sa { struct ...
Here, the $i$-th position of the $lcp$ array will denote the longest common prefix between $SA[i

Full text and comments »

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

132.
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 ...
representation of $a$ has $1$ on the $i$-th position from the right, there will be $1$ on the $(i-1)$-th, track his position, it's enough to store one variable denoting his current distance from the North

Full text and comments »

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

133.
By zscoder, history, 7 years ago, In English
Valentine's Day Contest 2020 Editorial I hope you enjoyed the contest! Expected problem difficulty is F < A < (G ~ D) < (C ~ E) < B (though it might be different for different people). I will mainly focus on explaining the full solution to the problems but I will briefly mention how to pass certain subtasks. ### Problem A &mdash; Leakage <spoiler summary="Solution"> This is unfortunately the most standard problem of the set. Obviously, we can model the friends as vertices and friendships as edges in an undirected graph. The problem basically asks us to answer queries of the form: "For a pair of vertices $u, v$, find the number of vertices $w \neq u, v$ such that removing $w$ from the graph disconnects $u$ and $v$". Removing vertices and disconnecting graphs should remind one of articulation points. The data structure to solve this problem is [block-cut tree](https://en.wikipedia.org/wiki/Biconnected_component#Block-cut_tree). Each biconnected component is considered as a block. An articulation point might be...
Call a position in the string bad if there exists a way for Nibutani

Full text and comments »

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

134.
By awoo, history, 7 years ago, translation, In English
Educational Codeforces Round 83 Editorial [problem:1312A] Idea: [user:BledDest,2020-03-10] <spoiler summary="Tutorial"> [tutorial:1312A] </spoiler> <spoiler summary="Solution (vovuh)"> ~~~~~ for i in range(int(input())): n, m = map(int, input().split()) print('YES' if n % m == 0 else 'NO') ~~~~~ </spoiler> [problem:1312B] Idea: [user:Roms,2020-03-10] <spoiler summary="Tutorial"> [tutorial:1312B] </spoiler> <spoiler summary="Solution (Roms)"> ~~~~~ for t in range(int(input())): n = input() print(*sorted(map(int, input().split()))[::-1]) ~~~~~ </spoiler> [problem:1312C] Idea: [user:adedalic,2020-03-10] <spoiler summary="Tutorial"> [tutorial:1312C] </spoiler> <spoiler summary="Solution 1 (adedalic)"> ~~~~~ fun main() { val T = readLine()!!.toInt() testCases@for (tc in 1..T) { val (_, k) = readLine()!!.split(' ').map { it.toLong() } val a = readLine()!!.split(' ').map { it.toLong() }.toLongArray() var maxPower ...

Full text and comments »

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

135.
By wsc2008qwq, history, 19 months ago, In English
How to Solve IOI2024 P2 Message Using Fewer Bits In this problem, we are required to transmit a message of up to $1024$ bits using at most $66$ packets. Each packet contains $16$ good bits, resulting in a total of $1056$ bits. Since the length of the message is unknown, transmitting it requires $1025$ bits—an extra bit is needed to record the length. This leaves only $31$ available bits, which happens to match the value of $N$ (the length of a packet). The intended solution uses exactly $N$ bits, which is sufficient to solve the problem. However, even if only $N−1$ bits are allowed, the problem still has a solution. In the following discussion, assume that each sent packet is denoted as $A$, and the state of each bit is $C$, where $C=1$ means the bit remains unmodified, and $C=0$ means it is modified. Note that the definition of $C$ is opposite to that in the original problem. It can be observed that if the states of $N−1$ out of $N$ bits are already determined, the state of the last bit can be directly deduced. To determ...
- For each determined position $u$:

Full text and comments »

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

136.
By Endagorion, history, 9 years ago, In English
Yandex.Algorithm 2017, third elimination round: editorial (with challenges, bells and whistles) This time I've decided to play with spoilers to faciliate the presentation as some of the guys here did before. Tell me what you think about this write-up! #### Problem A. Shifts Topics: dynamic programming. Summary: the first "hard" problem of the contest. Knowing your basic DP problems helps a lot, but coming up with the precisely correct solution may take a lot of persistence. Solution: Suppose that we are allowed to make left circular shifts as well as right ones. <spoiler summary="Can you solve the problem in this case?"> First of all, making a shift is effectively moving a character to a different position in the string. Clearly, moving a character more than once makes no sense since we could have just moved it to its final destination instead without wasting any operations. Also, it obvious that the number of occurences of each character should be the same in both strings since it is preserved by shifts. Now, consider the characters that are *not* moved by ...
First of all, making a shift is effectively moving a character to a different position in the, How to solve the problem if we are travelling in $k$-dimensional Manhattan, that is, theposition

Full text and comments »

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

137.
By Serval, 20 months ago, In English
Codeforces Round #1011 (Div. 2) Editorial <spoiler summary="Fun Fact 0"> [Attention is all you need](https://arxiv.org/abs/1706.03762). </spoiler> <spoiler summary="Fun Fact 1"> The current problems are the original A A B C D E, respectively. </spoiler> <spoiler summary="Fun Fact 2"> The idea for problem D came up after eating at Sushiro, and the idea for problem E came up after eating at McDonald's. However, Sushiro is not a buffet restaurant. :( </spoiler> <spoiler summary="Fun Fact 3"> The intended solutions are short. </spoiler> <spoiler summary="Fun Fact 4"> Some (very) strong testers couldn't solve E when testing, and that's why we gave E so much score. </spoiler> <spoiler summary="Fun Fact suggested by testers"> ![...](/predownloaded/61/a0/61a03f0e26b325e41dd12a2aa483b30b9e9e7c30.png) </spoiler> #### [problem:2085A] <spoiler summary="Hint 1"> When $s$ is lexicographically equal to or greater than the reversal of $s$, is it possible to make $s$ *universal* by performing the operations? ...
Focusing on the middle position of the *colorful* subarray, we enumerate all the positions in the

Full text and comments »

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

138.
By huangzirui, history, 4 years ago, In English
Editorial of Codeforces Round 796 [problem:1688A] Idea: [user:huangzirui,2022-06-03]. Solution: [user:huangzirui,2022-06-03]. Preparation: [user:huangzirui,2022-06-03]. Good problem Average problem Bad problem Did not solve <spoiler summary="Hint"> Consider $x=2^k$ and $x\ne 2^k$ separately. </spoiler> <spoiler summary="Solution"> Let $p_i$ be the $i$-th bit of $x$, $q_i$ be the $i$-th bit of $y$ (both indexed from $0$). $x\ \texttt{and}\ y > 0\Leftrightarrow \exists i,\ p_i= q_i = 1$. $x\ \texttt{xor}\ y > 0\Leftrightarrow \exists i,\ p_i\ne q_i$. To satisfy the first condition, find the minimum integer $k$ satisfying $p_k=1$, and assign $1$ to $q_k$. If $x\ne 2^k$, the second condition is satisfied now. Otherwise, find the minimum integer $j$ satisfying $p_j=0$, and assign $1$ to $q_j$. The time complexity is $O(1)$. </spoiler> <spoiler summary="Code (C++)"> ```cpp #include<bits/stdC++.h> ...
one position more than one times, and the answer is $\frac{k(k+1)}{2}$. - We can find that, position more than one times, and the answer is $\max\limits_{k\le i\le n}\sum\limits_{j=i-k+1

Full text and comments »

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

139.
By paulzrm, history, 4 months ago, In English
Codeforces Round 1116 (Div. 1, Div. 2) Editorial [2256A-Three Numbers on the Blackboard](https://codeforces.me/contest/2256/problem/A) Idea: [user:paulzrm,2026-08-10] <spoiler summary="Hint 1"> Sort the numbers as $a\le b\le c$. </spoiler> <spoiler summary="Hint 2"> After at least one operation, consider the median. </spoiler> <spoiler summary="Hint 3"> Doing nothing gives $c-a$; replacing $c$ with $a+b$ gives $b$. </spoiler> <spoiler summary="Tutorial"> Suppose the current numbers are $x\le y\le z$. An operation keeps two numbers and replaces the third with their sum. Since all values are nonnegative, the new sum is no smaller than either retained number. Thus the new median is the larger retained number, which is at least the old median $y$. The median never decreases. After an operation that retains $u\le v$, the numbers are $u,v,u+v$. Their range is exactly $v$, also their median. Hence every nonempty sequence of operations ends with a range of at least the initial median $b$. With no opera...
Only these two old values need to persist at each position.

Full text and comments »

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

140.
By Zlobober, 12 years ago, translation, In English
VK Cup Round 1 (+ online mirror) editorial Problemsets slightly differ in main round and in an online mirror, in editorial problems follow in an order of the main round. [problem:524A] ============== This problem didn't appear in an online mirror. Its editorial will be left as an exercise in Russian language for those who are curious what it is about =) [problem:524B] ============== In an original version there was no constraint that no more than n / 2 friends should lie. This version can be solved pretty easy. Iterate over all possible values of $H$. For a fixed $H$ we have to minimize total width of all rectangles on the photo. So, for each rectangle we need to choose in which orientation it fits into photo having the minimum possible width. [problem:529B] ============== In an online mirror version the problem was slightly harder. Let's call people with $w \leq h$ \textit{high}, and remaining people \textit{wide}. Let's fix photo height $H$. Let's consider several following cases: * If a high person fi...

Full text and comments »

Tutorial of VK Cup 2015 - Round 1
  • Vote: I like it
  • +90
  • Vote: I do not like it

141.
By Xellos, 13 years ago, In English
Codeforces Trainings Season 1 Episode 10: Editorial #### **Welcome to The Editorial!** <img src="http://th04.deviantart.net/fs70/PRE/f/2013/078/b/f/mi_super_saiyan_god_remasterizado_by_salvamakoto-d5ymxyi.png" height="50%" width="50%" /> **Keep the upvotes piling up! muhehe** IZ.COMPLETE. ### A. Rasheda And The Zeriba [cut] $\ $ (difficulty: medium) The first question is: When is it possible to construct a (convex) polygon from sticks of given lengths $L_i$? This question is answered by what's sometimes known as Polygon inequality theorem, which states that the sufficient and necessary condition is for every $L_i$ to be strictly less than the sum of all other $L_i$. You can imagine that it works because for the endpoints of every side, the shortest path between them (equal to the length of that side) must be smaller than any other path, including the other one along the perimeter of the polygon; constructing such a polygon, even a convex one, is pretty easy, just imagine it as having sticks linked to each other that...
(if we have a pair) to the smaller position ($N-1$ to position $i$, $N$ to pos. $N$, etc.).

Full text and comments »

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

142.
By DeMen100ns, history, 4 years ago, In English
Codeforces Round #812 (Div. 2) Editorial <spoiler summary="Before the round starts"> Great efforts have been put over last year. We want to say thanks to everybody who helped us to make this round as it is. Cannot wait to see you guys on the next one! <spoiler summary="Testers' predictions"> <table> <tr style ="background-color:#D3D3D3"> <th>Tester</th> <th>A</th> <th>B</th> <th>C</th> <th>D</th> <th>E</th> <th>F</th> </tr> <tr> <td>[user:tfg,2022-08-06]</td> <td>800</td> <td>1100</td> <td>1500</td> <td>1600</td> <td>1900</td> <td>2400</td> </tr> <tr> <td>[user:neko_nyaaaaaaaaaaaaaaaaa,2022-08-06]</td> <td>800</td> <td>1100</td> <td>1700</td> <td>1900</td> <td>2100</td> <td>2600</td> </tr> <tr> <td>[user:BucketPotato,2022-08-06]</td> <td>800</td> <td>1000</td> <td>1400</td> <td>1800</td> <td>2400</td> <td>-</td> </tr> <tr> <td>[user:LetterC67,2022-08-0...
And for each position that that cell can travel to, how many ways are

Full text and comments »

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

143.
By wangmarui, history, 11 months ago, In English
Hello 2026 Editorial We'd like to thank you all for participating in the contest, and hope you enjoyed it. Any feedback would be appreciated! <spoiler summary="Rate The Contest!"> - Great contest - Good contest - Average contest - Bad contest </spoiler> ## [2183A &mdash; Binary Array Game](https://codeforces.me/contest/2183/problem/A) Idea & Preparation: [user:wangmarui,2025-12-23] <spoiler summary="Rate The Problem!"> - Good Problem - Okay Problem - Bad Problem - Didn't Solve </spoiler> <spoiler summary="Hint 1"> If the sequence $a$ consists entirely of $1$ s, what will Alice do? </spoiler> <spoiler summary="Hint 2"> Consider discussing the values of $a_1$ and $a_n$. </spoiler> <spoiler summary="Solution"> First, if the entire sequence consists of $1$ s, Alice wins immediately by operating on the whole sequen...
condition of a unique solution), the position this snake would reach if it moved ignoring obstacles

Full text and comments »

Tutorial of Hello 2026
  • Vote: I like it
  • +146
  • Vote: I do not like it

144.
By adamant, history, 2 years ago, In English
Double-ended eertree Hi everyone! Quite recently, a problem named [Palindromes in Deque](https://judge.yosupo.jp/problem/palindromes_in_deque) was added to the Library Checker that asks you to execute the following: 1. Add a character $c$ to the beginning or the end of a string $s$; 2. Remove a character from the beginning or the end of $s$. In-between the queries you also need to maintain the number of distinct palindromes, and the size of the largest prefix- and suffix-palindromes of the current string. The problem on Library Checker uses the approach from [Double-Ended Palindromic Trees](arxiv.org/abs/2210.02292) article by, presumably, [user:liouzhou_101,2024-06-10]. The paper is quite long though, so after briefly looking through introduction part to familiarize myself with their main concepts, I decided to do something a bit different than they did. In this blog, I will explain my approach. [cut] <hr> ### Recap First, let's briefly recall what an **eertree** is. If we consid...
the position of their center. Well, that's it! We will keep a second deque that will store the

Full text and comments »

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

145.
By arvindf232, 4 years ago, In English
Codeforces Round #822 (Div.2) Editorial Thank you for your participation! [1734A &mdash; Select Three Sticks](https://codeforces.me/contest/1734/problem/A) ------------------ We first sort the array $a$ in non-decreasing order. Denote the indices of the elements that we choose from $a$ to be $x$, $y$, and $z$, where $1 \le x < y < z \le n$, and the final value (after performing the operations) of the concerned elements to be $v$. The minimum required number of operations is then $|a_x-v|+|a_y-v|+|a_z-v|$. It is well-known that such expression attains its minimum value when $v$ is the median of $a_x$, $a_y$, and $a_z$. Since the array $a$ has already been sorted, it is best to assign $v$ to be $a_y$. Our expression then becomes $|a_x-a_y|+|a_y-a_y|+|a_z-a_y|=(a_y-a_x)+0+(a_z-a_y)=a_z-a_x$. We would like to minimize the value of $a_z$, which implies $z$ should be as small as possible since $a$ is sorted. It is clear that taking $z=y+1$ would minimize the value of the expression. Similarly, we can show that we ...
right, start from position $k$, then find the smallest position $r$ such that slimes from $k+1, This can be solved with digit DP. We process the bit position from $\lceil \log(\max) \rceil$ down

Full text and comments »

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

146.
By kondasujay2, history, 3 months ago, In English
Codeforces Round 1120 (Div 1, Div 2) Editorial Thank you to everyone who participated! We are sorry for the poor testcases on C1, along with C1 and C2's solutions being so similar to the recent Div3 E. [problem:2263A] Author: [user:kondasujay2,2026-09-12] <spoiler summary="Tutorial"> [tutorial:2263A] </spoiler> <spoiler summary="Solution"> ~~~~~ #include <bits/stdc++.h> using namespace std; void tc() { int n; cin >> n; int cnt = 0; vector<int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; cnt += a[i]; } if(cnt >= n - cnt) { cout << "Bessie\n"; } else { cout << "Elsie\n"; } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t; cin >> t; while(t--) tc(); } ~~~~~ </spoiler> <spoiler summary="Rate the problem"> - Amazing: - Good: - Ok: - Bad: - Terrible: </spoiler> [problem:2263B] Auth...
while (remaining > 0) { if (a[position] < b[position]) { while (a

Full text and comments »

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

147.
By oursaco, history, 3 years ago, In English
Codeforces Round 914 (Div. 2) Editorial Sorry for the weak pretests on A :(. We hope you enjoyed the round nonetheless. [problem:1904A] Idea: [user:Apple_Method,2023-12-09] <br> Preparation: [user:Apple_Method,2023-12-09]/[user:oursaco,2023-12-09] <br> Analysis: [user:lunchbox,2023-12-09] <spoiler summary="Solution"> There are at most $8$ positions of the knight that can attack a single cell. Therefore, we can find all $8$ positions that attack the king and the $8$ positions that attack the queen and count the number of positions that appear in both of these lists. </spoiler> <spoiler summary="Code"> ```c++ #include <bits/stdc++.h> using namespace std; int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1}; int main(){ int t; cin >> t; for(int i = 0; i < t; i++){ int a, b; cin >> a >> b; int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; set<pair<int, int>> st1, st2; for(int j = 0; j < 4; j++){ st1.insert({x1+dx[j]*a, y1+dy[j]*b}); ...

Full text and comments »

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

148.
By awoo, history, 4 years ago, translation, In English
Educational Codeforces Round 130 [Rated for Div. 2] Hello Codeforces! On [contest_time:1697] [contest:1697] will start. Series of Educational Rounds continue being held as [Harbour.Space University](https://harbour.space/) initiative! You can read the details about the cooperation between [Harbour.Space University](https://harbour.space/) and Codeforces in the <a href="http://codeforces.me/blog/entry/51208">blog post</a>. This round will be **rated for the participants with rating lower than 2100**. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally. You will be given **6 or 7 problems** and **2 hours** to solve them. The problems were invented and prepared by Adilbek [user:adedalic,2022-06-11] Dalabaev, Vladimir [user:vovuh,2022-06-11] Petrov, Ivan [user:BledDest,2022-06-11] Androsov, Mak...

Full text and comments »

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

149.
By Zlobober, 12 years ago, translation, In English
Codeforces Round #296 Editorial [problem:527A] ============== It’s easy to see that described process is equivalent to the following loop: ~~~~~ while a > 0 and b > 0: if a ⩾ b: a = a - b else: b = b - a ans = ans + 1 ~~~~~ But such naive approach will obviously lead to verdict TLE, since it makes ~$10,2015-03-19^{12}$ operations even on the third sample test. The key idea is to replace repeating subtraction operations with integer division operations. This leads to the logarithmic-time solution that looks similar to the Euclid algorithm: ~~~~~ while a > 0 and b > 0: if a ⩾ b: ans = ans + a div b a = a mod b else: ans = ans + b div a b = b mod a ~~~~~ [problem:527B] ============== The first observation is that the new Hamming distance may not be less than the old one minus two, since we change only two characters. So the task is to actually determine, if we can attain decrease by two, one or can’t attain decrease ...
can be done by just “fixing” the character that stands on the wrong position, like in “permanent, manner. For each position i of the S for each character c from “ATGC” we will calculate match(c, i

Full text and comments »

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

150.
By AmShZ, 5 months ago, In English
Repovive Call for Tasks Hello everyone! We are opening a **Call for Tasks** for upcoming Repovive contests. Repovive is a competitive programming platform that regularly hosts Starter, Standard, and Premier rounds. We are looking for original and high-quality problems from the community. We especially welcome complete contest proposals, since having a full set with a consistent difficulty curve usually leads to a better contest. However, submitting a single task is also completely fine. You can submit your proposal here: https://repovive.com/proposals/contest After submitting a proposal, we will contact you and provide feedback within at most **3 days**. If the proposal is accepted, the payment will be made immediately according to the payment structure below. ### What kind of tasks are we looking for? We are interested in problems with clean ideas, short and natural statements, and solutions where the main difficulty is algorithmic thinking. In general, we prefer tasks that are: * ...
The final position of a task may be adjusted during preparation, and the reward will be based on

Full text and comments »

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

151.
By Endagorion, 12 years ago, In English
Codeforces Round #265 Editorial I'll upload my example solutions and will post links to them as soon as it becomes possible. Some of the problems editorials contain an additional challenge which is apparently harder to comprehend than the original problem. Feel free to share and discuss your ideas in the comments. =) [problem:465A] If we add 1 to a number, its binary representation changes in a simple way: all the least significant $1$'s change to $0$'s, and the single following $0$ changes to $1$. It suffices to find the length of largest suffix which contains only $1$'s, suppose its length is $l$. Then the answer is $l+1$ except for the case when all the string consists of $1$, when the answer is $l$. It is amusing that div1E problem is concerned with addition of 1 to a binary integer as well. =) [problem:465B] Optimal strategy is as follows: for every segment of consecutive $1$'s open the first letter in segment, scroll until the last letter in segment, if there are more unread letters left, retu...
increment rightmost position so that suffix can be filled up in some way, then fill the suffix in least

Full text and comments »

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

152.
By errorgorn, 5 years ago, In English
Interesting Information-Theoretical Problem Recently, there was a local contest which I set a problem for (task 4 in [this pdf](https://drive.google.com/file/d/1-HvrkdEdsZFFiLmtKNUqEidtXAhyPfZO/view?usp=sharing)). The abridged problem statement is that you choose an array $A$ of length $N$ where the elements are $<2^X$. The grader will pick $[L,R]$ and return $A_L \oplus A_{L+1} \oplus \ldots \oplus A_R$, where $\oplus$ is the bitwise xor operation. You need to find **any** integer $z$ such that $L \leq z \leq R$. I set this in contest with the constraints of $N=2^{19}$ and $X=192 \approx \frac{(\log N)^2}{2}$ where you also had to answer queries quickly. <spoiler summary="Solution"> The main idea of my solution is to keep splitting the query range in half. Suppose we know that $l \leq L \leq R \leq r$. Let $m=\frac{l+r}{2}$. Then there are $3$ cases: 1. answer $m$ 2. recurse to $[l,m)$ 3. recurse to $(m,r]$ Let us put a bit on position $m$. If that bit is activated, then it is case 1. Otherwise, we need ...
For layer 1 ($36$ bits), the position is blank if $i \text{ mod } B != 0$. Else if $i \text{ mod, Layer 2 ($36$ bits), the position has value $R[i \text{ mod } B]$.

Full text and comments »

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

153.
By qwexd, 3 months ago, In English
Codeforces Round 1121 (Div. 2) Editorial # Codeforces Round 1121 — Editorial Thanks for participating! ### [problem:2264A] Problem by [user:qwexd,2026-09-13]. <spoiler summary="Hint"> Look at the elements that are not in the right position. Which of them must be selected? Can selecting any other element help? </spoiler> <spoiler summary="Solution"> Every element that is not in the right position has to be selected; otherwise, it never moves. Selecting an element that is already in the right position cannot help. For it to stay correct after the reversal, it has to be paired with itself, because its value occurs nowhere else in the permutation. Thus it can only be the middle selected element, and removing it changes nothing. So, if the array is already sorted, choose any one element. Otherwise, select exactly the misplaced elements and reverse them. The answer is `YES` if this sorts the array, and `NO` otherwise. If the misplaced positions are listed from left to right, the reversal pairs the...
Fix the last chosen position. Which $m-1$ earlier values are best, and how can we maintain them

Full text and comments »

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

154.
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 ...

Full text and comments »

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

155.
By dmkozyrev, history, 8 years ago, translation, In English
[Tutorial] Rolling hash and 8 interesting problems [Editorial] **UPD**: while I was translating this post from Russian to English, [user:dacin21,2018-07-06] wrote his post, more advanced, [link](http://codeforces.me/blog/entry/60442). I hope that my post will help beginners, but in my post more rough estimates. And in Russia we call **rolling hashes** as a **polynomial hashes**. Hello, codeforces! This blogpost is written for all those who want to understand and use polynomial hashes and learn how to apply them in solving various problems. I will briefly write the theoretical material, consider the features of the implementation and consider some problems, among them: 1. Searching all occurrences of one string of length $n$ in another string length $m$ in $O(n + m)$ time 2. Searching for the largest common substring of two strings of lengths $ n $ and $ m $ $(n \ge m) $ in $O((n+m \cdot log(n)) \cdot log(m))$ and $O(n \cdot log(m))$ time 3. Finding the lexicographically minimal cyclic shift of a string of length $ n $ in $ O(n \cdo...
In the first line of the output file OUTPUT.TXT, output the position number of the given string in

Full text and comments »

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

156.
By zscoder, history, 10 years ago, In English
[Tutorial] Slope Trick Hi everyone! Following my [last article](http://codeforces.me/blog/entry/47764), today I'm writing about a not-so-common trick that has nevertheless appeared in some problems before and might be helpful to you. I'm not sure if this trick has been given a name yet so I'd refer to it as "Slope Trick" here. Disclaimer : It would be helpful to have a pen and paper with you to sketch the graphs so that you can visualize these claims easier. Example Problem 1 : [problem:713C] This solution originated from [user:koosaga,2016-10-16]'s comment in the editorial post [here](http://codeforces.me/blog/entry/47094?#comment-315161). The solution below will solve this problem in $O(n\log n)$, wheareas the intended solution is $O(n^2)$. So, the first step is to get rid of the strictly increasing condition. To do so, we apply `a[i] -= i` for all $i$ and thus we just have to find the minimum number of moves to change it to a non-decreasing sequence. Define $f_{i}(x)$ as the minimum n...
Let $Opt(i)$ denote a position where $f_{i}(X)$ achieves its minimum. (i.e. $g_{i}(Opt(i)) = 0

Full text and comments »

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

157.
By wuhudsm, 3 years ago, In English
Codeforces Round 930 (Div. 1, Div. 2) Editorial Thank you for participation and we hope you enjoy this round :) #### [D2A &mdash; Shuffle Party](https://codeforces.me/contest/1937/problem/A) Idea : [user:chromate00,2023-08-27] <spoiler summary="Hint (for thinkers)"> If you think in terms of $k$, it might be hard to find the solution. Maybe it will be helpful if you fix $d$ and find the $k$ which will be swapped with $d$. </spoiler> <spoiler summary="Hint (for observers)"> Try bruteforcing for, say, $n \le 20$. Do you see a pattern? </spoiler> <spoiler summary="Tutorial"> On $n=1$, the answer is trivially $1$. On $n=2$, index $1$ and $2$ are swapped. The answer is therefore $2$. For $n>2$, let us assume the element $1$ is on index $a$ and it will be swapped with index $k$. Then, $a$ must be $k/2$. We will prove this by contradiction. Let us assume that there is no divisor greater than $a$, and $a$ is lesser than $k/2$. But then, as $a$ is a multiple of $2$ in the base condition, $k$ must be a multiple of $2...
1. Select the last occurrence position $P$ of the $i$-th bit in $[l,mid].$, 2. Select the first occurrence position $Q$ of the $i$-th bit in $[mid+1,r].$, Observe: which cells actually change the direction of the pinball placed at position $p$ initially?

Full text and comments »

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

158.
By jeroenodb, 4 years ago, In English
Codeforces Round #869 (Div.1, Div.2) Editorial [problem:1818A]<!-- --> Problem idea: [user:adamant,2023-04-29] <br> Preparation: [user:adamant,2023-04-29] <spoiler summary="Editorial"> [tutorial:1818A]<!-- --> </spoiler> <spoiler summary="Solution"> ~~~~~ void solve() { int n, k; cin >> n >> k; string t[n]; int ans = n; for(int i = 0; i < n; i++) { cin >> t[i]; if(t[i] != t[0]) { ans--; } } cout << ans << "\n"; } ~~~~~ </spoiler> [problem:1818B] Problem idea: [user:adamant,2023-04-29] <br> Preparation: [user:adamant,2023-04-29] <spoiler summary="Editorial"> [tutorial:1818B] </spoiler> <spoiler summary="Solution"> ~~~~~ void solve() { int n; cin >> n; if(n == 1) { cout << 1 << "\n"; } else if(n % 2) { cout << -1 << "\n"; } else { int a[n]; iota(a, a + n, 1); for(int i = 0; i < n; i += 2) { swap(a[i], a[i + 1]); } for(auto ...
to care about the position of the special toy with index $k$. The other toys can be treated as

Full text and comments »

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

159.
By LMydd0225, 14 months ago, In English
Codeforces Round 1052 (Div. 2) Editorial [problem:2146A] <spoiler summary="Hint 1"> Let's focus on the number of occurrences of each element: let $c_i$ be the number of time that element $i$ occurs in the array. To keep a subsequence is to decrease each $c_i$ by a non-negative integer. We need to make all the non-zero elements in $c$ the same while maximizing the sum of $c$. </spoiler> <spoiler summary="Hint 2"> For each integer $x$: suppose the value of all non-zero elements in $c$ is $x$, what is the length of the longest subsequence? <spoiler summary="Answer"> For those $c_i<x$, we decrease it to $0$; for those $c_i\ge x$, we decrease it to $x$. </spoiler> </spoiler> <spoiler summary="Tutorial"> [tutorial:2146A] </spoiler> <spoiler summary="Implementation"> By [user:Caylex,2025-09-21]. ```py def solve(): n = int(input()) ls = list(map(int, input().split())) a = [0] * n for x in ls: a[x - 1] += 1 a = sorted(a) s = sum(a) ans = s for i in ra...
the numbers before the position small than $p_x$?

Full text and comments »

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

160.
By ilyakrasnovv, 4 years ago, translation, In English
Codeforces Round #816 (Div. 2) editorial Hello, Сodeforces! We are very grateful for Your participation in our round. Thanks to [user:Qwerty1232,2022-08-12] for the help with this editorial. [problem:1715A] <spoiler summary="Advice #0"> _Just to it. The testing system is here for the testing. Send your solution._ </spoiler> <spoiler summary="Hint #1"> If $(n; m) \neq (1; 1)$, then: - Stanley should teleport at most once - Megan shouldn't use portals at all </spoiler> <spoiler summary="Hint #2"> Stanley and Megan gonna move only toward their destinations (Stanley will increase $x$ and $y$, Megan will decrease $x$ and increase $y$. </spoiler> <spoiler summary="Hint #3"> Megan can move along one route, which is the same regardless of board size. </spoiler> <spoiler summary="Solution"> ### [problem:1715A] _For convenience let's define going upward as decreasing $x$ coordinate, downward &mdash; increasing $x$, left &mdash; decreasing $y$, right &mdash; increasing y._ One of the optimal...
Consider the next few cases for the relative position of those two portals:

Full text and comments »

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

161.
By minstdfx, history, 5 weeks ago, In English
[Shitpost] How to Teach Kids Basic Data Structures Using the Methods of a Mathematics Textbook ## Conventions This article is based on ordinary set theory. Natural numbers, integers, finite sequences, maps, Cartesian products, total orders, trees, induction, and the finite recursion theorem are assumed to be established. Write $\mathbf N=\{0,1,\ldots\}$ and $\mathbf N_{>0}=\mathbf N\setminus\{0\}$. All trees are finite trees; all intervals not otherwise qualified are integer intervals. For $l,r\in\mathbf Z$, put $$ [l,r]=\{i\in\mathbf Z:l\le i\le r\},\qquad [n]=[1,n]. $$ When $l>r$, $[l,r]=\varnothing$. For a nonempty finite set $E$, $|E|$ denotes its cardinality. The symbol $\sqcup$ denotes disjoint union. Composition of maps follows the convention $(f\circ g)(x)=f(g(x))$. For $n\ge1$, put $$ \lambda(n)=1+\lfloor\log_2 n\rfloor. $$ All asymptotic estimates are taken as $n\to\infty$; bounds written in terms of $\lambda(n)$ also apply to $n=1$. **Computational conventions.** Unless otherwise stated, we use the random-access machine model with word leng...
## §5. General Static Minimum-Position Queries, Since the second components are distinct, the minimum position is unique; it is the leftmost

Full text and comments »

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

162.
By dreamoon_love_AA, 12 years ago, In English
Codeforces Round #292 Editorial Thanks to [user:johnathan79717,2015-03-10] fo polish my words. #### [515-A Drazil and Date](http://codeforces.me/problemset/problem/515/A) If Drazil chooses the shortest path from (0,0) to (a,b), it takes $|a| + |b|$ steps. So we know that all numbers less than $|a| + |b|$ are impossible to be the number of steps that Drazil took. Now consider when the number of steps is not less than $|a| + |b|$. When Drazil arrives at $(a,b)$, he can take two more steps such as $(a,b)$ -> $(a,b+1)$ -> $(a,b)$ to remain at the same position. So we know that for all $s$ such that $s \geq |a| + |b|$ and $(s - (|a| + |b|)) \% 2 = 0$, there exists a way for Drazil to get to $(a,b)$ in exactly $s$ steps. The last part we should prove is that it's impossible for Drazil to arrive at (a,b) in exactly $s$ steps when $(s - (|a| + |b|)) \% 2 = 1$. We can color all positions $(x,y)$ where $(x+y) \% 2 = 0$ as white and color other points as black. After each step, the color of the p...
After each step, the color of the position you're at always changes.

Full text and comments »

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

163.
By cry, 23 months ago, In English
Codeforces Round 998 (Div. 3) Editorial <spoiler summary="Rating Predictions"> | Predictor | A | B | C | D | E | F | G | |--------------------------------------------|------|------|------|------|------|------|------| | [user:Proof_By_QED,2025-01-15] | 800 | 1000 | 1100 | 1300 | 1600 | 1900 | 2400 | | [user:cry,2025-01-15] | 800 | 1000 | 1000 | 1200 | 1700 | 2000 | 2400 | | [user:chromate00,2025-01-15] | 800 | 1000 | 1000 | 1400 | 1700 | 2000 | 2400 | | [user:DivinePunishment,2025-01-15] | 800 | 1200 | 1100 | 1200 | 1700 | 2000 | 2300 | | [user:-firefly-,2025-01-15] | 800 | 1000 | 1000 | 1400 | 1800 | 2000 | 2400 | | [user:Error_Yuan,2025-01-15] | 800 | 1100 | 1200 | 1600 | 1800 | 2100 | 2400 | | [user:macaquedev,2025-01-15] | 800 | 1000 | 1500 | 1400 | 1300 | 2000 | 1900 | | [user:In...

Full text and comments »

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

164.
By Noobish_Monk, history, 10 months ago, In English
Gale-Ryser Theorem _This blog is a submission for the [Third Codeforces Month of Blog Posts](https://codeforces.me/blog/entry/149422), thanks to [user:cadmiumky,2026-02-10] for the initiative!_ _Thanks to [user:TeaTime,2026-02-10] and [user:k1r1t0,2026-02-10] for giving feedback on the post._ --- Hi everyone! I want to talk about Gale-Ryser Theorem and some of its applications. I've provided proofs for each fact in the blog, they're hidden under the spoilers. --- Gale-Ryser Theorem ================== We have an array of $n$ non-negative integers $a_1, a_2, \ldots, a_n$ and an array of $m$ positive integers $b_1, b_2, \ldots, b_m$, $b_i \le n$. The array $b$ describes a sequence of operations, in the $i$-th operation we need to decrease the values at $b_i$ positions by $1$, formally pick $b_i$ unique indices $j_1, j_2, \ldots, j_{b_i}$ and decrease $a_{j_p}$ by $1$ for $1 \le p \le b_i$. We want to know if it's possible to have all $a_i \ge 0$ after the operations. Without loss o...

Full text and comments »

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

165.
By de_sousa, history, 11 months ago, In English
An Imprecision Problem (Small Imprecision Contest Editorial) This is the editorial for my **Small Imprecision Contest** ( https://codeforces.me/gym/106258 ). It is more detailed than regular editorials and is meant to be a standalone blogpost, so it should still be an interesting read even if you didn't participate. This problem has been passed around as a funny concept in some Discord servers, and it was first proposed by [user:pajenegod,2025-12-25] in 2023. This problem doesn't belong in regular competitions, but regardless, I thought it was too cool to not exist, and at the same time, solving it requires some advanced floating point knowledge and intuition; this blogpost is more detailed than usual in an attempt to create a good introduction to these concepts. *With this blogpost I would like to participate in https://codeforces.me/blog/entry/149422 , a cool initiative by [user:ntherner,2025-12-25] that is rewarding interesting Codeforces blogposts. If you have something interesting to share, please give it a read.* I...
So now we have a way of checking whether a position $p$ comes before another position $q$:

Full text and comments »

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

166.
By Vladithur, history, 3 years ago, In English
Codeforces Round #890 (Div. 2) Editorial Hope you liked the problems! [problem:1856A] <spoiler summary="Hints"> <spoiler summary="Hint 1"> How many operations are needed to make $a_i \le a_{i + 1}$ if initially, $a_i > a_{i + 1}$? </spoiler> </spoiler> <spoiler summary="Tutorial"> [tutorial:1856A] </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 char nl = '\n'; typedef long long ll; typedef long double ld; using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { ans = max(ans, a[i]); } } cout << ans << nl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { solve(); ...
Fix some possible index that will be the position of the maximum in the

Full text and comments »

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

167.
By cry, 2 years ago, In English
Codeforces Round 971 (Div. 4) Editorial Thanks for participating! Despite the round being unrated, we hope you've enjoyed the problemset. We put a lot of effort into this round :prayge: I want to give huge thanks to [user:Dominater069,2024-08-28] and [user:satyam343,2024-08-28] for their heavy contributions to the subtasks of G. If you're participating out of competition, we hope you enjoyed attempting these bonus subtasks. Otherwise, we hope you will enjoy upsolving them! [problem:2009A] Problem Credits: [user:cry,2024-08-28] <br> Analysis: [user:cry,2024-08-28] <spoiler summary="Solution "> We choose $c$ between $a$ and $b$ $(a \leq c \leq b)$. The distance is $(c - a) + (b - c) = b - a$. Note that the distance does not depend on the the position $c$ at all. </spoiler> <spoiler summary="Code (Python) (ntarsis30) "> ```py for _ in range(int(input())): a,b = map(int,input().split()) print(b-a) ``` </spoiler> [problem:2009B] Problem Credits: [user:cry,2024-08-28] <br> Analysis: [user:cry...
at position $(x-1) \mod n + 1$. Let $rl$ denote the rotation for $l$ and $rr$ denote the rotation

Full text and comments »

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

168.
By prvocislo, 3 years ago, In English
Editorial for Codeforces Round #945 (Div. 2) We hope you enjoyed the problems! Thank you for your participation! We are really sorry that A and D turned out to be harder than usual. [Problem A](https://codeforces.me/contest/1973/problem/A): idea by [user:prvocislo,2024-05-17] and [user:satyam343,2024-05-17], prepared by [user:prvocislo,2024-05-17] <spoiler summary="Hint 1:"> If someone would claim that the number of draws that happened between the three players are $d_{1, 2}$, $d_{1, 3}$ and $d_{2, 3}$, can you check in $O(1)$ whether this can be true? </spoiler> <spoiler summary="Hint 2:"> The constraints are very small. The number of draws between any two players is at most $30$. </spoiler> <spoiler summary="Hint 3:"> Hint 3: Try all the possibilities for $d_{1, 2}$, $d_{1, 3}$ and $d_{2, 3}$ and find the one with the biggest sum out of all possibilities that could've been the result of game that ended with scores $p_1$, $p_2$ and $p_3$. </spoiler> <spoiler summary="Solution:"> After each round, sum of...

Full text and comments »

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

169.
By maomao90, 5 years ago, In English
Global Round 20 Editorial Hope that everyone enjoyed the round. Feel free to ask questions in the comments if you do not understand any part of the editorial [problem:1672A] Author: [user:errorgorn,2022-04-23] <spoiler summary="Hints"> <spoiler summary="Hint 1"> No matter what move each player does, the result of the game will **always** be the same. </spoiler> <spoiler summary="Hint 2"> Count the number of moves. </spoiler> </spoiler> <spoiler summary="Tutorial"> Let us consider the ending state of the game. It turns out that at the ending state, we will only have logs of $1$ meter. Otherwise, players can make a move. Now, at the ending state of the game, we will have $\sum\limits_{k=1}^n a_k$ logs. And each move we increase the number of logs by exactly $1$. Since we started with $n$ logs, there has been exactly $(\sum\limits_{k=1}^n a_k) - n$ turns. Alternatively, a log of length $a_k$ will be cut $a_k-1$ times, so there will be $\sum\limits_{k=1}^n (a_k-1)$ turns. If the...
- pick index $iposition $i$.

Full text and comments »

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

170.
By henotrix, 15 months ago, In English
Codeforces Round 1045 (Div. 2) Editorial Unfortunately, the round turns out to be very unbalanced :( I'm deeply sorry about this issue. I hope you still enjoy the problems. <spoiler summary="Rate the contest! (definitely not copied from past contests)"> <spoiler summary="Quality"> * 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:2134A] <spoiler summary="Hint 1"> Check the parity of numbers $a$, $b$, and $n$. </spoiler> <spoiler summary="Solution"> Let us first consider the $b$ blue cells. Since all $b$ cells appear in the final painting, for the coloring to be symmetric, they must be placed at the middle of the grid...

Full text and comments »

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

171.
By TheScrasse, 5 years ago, In English
Editorial of Codeforces Round #778 (Div. 1 + Div. 2, based on Technocup 2022 Final Round) [problem:1654A] Author: [user:TheScrasse,2022-02-24]<br> Preparation: [user:TheScrasse,2022-02-19] <spoiler summary="Hint 1"> Suppose you want to choose pieces of cake $i$, $j$. Can you make them adjacent in $1$ move? </spoiler> <spoiler summary="Solution"> The answer is the sum of the $2$ maximum weights. You can always pick the $2$ maximum weights: if they are $a_i$ and $a_j$ ($i < j$), you can flip the subsegment $[i, j-1]$ to make them adjacent. The result can't be larger, because the sum of the weights of any $2$ pieces of cake is never greater than the sum of the $2$ maximum weights. Iterating over all pairs of pieces of cake is enough to get AC, but you can solve the problem in $O(n \log n)$ by sorting the weights and printing the sum of the last $2$ values, or even in $O(n)$ if you calculate the maximum and the second maximum in linear time. Complexity: $O(t \cdot n^2)$, $O(t \cdot n \log n)$ or $O(t \cdot n)$ </spoiler> Official solution: [submissi...

Full text and comments »

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

172.
By emorgan, 6 years ago, In English
[Tutorial] Slight Generalization of Grundy Numbers **Prerequisites**: Grundy numbers (aka nimbers, I will refer to them as Grundy numbers), the connection of Grundy numbers to mex and bitwise xor. **Note about mex**: We know the the mex of a set of non-negative integers is the smallest non-negative integer which is not in the set. This definition works fine for any proper subset of $\mathbb{N}$, since $\text{mex}(S)=\min(\mathbb{N}\setminus S)$, and min is well-defined for any non-empty subset of $\mathbb{N}$. However, the minimum of an empty set is not well-defined, so neither is $\text{mex}(\mathbb{N})$, so we will define a new object $\omega=\text{mex}(\mathbb{N})$. Most of the properties of this object as it relates to mex are pretty straight-forward, for example <br><br> $$ \text{mex}(\mathbb{N}\cup\{\omega\}) = \omega+1 $$ $$ \text{mex}(\{a\omega+b\,|\,a,b\in\mathbb{N}\}) = \omega^2 $$ **Games with Finite States**: Given any finite impartial game (i.e. an impartial game which is guaranteed to terminate in a finite number o...
consider the case $A = [1, x]$, for some $x\in\mathbb{N}$. Alice can move to anyposition $[0, y

Full text and comments »

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

173.
By BrayanD, history, 5 years ago, In English
Editorial of Codeforces Round #768 ### [problem:1631A] Author: [user:humbertoyusta,2022-01-27] <spoiler summary="Hint 1"> Think about how $max(a_1, a_2, ..., a_n, b_1, b_2, ..., b_n)$ will contribute to the answer. </spoiler> <spoiler summary="Hint 2"> The maximum of one array is always $max(a_1, a_2, ..., a_n, b_1, b_2, ..., b_n)$. How should you minimize then? </spoiler> <spoiler summary="Solution"> Let $m_1 = \max(a_1, a_2, ..., a_n, b_1, b_2, ..., b_n)$. The answer will always be $m_1 \cdot m_2$ where $m_2$ is the maximum of the array that does not contain $m_1$. Since $m_1$ is fixed, the problem can be reduced to minimize $m_2$, that is, minimize the maximum of the array that does not contain the global maximum. WLOG assume that the global maximum will be in the array $b$, we can swap elements at each index $x$ such that $a_x > b_x$, ending with $a_i \leq b_i$ for all $i$. It can be shown that the maximum of array $a$ is minimized in this way. Time complexity: $O(n)$ <spoiler ...
of size $x$ that starts at the position of the interval of size $x-y$, and an interval of size $y

Full text and comments »

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

174.
By tibinyte2006, 4 years ago, In English
CodeTON Round 3 (Div. 1 + Div. 2) Editorial [A — Indirect Sort](https://codeforces.me/contest/1750/problem/A) ===== Authors: [user:mejiamejia,2022-10-31], [user:Ecrade_,2022-11-06] <spoiler summary="Solution"> We claim that we can sort the array if and only if $a_1 = 1$. **Necessity** We can notice that index $1$ cannot be affected by any swap operation. Let's see what happens to the value $1$. According to the definition of the operation, it can either increase or be swapped. In order to be increased, there must exist some $k$ such that $1 > a_k$, but since $1$ is the minimum possible value, it will never be true as other values in array $a$ can only increse as well. Since index $1$ can not be affected by a swap operation and $a_1>1$, we conclude that if $a_1 \neq 1$, the answer is **No**. **Sufficiency** Let's focus on the second operation. Since we have $a_1 = 1$, we can always choose $i=1$ and the operation then turns into picking some pair $2 \le j < k \le n$ and swapping $a_j$ with $a_k$. It's t...
permutation, assume the first different position is $k$, if we fix $p_k$, the remaining numbers $a_

Full text and comments »

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

175.
By szdytom, 4 months ago, In English
Codeforces Round 1113 (Div. 2) Editorial [problem:2248A] <spoiler summary="Hint1"> Alice deletes a `0`, Bob deletes a `1`. Which occurrence should each of them choose? </spoiler> <spoiler summary="Hint2"> Deleting a `0` makes the string lexicographically larger. Does the position of that `0` matter? </spoiler> <spoiler summary="Hint3"> After Alice's move, Bob sees one string and deletes a `1`. What is his best move? </spoiler> <spoiler summary="Solution"> Deleting a `0` at an earlier position is always better for Alice. Indeed, compare deleting the `0`s at positions $i < j$: the two results agree before position $i$, and at position $i$ the first result has `1` while the second still has `0`. So Alice deletes the **first** `0`. After that, Bob wants to minimize the string. By the symmetric argument he deletes the **first** `1` of the remaining string, which is the first `1` of the original string, since deleting a `0` never changes the order of the `1`s. Hence the answer is the original string with it...
Deleting a `0` at an earlier position is always better for Alice

Full text and comments »

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

176.
By brunomont, history, 4 years ago, In English
[Tutorial] On Variations of String Matching Hello, Codeforces! Following the recent motivation of writing educational blogs thanks to [user:peltorator,2023-01-14] ([context](https://codeforces.me/blog/entry/110840)), I decided to write another blog on strings, specifically on variations of the very classic String Matching Problem. **Prerequisites** <br> 1. KMP &mdash; [cp-algorithms](https://cp-algorithms.com/string/prefix-function.html) <br> 2. Aho-Corasick &mdash; [cp-algorithms](https://cp-algorithms.com/string/aho_corasick.html) <br> 3. FFT &mdash; [blog](https://codeforces.me/blog/entry/111371) by [user:-is-this-fft-,2023-01-14] Throughout this blog, $n$ will be the size of the text (or sum of sizes of texts, if applicable), and $m$ will be the same for the pattern. Simple Pattern Matching ------------------ **Input**: text $T$, pattern $P$. <br> **Updates**: none. <br> **Query**: in which positions does $P$ occur in $T$? This is just KMP. **Complexity**: $\mathcal O(n + m)$ Multiple Patterns...
$, the number of characters that the pattern matches with the text for every possible startingposition

Full text and comments »

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

177.
By .o., 12 years ago, In English
Good Bye 2014 Editorial First of all, sorry for the late editorial. I was too exhausted and immediately went to bed after the round finished, and didn't write the editorial. There are many pictures in this editorial, to cover up my poor English skills! If you have detected any errors or have questions, feel free to ask questions by comments. Unfortunately, the authors only know English, so we can't answer you if you write comments in Russian. ## [problem:500A] Let's assume that I am in the cell $i$ ($1 \le i \le n$). If $i \le n-1$, I have two choices: to stay at cell $i$, or to go to cell $(i + a_{i})$. If $i = t$, we are at the target cell, so I should print "YES" and terminate. If $i > t$, I cannot go to cell $t$ because I can't use the portal backwards, so one should print "NO" and terminate. Otherwise, I must go to cell $(i + a_{i})$. Using this method, I visit each cell at most once, and there are $n$ cells, so the problem can be solved in linear time. #### What is test 13? There are 9...

Full text and comments »

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

178.
By Serval, history, 4 years ago, In English
Codeforces Round #853 (Div. 2) Editorial ### [problem:1789A] Idea & Preparation: [user:Bazoka13,2023-02-25] <spoiler summary="Tutorial"> Considering an array $a$ of $n$ ($n\geq 2$) positive integers, the following inequality holds for $2\leq i\leq n$: $$ \gcd(a_1,a_2,\cdots,a_i) \leq \gcd(a_1,a_2) \leq 2 $$ Therefore, when the prefix $[a_1,a_2]$ of $a$ is good, we can show that all the prefixes of $a$ whose length is no less than $2$ are good, then $a$ is beautiful. It is obvious that $[a_1, a_2]$ is good when $a$ is beautiful. So we get the conclusion that $a$ is beautiful if and only if the prefix $[a_1, a_2]$ is good. We can check if there exist $a_i, a_j$ ($i\neq j$) such that $\gcd(a_i, a_j)\leq 2$. If so, we can move $a_i,a_j$ to the front of $a$ to make it beautiful, then the answer is `Yes`. If not, the answer is `No`. Time complexity: $O(n^2\log 10^6)$. </spoiler> ### [problem:1789B] Idea & Preparation: [user:Bazoka13,2023-02-25] <spoiler summary="Tutorial"> If $s$ is palindromic initially...

Full text and comments »

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

179.
By Geothermal, history, 7 years ago, In English
Codeforces Round #644 (Div. 3) — Unofficial Solutions Hi all! I'm here to share my solutions to today's Div. 3 round, since I managed to finish the round relatively quickly and thought that my approaches might be of some use to others. Feel free to leave questions in the comments! --- #A &mdash; Minimal Square Without loss of generality, let's say $A \leq B$, that is, $B$ is the larger side-length. We claim that the minimum side length is $\max(2A, B)$, hence, the answer is $\max(2A, B)^2$. This is relatively easy to observe just by looking at the sample cases and trying different configurations, but I'll prove this claim below in case you're curious. To prove this, we first show that $\min(2A, B)$ is a valid side-length. To achieve this, just stack the two rectangles on top of each other, with the two short sides stacking vertically and the long sides overlapping. (This looks much like the solution given in the problem statement for the second test case.) The vertical side-length of the block formed will be $2A$, and...
. It is then clearly impossible to fire a $1$ into this position because if it is fired horizontally

Full text and comments »

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