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

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

Results

1.
By pajenegod, history, 3 years ago, In English
Slowdown bug affecting C++ (64 bit) on Codeforces Yesterday, investigating [Strange TLE by cin using GNU C++20 (64)](https://codeforces.me/blog/entry/126573), I found an easy and reproducable way to trigger a slowdown bug that I believe has been plaguing Codeforces for some time now. So I'm making this blog to raise awarness of it. [user:MikeMirzayanov,2024-03-02], please take a look at this! Here is how to trigger the slowness bug: 1. Take any problem with a relatively large input on Codeforces ($2 \cdot 10^5$ ints is enough). 2. Take a random AC C++ submission that uses `std::cin`. 3. Add the line `vector<vector<int>> TLE(40000, vector<int>(7));` somewhere in global space. 4. Submit using either C++20(64 bit) or C++17(64 bit). 4. ??? 5. TLE For example take [user:Tourist,2024-03-02]'s solution to problem [problem:1936-D]. With the vector of death added to the code, it gets [TLE on TC5](https://codeforces.me/contest/1936/submission/249181295) (taking $> 5$ s). While without the deadly vector, the submission takes [15...
Slowdown bug affecting C++ (64 bit) on Codeforces, **Remark**: I'm no longer to reproduce the issue in [Inconsistent times and TLE withC++17 (64bit, , vector(7));` somewhere in global space. 4. Submit using either C++20(64 bit) orC++17(64 bit, [Inconsistent times and TLE with C++17 (64bit) vs. C++17 ](https://codeforces.me/blog/entry/91474

Full text and comments »

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

2.
By Chilli, history, 7 years ago, In English
How to get actual 64 bit bitsets on Codeforces [Not Recommended] [Don't do this at your job] This blog post brought to you by [user:pajenegod,2020-05-16], [user:Narut,2020-05-16], and the rest of #constant-factor on the AC discord server. If you're interested in discussions like this, feel free to join! For the longest time, CF has constrained us to the tyranny of 32 bit C++. Not only has that slowed down our `long long` operations, it has also constrained us to a measly 32 bit constant factor reduction with bitsets! Let's take 2 pieces of equivalent code. For Loop: ~~~~ int a[MAXN], b[MAXN] for (int it = 0; it < iters; it++) for (int i = 0; i < MAXN; i++) if (a[i] & b[i]) cnt++; ~~~~ Bitset: ~~~~ bitset<MAXN> a, b; int cnt = 0; for (int it = 0; it < iters; it++) cnt += (a | b).count(); ~~~~ On Custom Invocation C++17 (32 bit) for MAXN=1e4 and iters=1e5, this boring for loop code runs in 3594 ms, while the equivalent bitset version runs in 104ms. 3594/104 is approximately 32. Ok, disappointing but makes sense. However, Mike...
How to get actual 64 bit bitsets on Codeforces [Not Recommended] [Don't do this at your job], , what happens if we try our previous benchmark? ~~~~ For Loop (C++17 64 bit): 3736 ms Bitset

Full text and comments »

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

3.
By Fyind, history, 3 years ago, In English
Intersting facts on scanf/cin,cout and segment tree implementation on C++20(64) and C++17(32) Problem: [1864F. Exotic Queries](https://codeforces.me/contest/1864/problem/F) The time limit is 4s. The input size is $n,q \le 10^6$. The standard solution uses a segment tree and the input/output size is very large. The sync of cin,cout with stdio is turned off in all implementations if cin,cout is used. ### Cin,cout vs Fast IO, Scanf on C++20 (64) * [220904724](https://codeforces.me/contest/1864/submission/220904724) Array implementation with cin,cout on C++20 (64) -> TLE * [220952057](https://codeforces.me/contest/1864/submission/220952057) Array implementation with Fast IO on C++20 (64) -> 1762 ms * [220950571](https://codeforces.me/contest/1864/submission/220950571) Array implementation with Scanf on C++20 (64) -> 3181 ms * [220950753](https://codeforces.me/contest/1864/submission/220950753) Pointer implementation with Scanf on C++20 (64) -> 3868 ms * [220947347](https://codeforces.me/contest/1864/submission/220947347) Pointer implementation with cin,cout ...
Intersting facts on scanf/cin,cout and segment tree implementation on C++20(64) andC++17(32), ### C++17 (32) vs C++20 (64), ### Cin,cout vs Fast IO, Scanf on C++20 (64), ) Pointer implementation with Fast IO on C++20 (64) -> 2277ms ### C++17 (32) vs C++20 (64

Full text and comments »

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

4.
By maomao90, history, 4 years ago, In English
Goodbye2022G C++ 64-bit vs 32-bit I was attempting to implement the solution to [problem:1770G] after reading the editorial recently but I kept getting TLE on test case 12. However, after changing the compiler from GNU C++17 to GNU C++17 (64), I got AC in 1185ms, which is very far off from the time limit of 5 seconds. GNU C++17: [submission:188211296] GNU C++17 (64): [submission:188211331] I tried testing it on [user:errorgorn,2023-01-06] solution in the editorial as well and there was the same problem. GNU C++17: [submission:188211673] GNU C++17 (64): [submission:188211705] I thought that it might be because of the NTT implementation that we used ([KACTL](https://github.com/kth-competitive-programming/kactl/blob/main/content/numerical/NumberTheoreticTransform.h)), however, I even tried on [user:Radewoosh,2023-01-06] submission which uses a different NTT implementation, but still faces the same issue. GNU C++17: [submission:188203821] GNU C++20 (64): [submission:187349301] I have seen some ca...
Goodbye2022G C++ 64-bit vs 32-bit, but I kept getting TLE on test case 12. However, after changing the compiler from GNUC++17 to GNU C, the comments. I guess it is about time that I shift from GNU C++17 to GNU C++17 (64) 😢, ++17 (64), I got AC in 1185ms, which is very far off from the time limit of 5 seconds. GNUC++17, GNU C++17 (64): [submission:188211331], GNU C++17 (64): [submission:188211705], GNU C++17: [submission:188203821], GNU C++17: [submission:188211296], GNU C++17: [submission:188211673]

Full text and comments »

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

5.
By lotusblume, 16 months ago, In English
Worst-Case Graphs for Maximum Flow Algorithms Maximum flow algorithms are known to perform significantly better in practice than their worst-case time complexities would suggest. So in this blog, I will present graphs on which the following maximum flow algorithms actually achieve their worst-case running time: | Algorithm | Time Complexity | | ----------------------- | ------------------------------ | | Ford-Fulkerson with DFS | $\mathcal{O}\big(m^2 \cdot U)$ | | Edmonds-Karp | $\mathcal{O}\big(n \cdot m^2\big)$ | | Dinic | $\mathcal{O}\big(n^2 \cdot m\big)$ | | DFS with Scaling | $\mathcal{O}\big(m^2 \cdot \log(U)\big)$ | | Dinic with Scaling | $\mathcal{O}\big(n \cdot m \cdot \log(U)\big)$ | | Most Improving Augmenting Paths | $\mathcal{O}\big(m \cdot \log(U) \cdot (m + n \cdot \log(n))\big)$ | | FIFO Preflow Push | $\mathcal{O}\big(n^3\big)$ | | Highest-Label Preflow Push | $\mathcal{O}\big(n^2 \cdot \sqrt{m}\big)$ | Here and in the rest of this blog: - $n =$ number of vertices, ...
/2707306e7a39351f2e5629c99f16dee44730f43c.svg) ![ ](/predownloaded/64 /a6/64a6405ed5ddcf2ac4cf4f5f39b6f6d83527cd9d.svg) ### Randomized DFS

Full text and comments »

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

6.
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;...
<< 18; int n, k, A, c[M << 1][2], dp[N]; vector> p[N]; void insert(int i, int v

Full text and comments »

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

7.
By awoo, history, 4 years ago, In English
Educational Codeforces Round 143 Editorial [problem:1795A] Idea: [user:BledDest,2023-02-17] <spoiler summary="Tutorial"> [tutorial:1795A] </spoiler> <spoiler summary="Solution (Neon) 1"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { auto ok = [](string s) { for (int i = 1; i < (int)s.size(); ++i) if (s[i - 1] == s[i]) return false; return true; }; int t; cin >> t; while (t--) { int n, m; string s, t; cin >> n >> m >> s >> t; bool f = false; for (int x = 0; x < 2; ++x) { string cs = s, ct = t; for (int i = 0; i < n; ++i) { f |= ok(cs) && ok(ct); ct.push_back(cs.back()); cs.pop_back(); } swap(n, m); swap(s, t); } cout << (f ? "YES\n" : "NO\n"); } } ~~~~~ </spoiler> <spoiler summary="Solution (Neon) 2"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; string ...
[problem:1795A] Idea: [user:BledDest,2023-02-17] [tutorial

Full text and comments »

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

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

Full text and comments »

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

9.
By YouKn0wWho, 4 years ago, In English
[Tutorial] Common Mistakes in Competitive Programming and How to Avoid Them One thing is for sure. You do make mistakes. I also make miskates and that's what makes us human. But what we can surely do is &mdash; to try to minimize the errors that we make throughout our life. I have compiled some of the mistakes that I made in my early Competitive Programming phase. I also mentioned how to avoid them. Also, in most cases, I will give you a chance to find out what the bug is before I reveal the culprit as I tried to make this blog interactive. The codes that I have used in this blog have been written in C++ as it is the most used language for CP. **So, if you are new to CP, stick with me as you might don't wanna repeat the mistakes that I made when I was a beginner.** #### Mistake 1 Check out the following code: <spoiler summary="Code"> ~~~~~ #include<bits/stdc++.h> using namespace std; int main() { int a = 1000'000'000,b = 1000'000'000; long long product = a * b; cout << product << '\n'; return 0; } ~~~~~ </spoiler> The outp...
used in this blog have been written in C++ as it is the most used language for CP. **So, if you are

Full text and comments »

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

10.
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...
/contest/17/problem/D (5) //B^(N-1)*(B-1)%C [B/N are big]

Full text and comments »

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

11.
By Endagorion, 12 years ago, In English
Codeforces Round #295: разбор (теперь с бонусами!) Мы хотели бы также поблагодарить тестеров задач этого раунда и олимпиады ЗКШ: [user:alger95,2015-03-02], [user:thefacetakt,2015-03-02], [user:adamant,2015-03-02], [user:dragonic,2015-03-02], [user:Who179,2015-03-02], [user:ASverdlov,2015-03-02]. Пожалуйста, пишите в комментариях о найденных ошибках. **UPD**: я вспомнил, что забыл написать регулярные бонусные челленджи. Так что вот, пожалуйста. [problem:520A] Идея:[user:Endagorion,2015-03-02] Подготовка:[user:Endagorion,2015-03-02] Чтобы проверить, что все буквы присутствуют, заведем массив длины 26 и для каждой буквы поставим в соответствующую ячейку единичку. В конце надо проверить, что все 26 единичек на месте. Решение работает за $O(n)$. Также надо не забыть перевести все буквы к нижнему регистру (или наоборот, все буквы к верхнему). Чтобы перевести буквы в нижний регистр, можно использовать встроенные функции, например, `tolower` в Python. Также можно пользоваться тем, что буквы от `a` до `z` идут подряд по их ...
$10^17$, что уже помещается в стандартный 64-битный тип в любом языке. **Challenge**: пускай нам, ^17$, which fits in 64-bit integer type in any language. **Challenge**: suppose that you have to

Full text and comments »

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

12.
By newbieToPupil, history, 2 years ago, In English
Speculations on RE / AC Differences in C++17 / C++20 In the recent CFR 950 div3-D, I came across a **Runtime Error Code: -1073741819** when run with **C++17 (GCC 7-32)**, but AC with **C++20 (GCC 13-64)**. After reading several blogs, it hinted me that I'm making an out of bound mistake using pointers, which in fact I was. I was able to fix my code. And got AC from **C++17** as well. Original Code: [264208915](https://codeforces.me/contest/1980/submission/264208915) (C++17) Fixed Code: [264209191](https://codeforces.me/contest/1980/submission/264209191) (C++17) And I made a few speculations: **C++17 (GCC 7-32)** throws a Runtime Error if we are accessing pointers out of last-bound, but **C++20 (GCC 13-64)** just auto-adjusts it to the last-most element. My proofs: ~~~~~ vector<int> v = {4,3,2,5}; v.erase(v.begin() + 10); ~~~~~ Gives Runtime Error in **C++17 (GCC 7-32)**: [264205342](https://codeforces.me/contest/1980/submission/264205342) Doesn't give Runtime Error in **C++20 (GCC 13-64)**: [264214...
Speculations on RE / AC Differences in C++17 / C++20, ++17 (GCC 7-32)**, but AC with **C++20 (GCC 13-64)**. After reading several blogs, it hinted me that

Full text and comments »

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

13.
By balbit, history, 5 years ago, In English
Let's Solve Some More Hard Problems! Inspired by ivan100sic's [problem list blog](https://codeforces.me/blog/entry/98630), I'll pick 10 nontrivial-seeming recent POI (Polish Olympiad in Informatics) problems that I haven't solved and track my progress here. It seems to me that POI is better suited for this format as their editorials are quite difficult to find (if possible [at all](https://szkopul.edu.pl/problemset/problem/v2Y2_UW56ENMcbwP22tkTb7a/site/?key=statement)). While Ivan's original challenge was supposed to last an entire year, I'm not nearly as patient, so I won't look for editorials only until February 1st (in just over 2 weeks). Hopefully I'll have completed at least 80% by that time. Until then, GLHF!!! The List: 1. [Multidrink 2013](https://szkopul.edu.pl/problemset/problem/GyDCbdIgFY5FsMa9iIsBl3hf/site/?key=statement) [Solved Jan 15] <spoiler summary="Fun-ness:"> 5/10 <spoiler summary="Comments"> My thought process on this problem went like "ew this is disgusting implementation" => ...
"> Is there a fast way to find min(A*B, C) where A, B, and C can be 64-bit numbers? I had to resort

Full text and comments »

Tags pow, odz, eni, abh, ai
  • Vote: I like it
  • +149
  • Vote: I do not like it

14.
By satyam343, 3 years ago, In English
Problems that I authored so far Hi everyone! I wanted to write such a blog for a long time. I finally decided to do it after Codeforces Round $934$. I would like to thank [user:Non-origination,2024-03-21], [user:GoatTamer,2024-03-21] and [user:KingRayuga,2024-03-21] for discussing the problems with me. For each problem, I tried to include the some interesting stuff if I could remember. I tried to avoid using spoilers for the problems. So you can look at the comments even if you have not tried the problem. | # | Date | Problem | Difficulty | Contest | Comment |----|-----------|---------------------------------|------------|--------------------------------------|--------------------------------------| | 1 | Aug 2021 | [Tree Distance Sum](https://www.codechef.com/problems/TREEDIST) | Div 2 E | Codechef Starters 10 | My first problem which appeared in some contest. I noticed some nice properties about the dfs traversal and de...
. | | 2 | Oct 2021 | [Equal Beauty](https://www.codechef.com/SNCK1A21/problems/EQBEAUTY)| Div 2C, C | SnackDown 2021 — Online Round 1A| | | 3 | Feb 2022 | [Or Sum](https://www.codechef.com

Full text and comments »

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

15.
By Chef_Ka_Baap, history, 6 years ago, In English
C++17(64) vs C++17 ~~~~~ // #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define lld long double #define w(x) ll x;cin>>x;while(x--) #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound #define iceil(n, x) (((n) + (x) - 1) / (x)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) __detail::__lcm(a,b) #define goog(tno) cout << "Case #" << tno <<": " #define PRESS_F_TO_PAY_RESPECT ios_base::sync_with_stdio(false), cin.tie(nullptr) using namespace std; ll dx[]= {-1,-1,-1,0,0,1,1,1}; ll dy[]= {-1,0,1,-1,1,-1,0,1}; const lld pi=3.1415926535897932384626433832795; const ll INF=1e18; const ll mod=1000000007; const ll maxn=1e5+5; // a^2=2*b+1; // c=b+1; int main(){ PRESS_F_TO_PAY_RESPECT; //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); w(T){ ll n; cin>>n; l...
C++17(64) vs C++17, // a^2=2*b+1; // c=b+1;, /problem/D) Hey there, can anyone tell me why first code got accepted using C++ 17(64) but not with, <=2*n+1;a++){ ll b=((a*a)-1)/2; ll c=b+1; if(a*a+b*b!=c*c, Hey there, can anyone tell me why first code got accepted using C++17(64) but not withC++17 ?

Full text and comments »

  • Vote: I like it
  • -26
  • Vote: I do not like it

16.
By dcclyde, history, 4 years ago, In English
My C++ template, incl. fancy colorized debug printouts My C++ template, incl. fancy colorized debug printouts ================== Use [this template](https://github.com/dcclyde/coding_puzzles/blob/master/templates/template.cpp) and you'll gain 350 rating right away! OK maybe not, but it has a bunch of cool features I built up while climbing from 1800 to 2150 in February-May of this year, and I bet some of them can be helpful to others too. Please, comment with feedback/suggestions/feature requests about how to make the template more useful :) #### Links * [Current template.cpp](https://github.com/dcclyde/coding_puzzles/blob/master/templates/template.cpp) &mdash; includes updates made after this blog was posted. This is the recommended version for most people. * [Minimal version with debug printouts only](https://github.com/dcclyde/coding_puzzles/blob/master/templates/dbg_demo.cpp) &mdash; Stripped-down version that compiles faster while still providing the `dbg()` setup, which is IMO the most novel and cool feature in the template....
My C++ template, incl. fancy colorized debug printouts, */ void solve() { lls(R, C); V dat; rv(R, dat); dbgR(MP(R,C), dat); // I usually

Full text and comments »

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

17.
By dsogari, 2 years ago, In English
Reusable modular integer for C++ (with static/dynamic moduli) <spoiler summary="A little bit about myself"> This is my first blog post on CF, and is probably a good starting topic for someone of my rating. Technically I'm not a CS, but an engineer who worked professionally as a software developer. CP was uncharted territory to me until recently, though now I find myself studying algorithms and working to improve my math skills so I can have fun solving difficult problems. :) </spoiler> So here's what I present: a structure for modular arithmetic operations which is short, reusable across static and dynamic moduli, supports 64-bit moduli and is as efficient as performing the operations manually. It requires the C++17 standard or newer. ### Motivation For the most part, there's obviously nothing novel about this idea: it was inspired by other blog posts ([63903](https://codeforces.me/blog/entry/63903), [23365](https://codeforces.me/blog/entry/23365)), as well as by various submissions to CF problems. On the other hand, I haven't come a...
Reusable modular integer for C++ (with static/dynamic moduli), as efficient as performing the operations manually. It requires the C++17 standard or newer

Full text and comments »

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

18.
By ExplodingFreeze, history, 6 years ago, In English
CF g++17 32 bit vs 64 bit Strange Behvaiour First of all apologies if this is something that has been asked before, my searching ability appears to have failed me then. While using printf with formatting for zero padding on CF (including custom invocation), I encountered this strange behavior: WA &mdash; [submission:109283810] AC &mdash; [submission:109284812] The only difference between these two submissions in the language chosen (32bit vs 64bit C++17). Somehow in the 32-bit version, the second argument is always processed as zero. In the 32-bit C++17 version, splitting the printf into 2 printfs also causes it to get AC &mdash; [submission:109284259] 1. Does CF use a different compiler / environment for 64 bit that could explain this difference in behavior? 2. Is there some undefined behavior in my code that is the source of this inconsistency?
CF g++17 32 bit vs 64 bit Strange Behvaiour, chosen (32bit vs 64bit C++17). Somehow in the 32-bit version, the second argument is always, In the 32-bit C++17 version, splitting the printf into 2 printfs also causes it to get AC &mdash, The only difference between these two submissions in the language chosen (32bit vs 64bitC++17

Full text and comments »

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

19.
By wuhudsm, history, 19 months ago, In English
Code Release for TheForce Round #42 Top 10 Hello, Codeforces. Today, as the main manager of a contest, I have decided to release the code for [TheForce Round # 42](https://codeforces.me/gym/105846) Top 10. The reason for this decision is that during the middle of the contest, we noticed unusual standings: ![ 2025-04-18 000415.png](https://s2.loli.net/2025/04/18/inqucELoWUXfOra.png) As a convention of codeforces, the code of all participants after the contest will be made public. I have decided to do the same thing here, and I believe that if you are a normal and honest participant, it will not infringe upon any of your rights. Also, we are checking the code of the participants and making cautious judgments. The allocation of prizes and the calculation of TheForce Rating will be delayed. Sorry for any inconvenience caused. We sincerely hope to maintain a fair and honest competitive environment for all participants. Integrity is the cornerstone of programming contests, and we believe that upholding these values...
= 2^64 + r (0 <= r < m) // let z = a*b = c*m + d (0 <= c, d < m) // a*b * im = (c*m + d

Full text and comments »

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

20.
By q234rty, history, 6 years ago, In English
Slow scanf/printf for the new 64-bit C++ compiler? **TL;DR Scanf/printf is very slow in the GNU C++17 (64) compiler. Use cin/cout with `ios_base::sync_with_stdio(0);cin.tie(0);` or fastio instead for problems with large io and/or tight TL.** So during [contest:1423] a submission ([submission:94787679]) using scanf/printf by one of my friends got TLE in the contest. After the contest I tried to add fread/fwrite for that submission and got Accepted in 405ms: [submission:94813416]. What surprised me is that the same solution can also get Accepted in 577ms ([submission:94878150]) by using cin/cout with `ios_base::sync_with_stdio(0);cin.tie(0);`. There are blogs testing cin/cout vs scanf/printf in the past, like [this one](/blog/entry/57745). Results in that blog probably still hold for those compilers, however the same experiments on the new 64-bit msys2 G++ 9.2.0 complier seem to yield bizarre results: [submission:94881344] using cin/cout runs in 140ms while [submission:94881282] using scanf/printf runs in 404ms. We had de...
Slow scanf/printf for the new 64-bit C++ compiler?, **TL;DR Scanf/printf is very slow in the GNU C++17 (64) compiler. Use cin/cout with `ios_base

Full text and comments »

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

21.
By wuhudsm, history, 19 months ago, In English
TheForces Round #42 (Ultimate-Answer-Forces) Editorial [A](https://codeforces.me/gym/105846/problem/A) Idea:[user:wuhudsm,2025-01-23] <spoiler summary="solution"> There are $n$ valid $x=n+k(0\le k<n)$. So the answer is $n$. </spoiler> <spoiler summary="code(C++)"> ```cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pii> vpii; typedef vector<vpii> vvpii; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<pdd> vpdd; typedef vector<vd> vvd; #define yn(ans) printf("%s\n", (ans)?"Yes":"No"); #define YN(ans) printf("%s\n", (ans)?"YES":"NO"); template<class T> bool chmax(T &a, T b) { if (a >= b) return false; a = b; return true; } template<class T> bool ch...
/105846/problem/C) Idea:[user:kaosar_the_Joyboy,2025-04-17]

Full text and comments »

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

22.
By Gheal, 4 years ago, In English
Codeforces Round #875 (Div.1 + Div. 2) Editorial [1831A &mdash; Twin Permutations](https://codeforces.me/contest/1831/problem/A) ------------------ Author: [user:Gheal,2023-05-25] <spoiler summary="Hints"> <spoiler summary="Hint 1"> If $a_i+b_i \le a_{i+1}+b_{i+1}$, then $a_i+b_i$ can be equal to $a_{i+1}+b_{i+1}$. </spoiler> <spoiler summary="Hint 2"> Building on the idea from the first hint, can we build a permutation $b$ such that $a_1+b_1=a_2+b_2=\ldots=a_n+b_n$? </spoiler> </spoiler> <spoiler summary="Solution"> Since $a_i+b_i \le a_{i+1}+b_{i+1}$, then $a_i+b_i$ can be equal to $a_{i+1}+b_{i+1}$. Therefore, any permutation $b$ which satisfies $a_1+b_1=a_2+b_2=\ldots=a_n+b_n$ is a valid answer. If $b_i=n+1-a_i$, then: 1. $b$ is a permutation; 2. $a_1+b_1=a_2+b_2=\ldots=a_n+b_n=n+1$ Consequently, $b=[n+1-a_1,n+1-a_2,\ldots,n+1-a_i,\ldots,n+1-a_n]$ is a valid answer. Time complexity per test case : $O(N)$ </spoiler> <spoiler summary="Code (Gheal, C++)"> ~~~~~ #include<bits/stdc++.h>...
case : $O(N)$ ~~~~~ #include

Full text and comments »

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

23.
By wuhudsm, history, 16 months ago, In English
TheForces Round #43 (DIV2-Forces) Editorial Reminder: We welcome you to participate in the official DIV1/DIV2 round scheduled on the 31st! [A](https://codeforces.me/gym/106014/problem/A) Idea:[user:tamzid1,2025-07-25] <spoiler summary="solution"> We can see if $x$ is a perfect square, $x^x$, $x^{(x^x)}$, $\ldots$ are also perfect square. Proof: assume $x=y^2$, $x^z=(y^z) \cdot (y^z)$. So the answer is the number of perfect squares not greater than $n$. There are exactly $\lfloor \sqrt{n} \rfloor$ integers $x$ (with $1 \leq x \leq n$) such that $x$ is a mystic number. </spoiler> <spoiler summary="code(C++)"> ```cpp #include <iostream> #include <cmath> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; cout << static_cast<int>(sqrt(n)) << '\n'; } return 0; } ``` </spoiler> <spoiler summary="Rate the Problem"> Amazing problem: Goo...
$1 \leq x \leq n$) such that $x$ is a mystic number.

Full text and comments »

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

24.
By Codeforcer, history, 6 years ago, In English
Getting TLE'd with O(nlogn) (2-sec) I cannot figure out why this code is getting TLE'd despite of everything being under order and constraint. I knew those mod operations were costly so I optimized them but still no luck. Problem : https://codeforces.me/contest/1466/problem/E <spoiler summary="Code"> ~~~~~ //Think simple yet elegant. #include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define all(v) v.begin(),v.end() #define F first #define S second #define pb push_back #define mp make_pair #define pi pair<int,int> #define REP(i,n) for(int i=0;i<n;i++) const int N = 3e4+10; const ll mod = 1e9+7; const int BLOCK_SIZE = 200; ll mul(ll a,ll b){ if(a>=mod) a%=mod; if(b>=mod) b%=mod; ll xt = a*b; if(xt>=mod) return (xt)%mod; return (xt); } ll add(ll a,ll b){ if((a+b)>=mod) return (a+b)%mod; return (a+b); } void run_case(){ ll n,i,j,k; //<i,j> -> {<j,1>+<j,2>+<j,3>,...............,...
(); } } ~~~~~ GNU C++17(64 bit) -> 453 ms GNU C++17 ->1263 ms

Full text and comments »

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

25.
By Paras_ydv, history, 4 weeks ago, In English
bits/stdc++.h, pb_ds and rope on macOS with one command Hi everyone, I do CP on a MacBook, and the first thing every Mac user hits is this: ``` main.cpp:1:10: fatal error: 'bits/stdc++.h' file not found ``` because `g++` on macOS is actually clang. I used to copy stdc++.h into the Xcode folder, but it got wiped every time Xcode updated, and pb_ds / rope still didn't work. Installing gcc from brew also works, but then you type `g++-15` everywhere and the editor keeps using clang anyway. So I made a small tool for it, cp-mac: ``` brew install paras-ydv/cp/cp-mac cp-mac link # only on apple silicon, once ``` or `curl -fsSL https://raw.githubusercontent.com/Paras-ydv/cp-mac/main/install.sh | sh` if you don't use brew. ![cp-mac-demo](https://raw.githubusercontent.com/Paras-ydv/cp-mac/main/docs/demo.gif) After that, a normal `g++ a.cpp` (and VS Code etc.) compiles stuff like this: ```cpp #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace st...
`, `__lg`, `random_shuffle`, `bind2nd` etc. in c++17 and later - `-D_GLIBCXX_DEBUG` actually does

Full text and comments »

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

26.
By SPyofgame, history, 6 years ago, In English
Counting such number whose digit product multiple to itself smaller than given number ### The problem Lets $f(x) = $ product of digits of $x$. Example: $f(123) = 1 * 2 * 3 = 6$, $f(990) = 9 * 9 * 0 = 0$, $f(1) = 1$ The statement is, given such limitation $N$, count the number of positive $x$ that $1 \leq x * f(x) \leq N$ Example: For $N = 20$, there are 5 valid numbers $1, 2, 3, 4, 11$ ------- ------- ### The limitation - Subtask 1: $N \leq 10^6$ - Subtask 2: $N \leq 10^{10}$ - Subtask 3: $N \leq 10^{14}$ - Subtask 4: $N \leq 10^{18}$ ------- ------- ### My approach for subtask 1 - If $(x > N)$ or $(f(x) > N)$ then $(x * f(x) > N)$. So we will only care about $x \leq N$ that $x * f(x) \leq N$ <spoiler summary="Calculating x * f(x) - O(log10(x))"> ```cpp ll cal(ll x, ll lim) { ll res = x; do { int t = x % 10; if (res > lim / t) return -1; /// (x * f(x) > N) res *= t; } while (x /= 10); return res; } ``` </spoiler> <spoiler summary="Counting - O(n log10(n))"> ```cpp ll brute(l...
$v$ ($v \in \mathbb{N}, 0 \leq v \leq 9$) $\rightarrow \exists\ a, b, c, d \in \mathbb{N} \rightarrow

Full text and comments »

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

27.
By physics0523, history, 3 years ago, In English
TheForces Round #26 Editorial [problem:104802A] Writer: [user:wuhudsm,2023-11-14] <spoiler summary="Editorial"> We use two pointers to solve this problem. Set $l=1$ and $r=n$ initially. - If $a_l=a_r$, <code>l++,r--;</code> - If $a_l<a_r$,split $a_r$ into $a_r-a_l$ and $a_l$, <code>r--;</code> - If $a_l>a_r$,split $a_l$ into $a_r$ and $a_l-a_r$, <code>l++;</code> When $l \geq r$,the process ends. </spoiler> <spoiler summary="Rate the problem"> Good problem! : Average problem : Bad problem... : </spoiler> [problem:104802B] Writer: [user:pavlekn,2023-11-14] <spoiler summary="Editorial"> Let $M$ be the initial mass of the bus with all passengers: $M = w + \sum_{i = 1}^{n}{m_i}$. Let $F$ be the total force of the pushers, initially, $F=0$. Imagine getting out the $i$-th passenger out of the bus, then $M$ is decreased by $m_i$, while $F$ is increased by $f_i$. Hence, $M - F$ is decreased by $m_i + f_i$. Clearly, we want to make ...
))/8)); for(long long c=1;;c++){ auto f = [&](long long v){ return (mulmn(v,v ,n)+c)%n

Full text and comments »

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

28.
By jay_jayjay, history, 4 years ago, In English
Indigo Contest 2023 Unofficial Editorial As the official editorial is promised to come out later, I will write an unofficial editorial for now. Some of the solutions are from my teammate [user:tcmmichaelb139,2023-04-17] orz. Contest: https://www.hackerrank.com/indigo-coding-competition ## Easy These problems are quite trivial, so I will only provide solutions: <spoiler summary="P1"> ~~~~~ n=int(input()) arr=[] for i in range(n):arr.append(input().strip().replace('x','')) for i in range(n): cnt=arr[i].count('y') arr[i]=arr[i].replace('y','') arr[i]+=cnt*'y' arr=sorted(arr,key=lambda x:(-len(x),x)) print('\n'.join(arr)) ~~~~~ </spoiler> <spoiler summary="P2"> Michael's solution: ~~~~~ #include "bits/stdc++.h" using namespace std; string pi = "31415926535897932384626433832... (truncated copy-paste from internet)"; void solve() { string s; cin >> s; for (int i = 0; i < s.length(); i++) if (s[i] != pi[i]) { cout << i << '\n'; r...
64;case 14: return 65;case 15: return 66;case 16: return 68;case 17: return 72;case 18: return 73

Full text and comments »

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

29.
By Siyah, history, 12 months ago, In English
Euler to AVX: Hi, I'm AmirMohammad (commonly known as **Danet**). I was inspired to write this article after completing my Calculus 1 course to bridge the gap between theory and implementation. Naturally, as a non-native speaker, the translation and editing process involved some assistance. If you spot any technical or linguistic errors, I would be grateful if you pointed them out! ## 1. Mathematical Foundations and Definitions The trigonometric and hyperbolic function families are intrinsically linked through complex analysis, specifically via Euler's formula: $$ e^{ix} = \cos x + i \sin x $$ ### 1.1 Trigonometric Functions (Circular Functions) These functions are defined geometrically based on a point $(x, y)$ on a unit circle of radius 1, where the angle subtended at the origin is $\theta$ (or $x$ radians): $$ \begin{align} \sin x &= y \\ \cos x &= x \\ \tan x &= \frac{\sin x}{\cos x} = \frac{y}{x} \\ \csc x &= \frac{1}{\sin x} \\ \sec x &= \frac{1}{\cos x} \\ \cot x...
essential. **SIMD-parallel sine computation using C++17 Parallel STL:** ``` #include

Full text and comments »

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

30.
By DanTheMan., 18 months ago, In English
mBIT 2025 Editorial Thank you to everyone who competed in mBIT 2025! It was a record breaking year for us with 84 in-person participants and 135 online participants. We hoped you guys enjoyed it as much as we did. We tried hard to make the problems fun and interesting for as wide of a skill gap as possible. In fact, this year's competition had an in-person team of middle schoolers that was unfamiliar with for loops, and an online team with all three participants in the top 15 in the world in codeforces. We are glad to contribute to all niches of the computer science community: beginner and advanced, local and global. Thank you all for your enthusiasm. Congratulations to the winners: **Online Advanced:** - 1st place &mdash; HoMaMaOvo &mdash; Masaki Nishimoto, Riku Kawasaki, Yui Hosaka - 2nd place &mdash; mathforcesbox &mdash; Brian Xue, Bing-Dong Liu, Alex Chen - 3rd place &mdash; bluepuppygreenturtle &mdash; Rain Jiang, Kai Jiang **Online Intermediate:** - 1st place &mdash; NULP Lega...
<< in C++. Look at your programming language's documentation to figure out how to print to standard

Full text and comments »

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

31.
By EvenImage, 4 years ago, In English
Problems that I authored so far Since competitive programming is dying, and I'm almost retired, so it's time to review the problems I authored. Hi everyone! I wanted to write such a blog for a long time, motivated by similar blogs, [by](https://codeforces.me/blog/entry/113093) [user:antontrygubO_o,2023-02-25], [by](https://codeforces.me/blog/entry/108940) [user:adamant,2023-02-25] and [by](https://codeforces.me/blog/entry/108595) [user:tibinyte,2023-02-25]. This is not a super-comprehensive list. I set many shit problems that I don't want to share for some local contests. It can be long, and I'm not sure if I have finished half of them yet. The number of asterisks after the label indicates the recommendation levels. One asterisk means this problem is worth reading. Two asterisks mean this problem is one of my favorite problems, Three asterisks mean this problem is one of my best problems. | # | Date | Problem | Contest | Comment | | ---- | ----------- | --------------------------------------------...
| [Hack it!](https://codeforces.me/contest/468/problem/C) | Codeforces Round #268 | It has an, ://codeforces.com/contest/468/problem/C) | Codeforces Round #268 | It has an unexpected beautiful

Full text and comments »

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

32.
By xug, 2 years ago, In English
TeamsCode Summer 2024 Contest Editorial The [TeamsCode Summer 2024 Virtual Programming Contest](https://codeforces.me/blog/entry/131526) was held on Sunday, July 28. The problems were written and prepared by [user:Yam,2024-07-14], [user:hyforces,2024-07-14], [user:oursaco,2024-01-20], [user:willy108,2024-07-14], [user:jay_jayjay,2024-07-14], [user:HaccerKat,2024-07-14], [user:xug,2024-07-14], [user:yash_9a3b,2024-07-14], [user:Red0,2024-07-16], and [user:superhelen,2024-07-16]. The problems (with problem credits) can be found in the [Novice Gym](https://codeforces.me/gym/105283) and [Advanced Gym](https://codeforces.me/gym/105284). [user:lunchbox,2024-08-02] solved all the problems during testing and provided valuable feedback. [Novice A /](https://codeforces.me/gym/105283/problem/A)[ Advanced A: P!=NP](https://codeforces.me/gym/105284/problem/A) === <spoiler summary = "Hint"> Try simplifying the equations by dividing by $p$, then think about which values of $p$ would produce a valid value of $n$. </spoiler> ...
solve() { ll a, b, c, n; cin >> a >> b >> c >> n; vector v; ll x = 1

Full text and comments »

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

33.
By imtiaj.zero, history, 4 years ago, In English
GNU C++17 vs GNU C++20 (64) When I submitted the following code in GNU C++20 (64) I got wrong on test 2, whereas in GNU C++17 it got Accepted. Would anyone please tell the reason behind this. Thanks in advance. ~~~~~ Problem Link: ~~~~~ [problem:1809B] ~~~~~ My submission link: ~~~~~ [submission:198895642] in GNU C++20 (64) lang. [submission:198895850] in GNU C++17 lang.
GNU C++17 vs GNU C++20 (64), When I submitted the following code in GNU C++20 (64) I got wrong on test 2, whereas in GNUC++17, [submission:198895850] in GNU C++17 lang., ~~~~~ My submission link: ~~~~~ [submission:198895642] in GNU C++20 (64) lang.

Full text and comments »

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

34.
By LNight121, history, 15 hours ago, In English
Codeforces Round 1136 (Div. 1, Div. 2) Editorial Thanks to everyone who participated in this round! I hope you enjoyed the problems! Apologies for the overly simplistic Div2D and the trivial Div1D(and the statements with poor readability). I think that the whole difficulty of Div1D lies in how people hack the solutions of other participants: if nobody hacks, this problem is easier than Div1C, but if somebody hacks, it becomes hard. I will explain this in more detail in the tutorial below. ### [problem:2288A] <spoiler summary="Hint 1"> The last operation can only be an Attack. </spoiler> <spoiler summary="Hint 2"> You can only Charge several times first and then Attack several times. </spoiler> <spoiler summary="Tutorial"> If your sequence of operations contains a segment [Attack, several Charges, several Attacks], move the leading Attack behind those Charges. The total damage cannot decrease. Therefore we may assume that all Attacks are performed after all Charges. Then you can enumerate how many Charges are perfo...
*m) + d*im = c*2^64 + c*r + d*im // c*r + d*im < m * m + m * im < m * m + 2^64 + m

Full text and comments »

  • Vote: I like it
  • -60
  • Vote: I do not like it

35.
By zxy0909, 4 years ago, In English
DAIICT IPC-1 2022 EDITORIAL #### **Contest Link: [DAIICT IPC-1 2022](https://codeforces.me/contestInvitation/b83fa9704c156aa82d1578273fcaa534eef71e8e)** **About Intra DA Programming Contest (IPC):** These are the short duration contests of 2.5 hours durations with 6-7 problems. The aim of these contests is to create a healthy and competitive environment of coding in the college(DAIICT), increase the problem solving skills and DSA knowledge. #####[Q-1 Alice Vs. Bob](https://codeforces.me/gym/396222/problem/A) <spoiler summary = "Hint"> Manage two variables, one with score of $1^{st}$ player and other with score of $2^{nd}$ player. Traverse the string and if one among two reaches to 11 break the loop and check who is the winner! </spoiler> <spoiler summary = "Codes"> Author: [user:kunalHS,2022-09-07] <spoiler summary = "Author's Code"> ~~~~~ #include <bits/stdc++.h> using namespace std; #define fo(i, n) for (int i = 0; i < n; i++) #define count(n) for (int i = 1; i <= n; i++) #define l...
]; #define pb push_back #define mk make_pair #define all(v) v.begin(),v.end() #define dis(v) for(auto

Full text and comments »

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

36.
By primeprogrammer2021, 4 years ago, In English
GNU C++20 (64) vs GNU C++17 I got TLE with GNU C++20 (64) : [submission:158299729] And AC with GNU C++17 : [submission:158299827] You can check that both the submissions are exactly same. Also, I custom tested [submission:158299729] and found out that it is taking 3 seconds. Can anyone tell the main difference between these two versions?
GNU C++20 (64) vs GNU C++17, And AC with GNU C++17 : [submission:158299827], I got TLE with GNU C++20 (64) : [submission:158299729]

Full text and comments »

37.
By Z0RR0, history, 8 years ago, In English
Codeforces Popularity Ranking Hello Codeforces! There has been several blogs similar to this. I know about [TOP 15 most popular users on codeforces](http://codeforces.me/blog/entry/49122) and [Who is the most popular?](http://codeforces.me/blog/entry/21041). But as none of these are updated, I thought this might be helpful. I have just calculated the most popular handles in Codeforces. I only considered those handles which have at least one rated contest. Begging my pardon to them who hasn't participated in any rated round. And here, the popularity depends simply on the number of people you are friend of. The complete standings can be found [here](https://docs.google.com/spreadsheets/d/1ADlF-bd6pBYCap75yzf-pUnVwI9f9YmPkiYNW3lD-xo/edit?usp=sharing)(This may took a while to load at the bottom). Anyway here is Top 200 handles. | Rank | Handle | Follower | |---|---|---| 1. | [user:tourist,2018-08-22] | 14082 | 2. | [user:Petr,2018-08-22] | 6430 | 3. | [user:OO0OOO00O0OOO0O00OOO0OO,2018-08-22] | 420...
. | [user:Endagorion,2018-08-22] | 1495 | 16. | [user:dragoon,2018-08-22] | 1470 |17. | [user:uwi,2018-08-22, ] | 1495 | 16. | [user:dragoon,2018-08-22] | 1470 | 17. | [user:uwi,2018-08-22] | 1446 | 18

Full text and comments »

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

38.
By FazeCT, history, 4 years ago, In English
266 Coding Cup Editorial Link to the contest: https://codeforces.me/contests/397164 (Problems are at 1300- difficulty). **A. Another Sanity Check, Why Not?** Idea: [user:FazeCT,2022-09-17] <spoiler summary="Tutorial"> First, you have to check if $n$ is in one of the following $3$ ranges: $48 \le n \le 57$, $65 \le n \le 90$, $97 \le n \le 122$. If **no**, then output "Lmao". Else, use **char()** to output the character associated with the number $n$. </spoiler> <spoiler summary="Solution"> ~~~~~ #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; if(n<48 || (n>57 && n<65) || (n>90 && n<97) || n>122) cout << "Lmao" << endl; else cout << char(n) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solve(); } ~~~~~ </spoiler> **B. Seghhhhhhhhh** Idea: [user:junvalentine,2022-09-17] <spoiler summary="Tutorial"> If the length of the given string s is odd, then the answer is $NO$, since adding two strings...
). **A. Another Sanity Check, Why Not?** Idea: [user:FazeCT,2022-09-17]

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

39.
By Safin17, history, 17 months ago, In English
Issues with m1/m2/m3.codeforces.com During Today’s Contest (Site Freeze & Missing Statements) In today’s Codeforces contest, the website was frozen and not working properly during the first 5 minutes. Also, the subdomains `m3.codeforces.com` and `m1.codeforces.com` were not displaying the problem statements &mdash; it was showing “The statement is not available” About 5 minutes after the contest started, I was finally able to access the statements from the main website and began the contest. Even after around 60 minutes, the `m1` and `m3` subdomains were still not working. (I didn’t check `m2` by then.) The main website also seemed slow during problem submission. When I submitted the file for Problem A, it kept loading without showing the status page. I panicked and foolishly, even though `m3` wasn’t showing the problem statement , I pasted the same code and submitted it again through `m3`. But on `m3`, the submission page was saying "No Data." After a few minutes, the main site refreshed and I saw two submissions with exactly the same code, but with different...
different languages: - **C++23 (GCC 14-64, msys2)** — submitted via `m3` - **C ++17 (GCC 7-32

Full text and comments »

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

40.
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 ...
possible to do. At this point, the top teams were close to being done with the 5 easiest problems, andC

Full text and comments »

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

41.
By SnowLucario_Z, history, 4 years ago, In English
A Recap of My First Year in CodeForces Hello all on Codeforces! ------------------ It’s been just over a full year since I created my Codeforces account. Since then a lot has happened on my Codeforces journey so far. With everything that’s happened I want to look back at how I got to my current point, share what I learned in the process, recap some of my best moments, and laugh at whatever I was thinking on a few of these contests, because a lot happened. The only issue is that there’s no way I’m going to detail all **60** contests I took part in 2022. Instead I’ve chosen to “award” the 9 most memorable contests, wheter it be because I did exceedingly well or self destructed in almost hilarious fashion. A few notes before I begin: No full solutions for any problems are shown in this post but there are code snippets and discussions that are spoilers for these problems. I apologize in advance. ### First Contest &mdash; [Hello 2022](https://codeforces.me/contest/1621) This was the first contest held in 2022, ...
Problems A and B with Problem C being inconsistent and Problem D being well out of my current

Full text and comments »

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

42.
By eulmelk, 12 months ago, In English
National Competitive Programming Challenge — Editorial Here is the link to the contest: [Link](https://codeforces.me/contestInvitation/6071a436743e70518e953453aadcf924bca069aa) ### [A. The Blacksmith](https://codeforces.me/gym/656191/problem/A) <spoiler summary="Credits"> - **Problem Idea**: [user:eulmelk,2025-12-12] - **Problem Setter**: [user:eulmelk,2025-12-12] </spoiler> <spoiler summary="Rate the Problem"> - **How good is this problem?** - Very Good - Good - Bad - Very Bad - **How hard is this problem?** - Very Easy - Easy - Hard - Very Hard </spoiler> #### Approach 1 <spoiler summary="Tutorial"> **Step 1**<br> $n \le 500$, so the total number of pairs is at most $\frac{n(n-1)}{2} = \frac{500 \cdot 499}{2} = 124750$. This is easily manageable within time limits. **Step 2**<br> By checking every possible pair, we never miss any valid combination. Therefore, keeping the maximum among all va...
is, the maximum path sum) is the answer.

Full text and comments »

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

43.
By TsReaper, 23 months ago, In English
Problems that I Authored So Far Hi everyone! As we're reaching the end of this year and as AI becomes smarter, I'd like to write such a blog, motivated by similar blogs [by](https://codeforces.me/blog/entry/108940) [user:adamant,2024-12-22], [by](https://codeforces.me/blog/entry/108595) [user:tibinyte,2024-12-22], [by](https://codeforces.me/blog/entry/113093) [user:antontrygubO_o,2024-12-22], [by](https://codeforces.me/blog/entry/113720) [user:wuhudsm,2024-12-22], [by](https://codeforces.me/blog/entry/113687) [user:xiaowuc1,2024-12-23], [by](https://codeforces.me/blog/entry/113213) [user:jqdai0815,2024-12-23], [by](https://codeforces.me/blog/entry/118825) [user:TheScrasse,2024-12-23] and [by](https://codeforces.me/blog/entry/127391) [user:satyam343,2024-12-22]. I am a member of the [SUA Programming Contest Problem Setter Team](https://sua.ac), so most of the problems I authored are for the onsite contests prepared by our team. I would like to thank all our team members for discussing the problems with me, ...
Castle 2](https://codeforces.me/gym/105386/problem/C) | 2024 ICPC Kunming Invitational | 2600

Full text and comments »

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

44.
By jmichael, history, 3 years ago, In English
Four nested loops not enough for TLE??? Why isn't there TLE? ================== I was solving the D problem of the previous contest Div2.907 <br> I used binary search, but it needed ridiculous optimizations before it got accepted, and even then, it was a close call. <br> I played around for a while trying to make it even closer. <br> After all a while, I noticed.... <br> That, codeforces forgot what TLE is. As far as I can make out, this is a supreme example of machine learning that in the future, should be of great service to all competitive programmers worldwide. I made a last attempt at manufacturing a TLE, unfortunately, I failed to get it. It was very disappointing for me. As a competitive programmer, I thought that though I couldn't get AC all the time, at least I could get TLE, if I wanted. Apparently, even this is beyond my ability. <spoiler summary="My Entire Program"> ```c++ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL_MACHINE template <class K, class V> ostream& o...
, even this is beyond my ability. ```c++ #include

Full text and comments »

Tags tle
  • Vote: I like it
  • +10
  • Vote: I do not like it

45.
By alex_rider123, 7 months ago, In English
Freshers' CodeNite 2026 Hello everyone! Thanks for participating in the contest! Link to access the contest: [Freshers' CodeNite 2026](https://codeforces.me/contestInvitation/aa6ac1740a448d12475ec188f62b8321d4499580) Below are the hints and solutions for all the problems. --- ### [Illu Hopping](https://codeforces.me/gym/683650/problem/A) **Author:** [user:rakshit_ranka,2026-04-11] <spoiler summary="Hint"> Try to write out the pattern for small values of n and k and observe when you get stuck in invalid cycles. What are the gaps between the numbers in the invalid cycles? </spoiler> <spoiler summary="Tutorial"> There are 2 valid approaches to the problem under the given constraints. **Approach 1:** You may simulate the process of jumping and mark the visited halls using an array or set. When you reach a hall already visited check if the number of halls visited is n. **Approach 2:** This problem is a classic application of modular arithmetic. It is a known mathematical property that...
exceeds the limit of a 32-bit integer. You must use 64-bit integers (`long long` inC++) for your running

Full text and comments »

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

46.
By catalystgma, history, 2 years ago, In English
Exponential Length Substrings in Pattern Matching Hi all, I would like to share with you a part of my undergraduate thesis on a Multi-String Pattern Matcher data structure. In my opinion, it's easy to understand and hard to implement correctly and efficiently. It's (relatively) competitive against other MSPM data structures (Aho-Corasick, suffix array/automaton/tree to name a few) when the dictionary size is specifically (uncommonly) large. I would also like to sign up this entry to [user:bashkort,2024-10-04]'s [Month of Blog Posts](https://codeforces.me/blog/entry/133806):-) Many thanks to him and peltorator for supporting this initiative. #### Abstract This work describes a hash-based mass-searching algorithm, finding (count, location of first match) entries from a dictionary against a string $s$ of length $n$. The presented implementation makes use of all substrings of $s$ whose lengths are powers of $2$ to construct an offline algorithm that can, in some cases, reach a complexity of $O(n \log^2n)$ even if there are $O...
with A, B, C, D, ...} **Property 6:** Let $1 \leq x = 2^{x_1} + .. + 2^{x_{last}} < y = x + 2

Full text and comments »

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

47.
By eulmelk, 6 months ago, In English
Code League — National Competitive Programming Contest — Round 2 — Editorial Here is the link to the contest: [Link](https://codeforces.me/contestInvitation/f528fcc29732183e36f82a0adfdc6dbac0743f3f) ### [A. Free Coupon](https://codeforces.me/gym/690685/problem/A) <spoiler summary="Rate the Problem"> - **How good is this problem?** - Very Good - Good - Bad - Very Bad - **How hard is this problem?** - Very Easy - Easy - Hard - Very Hard </spoiler> <spoiler summary="Hint"> Which items should be taken using coupons? <spoiler summary="Answer"> Since a coupon can be used on any item regardless of its price, it is always best to use coupons on the most expensive items. This allows us to spend our coins only on cheaper items. </spoiler> </spoiler> <spoiler summary="Solution"> The problem asks us to find the maximum number of items Abenezer can obtain given $k$ coins, with the offer that every $b$ items bought with coins yiel...
= map(int, input().split()) c = list(map(int, input().split())) c.sort() x = 0

Full text and comments »

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

48.
By skywalkert, history, 7 years ago, In English
2018 CMUT BeihangU Contest, Editorial This editorial corresponds to [contest:102114] (stage 5), which was held on Aug 6th, 2018. Moreover, this problem set was also used as Jingzhe Tang Contest 1 in Petrozavodsk Winter Camp on Jan 30th, 2019. **This post is now finished**, in which I try to elaborate on notes, solutions and maybe some data generating. Alternatively, you can refer to [an old published material](https://drive.google.com/file/d/1CFumWbNLTUEywkVDNF-LKT3SzYd1r15L/view), though I think the old English version did not explain something clearly. --- [problem:102114A] This problem requires to calculate $s$-$t$ min cut between any two vertices on a weighted cactus graph having $n$ vertices, denoted by $\mathrm{flow}(s, t)$. You need to report $\sum_{s < t}{(s \oplus t \oplus \mathrm{flow}(s, t))}$. $n \leq 10^5$, $\sum{n} \leq 10^6$, weights are $\leq 10^9$. Try to find some features of this graph. <spoiler summary="solution"> By contradiction, we can prove that for an undirected graph, each ed...
) \leq 6$ when $n \leq 10^5$, because $2 \times 3 \times 5 \times 7 \times 11 \times 13 \times17

Full text and comments »

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

49.
By SPyofcode, history, 5 years ago, In English
[Tutorial] An interesting counting problem related to square product ## The statement: Given three integers $n, k, p$, $(1 \leq k \leq n < p)$. Count the number of array $a[]$ of size $k$ that satisfied - $1 \leq a_1 < a_2 < \dots < a_k \leq n$ - $a_i \times a_j$ is perfect square $\forall 1 \leq i < j \leq k$ Since the number can be big, output it under modulo $p$. For convenient, you can assume $p$ is a large constant prime $10^9 + 7$ **Notice that in this blog, we will solve in $O(n)$ for general $k$ from the original task** **For harder variants you can see in this blog [[Variants] An interesting counting problem related to square product](https://codeforces.cc/blog/entry/96498)** ## Solution for k = 1 The answer just simply be $n$ ## Solution for k = 2 #### Problem Given $n (1 \leq n \leq 10^6)$, count the number of pair $(a, b)$ that satisfied - $1 \leq a < b \leq n$ - $a \ti...
represent $x = u \times p^2$ and $y = v \times q^2$ (still, minimum $u$, $v$ ofcourse). We can

Full text and comments »

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

50.
By Sammarize, 15 years ago, In Russian
Codeforces Round 110 — Разбор задач A (Div2) Результат игры ------------------ В этой игре можно было просто сделать, то, что просят в условии.А именно, завести счётчик, перебрать все клетки поля, и для каждой клетки найти сумму чисел в клетках, стоящих с ней на одной горизонтали, сумму чисел в клетках, стоящих с ней на одной вертикали, и сравнить эти суммы. Если сумма по вертикали больше, увеличить счётчик на один. После того, как перебраны все клетки, вывести счётчик. Максимальная сумма может быть $2 \times 30 \times 100 = 6\,000$, поэтому для её достаточно типа _int_. B (Div2) След ------------------ Извиняюсь за кривой Давайте для начала отсортируем радиусы окружностей по убыванию. Пусть у нас теперь радиус первой окружности --- $r_1$, второй окружности --- $r_2$, ..., последней окружности --- $r_n$, где $r_1 > r_2 > \ldots > r_n$. Внешняя область --- так, которая снаружи первой окружности --- покрашена в синий цвет, значит, область между первой и второй окружностью покрашена в красный. Далее, область ме...
нечётный номер, и квадрат её радиуса надо тоже прибавить к сумме. A (Div1) --- C (Div2) Сообщение

Full text and comments »

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

51.
By Ilya_Is2022, 3 years ago, translation, In English
Разбор задач SRound #1 Барабанная дробь и разбор готов! (⁠✷⁠‿⁠✷⁠) [SRound #1](https://codeforces.me/contestInvitation/1e1101b5bd6369e8a377b6efce1e6a8ea10bdbf0) ------------------------------------------ ### [problem:447021A] - Идея: [user:Ilya_Is2022,2023-06-08] - Разработка: [user:Ilya_Is2022,2023-06-08] <spoiler summary="Разбор"> Для решения данной задачи достаточно было проверять введённый пинг на принадлежность к 4 числовым отрезкам, а именно: - Если $n \in [0, 21)$, то выводить _amazing!_. - Иначе если $n \in [21,\ 51)$, то выводить _good!_. - Иначе если $n \in [51,\ 151)$, то выводить _bad!_. - В противном случае $n \in [51,\ 1001)$, тогда нужно вывести _very bad!_. Итоговая асимптотика решения: $\mathcal{O}(1)$ </spoiler> <spoiler summary="Решение"> ~~~~~ n = int(input()) if n < 21: print("amazing!") elif n < 51 and n > 20: print("good!") elif n < 151 and n > 50: print("bad!") else: print("very bad!") ~~~~~ </spoiler> <spoiler summary="Оце...
languages, the answer may not fit into a 32-bit integer data type, so it is necessary to use a64-bit, помещаться в 32-битный целочисленный тип данных, поэтому необходимо использовать64-битный тип данных

Full text and comments »

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