Errichto's blog

By Errichto, 4 years ago, In English

I'm back to streaming and I plan the following three problem-solving streams, each lasting around 5 hours:

I will think out loud and talk about solutions, sometimes with implementation too. Streams 1 and 3 are meant to be educational, while stream 2 will be more of me thinking and struggling. I will not do virtual participation because the pressure of time doesn't go well with explaining anything.

You can watch me on my secondary Youtube channel https://www.youtube.com/errichto2/live or on Twitch https://www.twitch.tv/errichto.

See you in the chat :)

UPD — I will make shorter streams on Monday (the 17th) and Thursday (the 20th). It will be Codeforces div1C-D problems and Boring stream, respectively. I'm updating this old blog so I wouldn't spam with new one.

Full text and comments »

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

By Errichto, 4 years ago, In English

Part 1 (link) 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 of this blog (on my Youtube channel).

Built-in functions

In C++, __builtin_popcount(x) returns popcount of a number — 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. Now, try to solve these two simple tasks in $$$O(1)$$$, then open the spoiler to check the solution:

Compute the biggest power of 2 that is a divisor of x. Example: f(12) = 4
Compute the smallest power of 2 that is not smaller than x. Example: f(12) = 16

While popcount is often needed, I rarely use the other two functions. During a contest, I would solve the two tasks above in $$$O(\log x)$$$ with simple while-loops, because it's easier and more intuitive for me. Just be aware that these can be done in $$$O(1)$$$, and use clz or ctz if you need to speed up your solution.

Motivation behind bitsets

Consider this problem: There are $$$N \leq 5000$$$ workers. Each worker is available during some days of this month (which has 30 days). For each worker, you are given a set of numbers, each from interval $$$[1, 30]$$$, representing his/her availability. You need to assign an important project to two workers but they will be able to work on the project only when they are both available. Find two workers that are best for the job — maximize the number of days when both these workers are available.

You can compute the intersection of two workers (two sets) in $$$O(30)$$$ by using e.g. two pointers for two sorted sequences. Doing that for every pair of workers is $$$O(N^2 \cdot 30)$$$, slightly too slow.

We can think about the availability of a worker as a binary string of length $$$30$$$, which can be stored in a single int. With this representation, we can count the intersection size in $$$O(1)$$$ by using __builtin_popcount(x[i] & x[j]). The complexity becomes $$$O(N^2)$$$, fast enough.

What if we are given the availability for the whole year or in general for $$$D$$$ days? We can handle $$$D \leq 64$$$ in a single unsigned long long, what about bigger $$$D$$$?

We can split $$$D$$$ days into convenient parts of size $$$64$$$ and store the availability of a single worker in an array of $$$\frac{D}{64}$$$ unsigned long longs. Then, the intersection can be computed in $$$O(\frac{D}{64})$$$ and the whole complexity is $$$O(N^2 \cdot \frac{D}{64})$$$.

code

So, we can simulate a long binary number with multiple unsigned long longs. The implementation isn't that bad but doing binary shifts would be quite ugly. Turns out all of this can be done with bitsets easily.

Bitsets

bitset<365> is a binary number with $$$365$$$ bits available, and it supports most of binary operations. The code above changes into simple:

code

Some functions differ, e.g. x.count() instead of __builtin_popcount(x) but it's only more convenient. You can read and print binary numbers, construct a bitset from int or string bitset<100> a(17); bitset<100> b("1010");. You can even access particular bits with b[i]. Read more in C++ reference https://en.cppreference.com/w/cpp/utility/bitset.

Note that the size of the bitset must be a constant number. You can't read $$$n$$$ and then declare bitset<n> john;. If $$$n$$$ is up to $$$100$$$, just create bitset<100>.

The complexity of bitwise operations is $$$O(\frac{size}{32})$$$ or $$$O(\frac{size}{64})$$$, it depends on the architecture of your computer.

Problems

P1. Different numbers — You are given a sequence of $$$N \leq 10^7$$$ numbers, each from interval $$$[0, 10^9]$$$. How many different values appear in the sequence? Don't use set or unordered_set because they quite slow.

solution

P2. Knapsack — You are given $$$N \leq 1000$$$ items, each with some weight $$$w_i$$$. Is there a subset of items with total weight exactly $$$W \leq 10^6$$$?

solution

P3. Triangles in a graph — Given a graph with $$$n \leq 2000$$$ vertices and $$$m \leq n \cdot (n - 1) / 2$$$ edges, count triples of vertices $$$a, b, c$$$ such that there are edges $$$a-b$$$, $$$a-c$$$ and $$$b-c$$$.

hint

P4. Chef and Querieshttps://www.codechef.com/problems/CHEFQUE (easy)

P5. Odd Topichttps://www.codechef.com/AABH2020/problems/ODTPIC (medium), thanks to Not-Afraid for the suggestion

P6. Funny Gnomeshttps://www.codechef.com/problems/SHAIKHGN (hard)

Bonuses

1) m & (m-1) turns off the lowest bit that was set to $$$1$$$ in a positive number $$$m$$$. For example, we get $$$24$$$ for $$$m = 26$$$, as $$$11010$$$ changes into $$$11000$$$. Explanation on quora
2) A quite similar trick allows us to iterate efficiently over all submasks of a mask, article on cp-algorithms / e-maxx. This article also explains why masks-submasks iteration is $$$O(3^n)$$$.
3) DP on broken profile (grid dp) — https://cp-algorithms.com/dynamic_programming/profile-dynamics.html
4) SOS dp (sum over subset) — https://codeforces.com/blog/entry/45223 & https://www.youtube.com/watch?v=Lpvsd8WpbWc&t=5m4s
5) _Find_next function and complexity notation for bitsets — https://codeforces.com/blog/entry/43718

I will add links to some problems in online judges, feel free to suggest some in the comments. I think that bonuses 3 and 4 lack some explanation with drawings, maybe I will make some soon.

Full text and comments »

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

By Errichto, 4 years ago, In English

You can watch my Youtube video (link) with the same content as this blog. Anyway, enjoy.

Introduction

Let's learn bitwise operations that are useful in Competitive Programming. Prerequisite is knowing the binary system. For example, the following must be clear for you already.

$$$13 = 1 \cdot 8 + 1 \cdot 4 + 0 \cdot 2 + 1 \cdot 1 = 1101_{(2)} = 00001101_{(2)}$$$

Keep in mind that we can pad a number with leading zeros to get the length equal to the size of our type size. For example, char has $$$8$$$ bits and int has $$$32$$$.

Bitwise AND, OR, XOR

You likely already know basic logical operations like AND and OR. Using if(condition1 && condition2) checks if both conditions are true, while OR (c1 || c2) requires at least one condition to be true.

Same can be done bit-per-bit with whole numbers, and it's called bitwise operations. You must know bitwise AND, OR and XOR, typed respectively as & | ^, each with just a single character. XOR of two bits is $$$1$$$ when exactly one of those two bits is $$$1$$$ (so, XOR corresponds to != operator on bits). There's also NOT but you won't use it often. Everything is explained in Wikipedia but here's an example for bitwise AND. It shows that 53 & 28 is equal to $$$20$$$.

53 = 110101
28 = 11100

  110101
&  11100  // imagine padding a shorter number with leading zeros to get the same length
 -------
  010100  =  20
C++ code for experimenting

Shifts

There are also bitwise shifts << and >>, not having anything to do with operators used with cin and cout.

As the arrows suggest, the left shift << shifts bits to the left, increasing the value of the number. Here's what happens with 13 << 2 — a number $$$13$$$ shifted by $$$2$$$ to the left.

    LEFT SHIFT                             RIGHT SHIFT
       13 =     1101                          13 =   1101
(13 << 2) =   110100                   (13 >> 2) =     11   

If there is no overflow, an expression x << b is equal to $$$x \cdot 2^b$$$, like here we had (13 << 2) = 52.

Similarly, the right shift >> shifts bits to the right and some bits might disappear this way, like bits 01 in the example above. An expression x >> b is equal to the floor of $$$\frac{x}{2^b}$$$. It's more complicated for negative numbers but we won't discuss it.

So what can we do?

$$$2^k$$$ is just 1 << k or 1LL << k if you need long longs. Such a number has binary representation like 10000 and its AND with any number $$$x$$$ can have at most one bit on (one bit equal to $$$1$$$). This way we can check if some bit is on in number $$$x$$$. The following code finds ones in the binary representation of $$$x$$$, assuming that $$$x \in [0, 10^9]$$$:

for(int i = 0; i < 30; i++) if((x & (1 << i)) != 0) cout << i << " ";

(we don't have to check $$$i = 30$$$ because $$$2^{30} > x$$$)

And let's do that slightly better, stopping for too big bits, and using the fact that if(value) checks if value is non-zero in C++.

for(int i = 0; (1 << i) <= x; i++) if(x & (1 << i)) cout << i << " ";

Consider this problem: You are given $$$N \leq 20$$$ numbers, each up to $$$10^9$$$. Is there a subset with sum equal to given goal $$$S$$$?

It can be solved with recursion but there's a very elegant iterative approach that iterates over every number $$$x$$$ from $$$0$$$ to $$$2^n - 1$$$ and considers $$$x$$$ to be a binary number of length $$$n$$$, where bit $$$1$$$ means taking a number and bit $$$0$$$ is not taking. Understanding this is crucial to solve any harder problems with bitwise operations. Analyze the following code and then try to write it yourself from scratch without looking at mine.

solution code

Two easy problems where you can practice iterating over all $$$2^N$$$ possibilities:
- https://codeforces.com/problemset/problem/1097/B
- https://codeforces.com/problemset/problem/550/B

Speed

Time complexity of every bitwise operation is $$$O(1)$$$. These operations are very very fast (well, popcount is just fast) and doing $$$10^9$$$ of them might fit in 1 second. You will later learn about bitsets which often produce complexity like $$$O(\frac{n^2}{32})$$$, good enough to pass constraints $$$n \leq 10^5$$$.

I will welcome any feedback. Coming next: popcount, bitsets, dp with bitmasks. I will also make a YT video on this. YT video link is at the top.

Part 2 link

Full text and comments »

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

By Errichto, 4 years ago, In English

Instructions how to setup up Linux and Geany for competitive programming: https://github.com/Errichto/youtube/wiki/Linux-setup

An optional video that shows the process: https://youtu.be/ePZEkbbf3fc

I created this because so many people ask me about my environment and compilations flags. You don't have to follow exactly these steps or actually use Linux at all. Remember that 99% of your performance comes from skills so you should focus on that instead of worrying too much about tools you use.

Full text and comments »

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

By Errichto, 4 years ago, In English

Previous part: https://codeforces.com/blog/entry/63606

Apparently, one of problems had incorrect output data. Can someone confirm? On the bright side, no huge technical issues this year afaik.

Unpopular opinion here: Prague isn't a good organizer :O

Also, some disqualification in the top happened :O

Full text and comments »

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

By Errichto, 4 years ago, In English

I and Lewin will do some commentary of TCO semifinal 1, starting in a few minutes. Watch it on TCO Twitch website.

Stream: https://www.twitch.tv/topcoder_official

Statements: https://docs.google.com/document/d/1OjmXL8DMDiWf92XhLch_xjjPVA21-dvIhcnYEh_0CbM/edit?usp=sharing

Full text and comments »

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

By Errichto, 4 years ago, In English

You can watch the lecture on Youtube: https://youtu.be/0r2D32esF3Y. I will do a second part soon. Some problems are quite vague, it's a nature of this topic.

  1. Warm-up: You toss a coin till you get tails. How many tosses there will be, on average?
  2. X or smaller — There is a hidden number $$$X$$$. An interactor repeatedly gives you a number, either $$$X$$$ or something smaller than $$$X$$$. All numbers are positive integers. When can you stop and say that you are (almost) certain what is the value of $$$X$$$?
  3. Line through N/4 points — Given $$$N \leq 10^5$$$ points, find a line that passes through the maximum number of points. It's guaranteed that the answer is at least $$$N / 4$$$.
  4. GCD (364D - Ghd) — given a set of $$$N \leq 10^6$$$ numbers, each up to $$$10^{12}$$$, find the maximum possible number that is a divisor of at least half of given numbers.
  5. ACTG prefix — Guess a hidden string $$$S$$$ with characters A, C, T, G. You can choose some string and ask if it's a prefix of $$$S$$$. The length of $$$S$$$ is at most $$$10\,000$$$ and you can ask up to $$$25\,000$$$ queries.
  6. How many tails you will get after tossing a fair coin $$$10^6$$$ times? It should be around $$$500\,000$$$, but how far away from this number can you realistically/plausibly get?
  7. Don't use a fixed seed in Codeforces or Topcoder because somebody can hack/challenge you.
  8. RAND_MAX in Codefoces is around $$$30\,000$$$, so use your own rand() in C++, same for random_shuffle(). More here: https://codeforces.com/blog/entry/61587

More (and harder) problems can be found here: https://codeforces.com/blog/entry/51244

And if you want to learn more about expected value: https://codeforces.com/blog/entry/62690

Save trees: https://youtu.be/TnCVAEsYGKs #TeamTrees

EDIT, part 2: https://youtu.be/GS2MxmorEzc

  1. Catch 'em all — When you encounter a Pokemon, it's random out of $$$N$$$ types. How many Pokemon will you encounter (on average) before seeing all $$$N$$$ types? Estimate this value.
  2. Birthday paradox — How many encounters before we see the same type of Pokemon twice?
  3. Hash collision — what is the probability of hash collision in problems like "given queries, check if this substring is equal to that substring" compared to "given a bunch of strings, find a pair of equal strings". The latter has much bigger probability of collision. Why?
  4. How to randomly shuffle an array?
  5. Repeated binary search — Find max element in a hidden sequence by asking queries "is $$$a_i$$$ greater than $$$x$$$?" faster than $$$\mathcal O(n \log n)$$$, https://codeforces.com/blog/entry/62602
  6. Bonus: estimate $$$\pi$$$ using randomized algorithm.

Full text and comments »

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

By Errichto, 5 years ago, In English

There are two mainstream contests tomorrow (Google Kickstart and Leetcode biweekly) and I will make a live stream just after them at 18:30 CEST on Saturday. After talking about some problems from those contests, I will upsolve Codeforces or Topcoder problems, maybe from a recent CF round by tourist.

Watch me on Youtube — https://youtu.be/w3W-w0EXEtc.

Full text and comments »

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

By Errichto, 5 years ago, In English

Hey, hi, hello.

Codeforces Round 584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) starts on Sep/14/2019 16:05 (Moscow time) and lasts 2h30m. The score drain will be adjusted for longer contest duration. It's a combined rated round with around eight problems. It is open and it is rated for everybody. Yes, it's rated. There are Dasha t-shirts for top 30 competitors (not counting later-to-be onsite finalists).

As an extra, this is an elimination round for those who live in/near SPb/Novosibirsk. More info about the championship is in the other blog. Thanks to Dasha.AI for making such an event for the community!

Problems are prepared by MikeMirzayanov, FieryPhoenix, dragonslayerintraining and Errichto. One of these setters also created Codeforces, thanks for that! And huge thanks to cdkrot for coordinating the round, to Merkurev, isaf27, KAN and me for testing, and finally to mareksom, Radewoosh and Marcin_smu for some small help.

I wish you more fun than bugs. Enjoy the contest!

PS. I recorded the process of preparing one problem with commentary, will publish it on Youtube after the contest. EDIT: https://www.youtube.com/watch?v=IaViSV0YBog

UPDATE, points: A 500, B 500, C 1250, D 1500, E 1000+1500, F 2500, G 1500+2250, H 4000. There are 8 problems and 2 of them are split into two versions. Good luck!

UPDATE, huge congratulations to winners!

  1. Petr
  2. jqdai0815
  3. LayCurse
  4. zeliboba
  5. 300iq

I was the author of last two problems: Into Blocks (but thanks for cdkrot for preparing it!) and Walkways, hope you liked them.

UPDATE, editorial is out.

Full text and comments »

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

By Errichto, 5 years ago, In English

I think that all problems looked awful at the first sight but actually all were quite cool :O

editorial (was posted as announcement after the round)

Congratulations to advancers! Results screenshot below (top10 gets to the finals + some early advancers from previous rounds).

results

Full text and comments »

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

By Errichto, 5 years ago, In English

I conducted a camp for Kazakhstan via the Internet and I was allowed to record it. I'm putting some of those lectures and problem analysis on Youtube. Maybe it will be useful for participants who are still practicing. See recent videos here, https://www.youtube.com/errichto2.

There are currently solutions for Innopolis Open 2018-19 (cool hard contest in CF GYM), two days of POI 23 (2015-2016) and also a lecture on wavelet trees. Innopolis Open solutions include these two methods:

Спойлер

Will soon add some more, including segment tree beats and Li Chao tree.

Full text and comments »

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

By Errichto, 5 years ago, In English

I want to go to Joker's Asylum ER in San Jose (California) on the 7th of August, two days before GCJ finals. It's a difficult escape room and a team should consist of 5-10 people. So far, there's me and my friend — not really pros. I'm looking for more people to go there and maybe grab a beer later. If the date is fine for you and you are good at ER and/or algo, write a DM to me.

This room has very good reviews and the escape room veteran Swistakk recommends it a lot. Sounds promising, right?

Full text and comments »

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

By Errichto, 5 years ago, In English

I recorded a 30-minute lecture about binary search. It should allow you to really understand it and stop guessing about +1 in random places. Enjoy.

https://www.youtube.com/watch?v=GU7DpgHINWQ

Consider watching with captions on and with x1.25 speed.

Full text and comments »

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

By Errichto, 5 years ago, In English

Which one should we use?

Competitive Programming is used more often but it has stupid abbreviation (Cerebral Palsy and Child Pornography). Some Youtube accounts about Pokemon Go were actually banned for using that because of Combat Points. Here you can read things like "My Club Penguin video had been flagged for sexual content". This also means it isn't cool to write "I'm addicted to CP" in any social media. Urban Dictionary says that SP means Sex Party, but I don't think it's common and at least it isn't something shameful/harmful.

I think the Polish term is "programowanie sportowe" (sports programming) but sometimes we just say English words "competitive programming". The Russian say "Спортивное программирование" (sports programming), in Portuguese it is "Maratona de Programação" (programming marathon). What do you say in your language? In particular, I would like to hear native speakers to state their opinion.

And Sports Programming is arguably cooler.

I'm asking because I want to make videos like "What is Competitive Programming?" and "How to start with ...", "TOP FIVE BEST COMPETITIVE PROGRAMMING PLATFORMS OF 2019, YOU WON'T BELIEVE NUMBER 4" etc. If we prefer Sports Programming, I will use it instead.

EDIT: A huge argument for CP is ofc. that we use it like 99% of time. There are some single occurrences of SP, e.g. "The ICPC is the world’s premiere university sports programming competition" on the ICPC 2019 website, but it's a minority.

Full text and comments »

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

By Errichto, 5 years ago, In English

Hi.

Even more streams are coming. For notifications, subscribe to my secondary channel for streams Errichto 2, or you can watch me on Twitch.

Stream 1 — Monday at 12:00 CEST, I want to check out coding interview platforms like Leetcode. Here's Youtube link.

Stream 2 — Tuesday at 9:00 CEST. Algo research and writing old editorials. Links to part 1 and part 2 (the stream stopped for a few seconds and the new one started).

Stream 3 — Friday at 12:00 CEST. Solving Codeforces problems, mainly around div1D div2D (sorry, a typo). In particular, I will solve rounds #560, #561 and Edu #65. Links to part 1 and part 2. Again, the stream stopped for a moment and YT splitted it into two.

See ya.


Same plan next week:

Stream 4 — Monday, 27th of May, at 12:00 CEST. Boring stream with planning my future blogs and Youtube videos. Link.

Stream 5 — Tuesday at 9:00 CEST. Coding interview platforms again. Link

Stream 6 — Friday at 12:00 CEST. Some old POI problems. I will choose something and update the post so you could read problems and think about them in advance. Data structures for coding interviews like linked lists. (After an update, Linux stopped working on my PC, so no coding stream.) Link

Full text and comments »

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

By Errichto, 5 years ago, In English

Hi.

I will make two streams this week. Both will be on my YT channel Errichto 2 and on Twitch. My streams will usually be on that second YT channel, while my main channel is for short educational videos, also outside of competitive programming.

Stream 1 — Thursday at 9am, virtual participation of PSUT Coding Marathon 2019 with commentary, just like Atcoder DP stream. The contest is in GYM (link). The original announcement by Hasan0540 is here.

Stream 2 — Friday at 2pm, boring programming stream: maintaining and planning my YT channel, checking out blogs, checking out new game on Codingame (it will start too late), finishing problems from PSUT stream.

See ya.

Full text and comments »

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

By Errichto, 5 years ago, In English

Google Code Jam round 1A starts in less than 3 hours. https://codingcompetitions.withgoogle.com/codejam

In each of rounds 1A, 1B, 1C, top 1500 participants will advance to round 2 (4500 in total).

I'm not going to participate (because it's the middle of a night for me), but a reminder might help other people.

Full text and comments »

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

By Errichto, 5 years ago, In English

Hi.

On Wednesday at 9:05 CET / 8:05 UCT 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 and day2.

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 MikeMirzayanov for helping me with using GYM.

And credits to problem authors: Andreikkaa for Radium, Endagorion for Viruses, pashka for Innophone, Георгий Корнеев and GlebsHP for Quantum Teleportation.

Second day authors: cdkrot for Decryption, "jury" for Quick Sort, GlebsHP for Robomarathon, Endagorion for Addition without carry.

I will post a very short editorial in English here, after the contest.

Extraction of radium
Innophone
Quantum teleportation
Viruses

Second day tomorrow, same time.

Thank you for participation.

Addition without carry
Decryption
Quick sort
Robomarathon

Full text and comments »

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

By Errichto, 5 years ago, In English

There was a blog that chemthan got hacked, and indeed I got strange messages from his account, asking for help with problems from the next Google Kickstart. The blog is now deleted. It would be nice to hear from some friends of his whether everything is ok now. chemthan1 is allegedly his temporary alt account. Also, ikatanic was mentioned.

I can remove this blog a few days after everything is resolved, if chemthan wishes so.

Full text and comments »

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

By Errichto, 5 years ago, In English

Hi.

https://www.codingame.com/ regularly holds 10-day long competitions where you should write a program that plays a 2-player game. Sometimes you must move units/soldiers in a grid, sometimes it's a card game. The next game starts tomorrow (Friday) and then we'll see what's the topic (well, it must be food related).

I'm going to stream my approach from scratch on Youtube and Twitch. Start on Friday at 9pm CET (3pm EST). Btw. I streamed the previous game three months ago, link.

No prerequisites needed. I will explain my thoughts and give general advice for this type of contests. Feel free to ask questions in chat.

See you!

Full text and comments »

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

By Errichto, history, 5 years ago, In English

The qualification round starts in 50 minutes. Let's share scores and discuss the problem after the contest. Useful links below.

Judge System
Official livestream
FAQ

Good luck!

Full text and comments »

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

By Errichto, 5 years ago, In English

Sadly, after spending a few hours learning about quantum programming, I decided to cancel the stream. Maybe I would be able to solve some problems in the warm-up round, but certainly, I don't have enough knowledge to make a stream about it, and I'm afraid I would say something incorrect multiple times and thus cause damage to viewers. I'm extremely sorry for that.

Instead, I will talk about the Google Hash Code competition. I competed last year with a success. Our team won the qualification round and we were 6-th in the final round (I hope I remember that correctly because I can't find the standings). I'm going to go through the problems from that 2018 edition, talk about my codes, and I will give general advice for the contest. If you want to participate this year, you must hurry — the registration closes tomorrow (on Monday)! Registration link.

The stream starts at 12:00 CET.

My next stream is this Sunday at 12:00 CET, and I will try to solve problems from the ongoing warm-up of Q# Coding Contest by Microsoft's Quantum team. Read more details about that contest in the announcement.

I'm very excited about this because it will be something unusual, just like distributed algorithms that were new and amazing for me. mareksom competed in the first edition and he said it's very cool. If it turns out boring, let's blame him.

PS. I have no idea what quantum programming is, but I watched Ant-man and Ant-man 2. I hope this is enough. (yeah...)

You can watch me on Youtube or Twitch.

Full text and comments »

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

By Errichto, 5 years ago, In English

Hi.

On Sunday, I'm going to solve problems from the Educational Dynamic Programming contest on AtCoder — https://atcoder.jp/contests/dp. Start at 10:00 CET (check your timezone), expected duration 5 hours. Watch me on YT or Twitch: https://www.youtube.com/errichto, https://www.twitch.tv/errichto.

There will be 26 problems, all on dynamic programming. More info here.

See you tomorrow!

Full text and comments »

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

By Errichto, 5 years ago, In English

What to do when you need help with a problem?

  1. If there is an editorial, read it. If you don't know some technique, google it and read a tutorial.
  2. Ask a friend for help. It's very useful to find someone in your university/country who also does competitive programming.
  3. "I'm getting WA and don't know why."
    Try to find a counter-test. Take an accepted code if it's available, and write a brute force otherwise. Test it against your solution on thousands of random tests, especially small ones.
  4. "My code doesn't work on this test."
    Use some debugging tools (google them for your OS/IDE) or just print values of everything you compute. I use gdb and valgrind. Simulate the program on paper too. This way you should find an exact place where something incorrect happens, or you will see that your approach is completely wrong.
  5. "The output differs on my machine and in Codeforces/anotherPlatform."
    It's likely "undefined behavior", e.g. you don't initialize a local variable or you don't return anything from a non-void function. It doesn't happen often if you know the language well. Avoid non-integer values if possible, because real values involve the precision error. Try running your program in a few places online like ideone.com or Codeforces custom invocation. Don't use ideone during a contest or somebody will see your code and you will be disqualified! If it's C++, use compilations flags that catch more errors. I use g++ -std=c++17 -Wshadow -Wall -o a a.cpp -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g. It increases the running time though, so compile in a different way if you need the speed.

General advice:

  1. Practice by solving problems with editorials, especially if you don't know people doing CP, e.g. in your university.
  2. Solve problems slightly above your level, not something extremely hard. If the solution/editorial is overwhelming, maybe get back to this problem in a few months.

Still want to ask for help?

  1. If you think your question is small and easy to answer, consider asking in the discord channel, link.
  2. Write a blog instead of asking some random red guy in priv. This way more people can see it and more people can read the answer and learn something.
  3. Provide a source of your problem.
    If there is no link and a person is not well known in the community, I'm assuming it's from an ongoing contest or it's your homework. I think such blogs should be answered too, but not immediately.
  4. Describe what you already came up with.
  5. If you have some code, use meaningful variable names and put comments. If you know which part doesn't work, mention it.
  6. Either put the code in "block" and "spoiler" tags (you can see them next to bolding and enumeration), or give a link to a submission or an upload in pastebin/ideone/etc.
  7. Use proper English. Full words, dots to finish sentences, uppercase to start them. Use a browser that checks your spelling in English.
  8. You can read more here.

Also:

"Can I ask a question?"

This happens often in priv. Just ask your question instead of wasting my time. Also, http://www.nohello.com/.

Using "bro/sir"

Don't use that. See how others write in Codeforces or any other international forum.

"Why is my blog downvoted?"

You shouldn't care about it. Codeforces votes are strange and random sometimes. Still, use your main account. I prefer answering people that use Codeforces and have some non-empty contest history.

"How to train, get better, etc.?"

Google your question. There were plenty of those in Codeforces and Quora. If you don't want to do that, just read this.

What should I add here? Suggestions in comments or priv, please. And when you see a badly asked question or somebody bothers you in priv, feel free to link to this blog.

Full text and comments »

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

By Errichto, 5 years ago, In English

I got a private message in Codeforces:

"hey u r on cf and toc both . how r problems at toc div1 for gcj and fb hc ? for practicing."

I told the guy to use full words and to start the beginning of a sentence with uppercase, so it would be easier to understand him. And he indeed sent me a version that is easy to read!

"ok ! Hey , you use both codeforces and topcoder ! I wanna know How are problems at topcoder division 1 for practicing for google code jam and facebook hacker cup !
Which is the best Platform for it !"

So much better! Remove an unnecessary space character before punctuation marks (dots, exclamation marks, etc.) and you have proper grammar and everything. I also recommend using uppercase for abbreviations like CF, TC, FHC, GCJ. My English isn't perfect either, but I'm learning. And I use Grammarly (a free add-on with optional premium) that finds a lot of errors, typos, and missing commas. For example, I've just written "grammarly" and it suggested correcting it to "Grammarly". Fair enough. Btw. my answer was: Topcoder and Atcoder for GCJ, Codeforces and Codechef for FHC.

Anyway, what did make you proud of Codeforces recently? Did you see some post that asked for help with a problem and wasn't downvoted into oblivion? Or maybe somebody wanted to share their private videos for free? Share your stories!

Full text and comments »

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