tweety's blog

By tweety, history, 4 years ago, In English

Hello fellow people of Codeforces

I hope everyone doing well in these uncertain and unprecedented times. I wanted to share this cool C++20 trick that I learned recently.

Check out this cool implementation of is_prime(n) to test if n integer is prime in O(1) runtime (without any runtime precomputation!)

bool is_prime(int n);

This code computes primes up to MAXN during compilation and stores them in a table right in the compiled binary. On a runtime is_prime(n) call, it queries the compiled table to find the result. Check this compiled assembly to find the sieve mask baked in the binary: https://godbolt.org/z/G6o84x.

This trick is achieved by passing the constructed Sieve as a template argument, which is always evaluated on compile-time. If you compile this code using older C++ standard, you will get the error:

error: a non-type template parameter cannot have type 'Sieve<MAXN>'

However, since C++20, non-type template parameter can have any LiteralType (note). In short, it is possible to compile-time compute an instance of any class with a constexpr constructor.

Here is a time test of compile-time vs run-time sieve computation:

main.cpp

Compiled with GCC 9.3.0 using the command g++ -std=c++2a main.cpp. This is the execution output on my laptop:

Runtime ans: 90. Elapsed (ms): 1008
Compiletime ans: 90. Elapsed (ms): 0

Of course no one re-computes sieve 1000 times, this is done here for the sole purpose of showing that the algorithm is not computing sieve in run time 1000 times.

While such tricks won't help you cheat pass Codeforces problems, they might will help your submission stand out for fastest runtimes. Hope you found this interesting!

Full text and comments »

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

By tweety, history, 7 years ago, In English

Hello everyone,

Unlike the norm, we have no structured schedule/training for IOI-ers in my country, and I feel really lost when I come to practice — picking random Codeforces problems and trying to solve them doesn't feel like an optimal use of time.

You can guess my level by my cf rating and previous IOI performance. Do you have any resources/suggestions/practice groups that wouldn't mind me joining them? Or maybe we can create such a group?

Thanks!

Full text and comments »

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

By tweety, history, 8 years ago, In English

This year is my first qualifying to IOI. Our team started the travel at 6 AM and arrived to Russia at 2 AM (next day) and only finished registration and got assigned to a room at 3:30 AM. Next day's (this day's, to be precise) schedule starts at 7 AM, and I have sleep problems so there's no point in trying to sleep now. :D I'm planning to write a summary of every day from my perspective. Do you think it's a good idea? I'll add pictures too :D

Full text and comments »

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

By tweety, history, 9 years ago, In English

I always sleep at 10 PM, except when there's an official contest next day I spend more than 3 hours trying to sleep while awake in bed. Tomorrow I have an official contest and I'm facing the same problem. To prevent this from happening I intentionally slept only 3 hours last night to be tired enough to sleep today, and I was very tired and sleepy all day because of that, and now it's almost 12 PM and I can't sleep. Does this usually happen to you? Do you have any suggestions on how to prevent it?

Full text and comments »

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

By tweety, history, 9 years ago, In English

UPD: a more complete and official list is now available here. I won't update this list anymore.

Name CF Handle Country Previous IOIs
Román Castellarin ponysalvaje Argentina 2013 — 2014 — 2015
Maximiliano Redigonda mredigonda Argentina 2015
Gianni Weinand Weheineman Argentina 2014 — 2015
Gastón Fontenla gfonn Argentina First Participation
Mushegh Shahinyan MyLeg Armenia 2014 S — 2015 B
Levon Muradyan _LeMur_ Armenia First Participation
Ashot Matevosyan ashmat98 Armenia First Participation
Karen Mkrtumyan KARM Armenia First Participation
Jerry Mao jerry Australia 2015 B
Declan McDonnell DXsmiley Australia 2015 B
Belinda Shi BeeShi Australia First Participation
Richard Gong gongy Australia First Participation
Florian Leimgruber fleimgruber Austria 2014 B — 2015
Miklós Horváth Austria First Participation
Simon Lehner-Dittenberger Austria 2015
Stefan Kurzbauer Austria First Participation
Jubayer Rahman Nirjhor Alpha_Q Bangladesh First Participation
Syed Rubab Redwan rubabredwan Bangladesh First Participation
Ruhan Habib ruhan.habib39 Bangladesh First Participation
Tasmeem Reza Bruteforceman Bangladesh First Participation
Ilya Medyanikov Ferathorn Belarus 2015 B
Fedar Karabeinikau Mediocrity Belarus 2014
Mikhail Natalevich minthe Belarus First Participation
Artur Petukhouski Arthur Belarus First Participation
Damien Galant damien_g Belgium 2014 — 2015 B
Corentin Simon azercoco Belgium First Participation
Bruno Ploumhans BrunoPloumhans Belgium First Participation
Ruben Van Dijck Belgium First Participation
Rogério Junior rogerioagjr Brazil First Participation
Pedro Henrique Pedrohso Brazil First Participation
Victor Agnez victoragnez Brazil First Participation
Lucca Siaudzionis luccasiau Brazil 2015 B
Alexander Crustev perchema Bulgaria First Participation
Encho Mishinev Enchom Bulgaria 2013 S — 2014 G — 2015 S
Hristo Venev mustrumr Bulgaria 2012 S — 2013 G — 2014 G — 2015 G
Daniel Atanasov Bulgaria 2015 S
Yikuan Li FatalEagle Canada 2014 B — 2015 S
Farbod Yadegarian NoWoDeYo Canada 2015 B
Kevin Sun ksun48 Canada First Participation
Jeffrey Xiao jeffrey.xiao Canada First Participation
KeFan Dong KFDong China First Participation
Zhizhou Ren Stilwell China First Participation
Wu Zuofan brandnewnode China First Participation
Ce Jin jcvb China First Participation
Marin Kisic mkisic Croatia First Participation
Adrian Beker abeker Croatia First Participation
Vilim Lendvaj vilim_l Croatia First Participation
Domagoj Bradac DBradac Croatia 2015 S
Ernesto David Peña Herrera Ernestico Cuba First Participation
Filip Bialas f.bialas Czech Republic 2015 B
Richard Hladík RiHL Czech Republic First Participation
Ronald Luc Czech Republic First Participation
Václav Volhejn -Wave- Czech Republic First Participation
Michael José Gonzáles Bardales Mjgonzales Dominican Republic 2015
Kelvin Xavier García Tiburcio xavier Dominican Republic First Participation
Ahmed ElBatanony ElBatanony Egypt First Participation
Ayman AbdALLAH Egypt First Participation
Mahmoud Badawy mahmoudbadawy Egypt First Participation
Sherif Nafee Sh1co Egypt First Participation
Andres Unt .I. Estonia 2014 — 2015 B
Oliver Nisumaa SLLN Estonia 2015
Toomas Tennisberg toomas Estonia 2015 B
Kristjan Kongas kkongas Estonia First Participation
Juha Harviainen Kuha Finland First Participation
Hannes Ihalainen Hansuzu Finland First Participation
Pietari Kaskela eXeP Finland First Participation
Kalle Luopajärvi kllp Finland 2013 B — 2014 S — 2015 S
Félix Breton France First Participation
Théophane Vallaeys France 2015
Thomas Sepulchre France 2015 B
Arthur Léonard Arturgo France 2014 — 2015 B
Malvika Raj Joshi a0666 India 2014 S — 2015 S
Rajat De rajat1603 India First participation
Sampriti Panda sampriti India First participation
Srijon Mukherjee India First participation
Stacia Edina Johanna Indonesia 2015
Sergio Vieri Indonesia First participation
Kwee Lung Sin Klungs Indonesia First participation
Muhammad Yusuf Sholeh yusufsholeh Indonesia First participation
Ali Bahjati LiTi Iran 2015 G
AmirMohammad Dehghan PrinceOfPersia Iran First participation
Arash Mahmoudian Reyna Iran First participation
SeyedParsa Mirtaheri SeyedParsa Iran First participation
Liran Markin markin2000 Israel 2015 B
Noam Tashma Israel First participation
Ron Solan Israel First participation
Tomer Adar Tomer.Adar Israel First participation
Takuya Inoue yokozuna57 Japan 2015 G
Riku Kawasaki maroonrk Japan First Participation
Yuta Takaya yutaka1999 Japan 2014 G — 2015 G
Takahiro Masuda namonakiaccount Japan 2015 G
Amangeldi Zhusubaliev bktl4ever Kyrgyzstan First participation
Arsen Kasymov AcPlusOne Kyrgyzstan First participation
Azret Kenzhaliev Azret Kyrgyzstan 2015
Bolot Bekbolotov bolot.bekbolotov Kyrgyzstan First participation
Aleksejs Popovs popoffka Latvia 2011 — 2012 B — 2013 B — 2014 S — 2015 B
Aleksandrs Zajakins Sanja Latvia First Participation
Ingus Jānis Pretkalniņš Ingus Latvia 2014 — 2015
Daniels Keziks DKezik Latvia First Participation
Dimitar Bajraktarov whitewind664 Macedonia 2015
Dushan Terzic dusante1 Macedonia First Participation
Nikola Stojkoski nikolastojkoski Macedonia First Participation
Vladimir Maksimovski ReaLNero Macedonia First Participation
Zi Song Yeoh zscoder Malaysia First Participation
Jen Khai Yew jenkhai Malaysia 2015
Jia Jen Ng tempeh Malaysia 2014 — 2015
Uday Patel dtb_oods Malaysia First Participation
Marcel Bezdrighin please_delete_account Moldova 2014 — 2015 B
Mihail Tarigradschi ThatMathGuy Moldova 2015 B
Gabriel Cojocaru I_Love_Tina Moldova First Participation
Daniel Grosu explodingking Moldova First Participation
Christopher Brown New Zealand 2014 — 2015 B
Jonathan Khoo Sosunser New Zealand 2015 B
Chris Jung xenoframium New Zealand First Participation
Chuanye Chen andrewchen New Zealand First Participation
Chibuoyim Faith Wilson Ogbonna ogbonnachibuoyim12 Nigeria 2015
Lesi Bright Nigeria First Participation
Tanitoluwa Adebayor Nigeria First Participation
Peter Achimugo Nigeria First Participation
Robin Yu robinyu Philippines 2015 B
Farrell Wu wfe2017 Philippines First Participation
Maded Batara Philippines First Participation
Ian Palabasan pocavreportgroup Philippines 2015
Mateusz Radecki Radewoosh Poland First Participation
Paweł Burzynski pawelek1 Poland First Participation
Juliusz Pham a.piasta Poland First Participation
Jarek Kwiecień yarek Poland 2014 G — 2015 G
Hyunsoo Kim khsoo01 Republic of Korea First Participation
Gyuho Suh WilliamGyuhoSuh Republic of Korea First Participation
Seungwon Shin Namnamseo Republic of Korea First Participation
Jaehyun Koo ko_osaga Republic of Korea 2015 S
Andrei Costin Constantinescu Andrei1998 Romania First Participation
Costin Andrei Oncescu geniucos Romania First Participation
Andrei Popa AndreiNet Romania 2015 B
Radu Muntean heracle Romania First Participation
Vladislav Makeev V--o_o--V Russia 2015 G
Mikhail Putilin SpyCheese Russia 2015 G
Stanislav Naumov josdas Russia First Participation
Grigory Reznikow vintage_Vlad_Makeev Russia First Participation
Denis Solonkov solonkovda Russia First Participation — Unofficial (Host Team)
Alexandra Drozdova demon1999 Russia First Participation — Unofficial (Host Team)
Mikhail Anoprenko manoprenko Russia First Participation — Unofficial (Host Team)
Askhat Sakhabiev super_azbuka Russia First Participation — Unofficial (Host Team)
Nenad Bauk fifiman Serbia First Participation
Dušan Živanović zDule98 Serbia 2015 S
Luka Vukelić Serbia First Participation
Nikola Spasić NNSpasic Serbia First Participation
Zhang Guangxuan zhangguangxuan99 Singapore First Participation
Pang Wen Yuen pwypeanut Singapore 2015 B
Clarence Chew Singapore First Participation
Jacob Por Loong Teo jacobtpl Singapore 2015 S
Peter Ralbovský peto159 Slovakia 2013 — 2014 — 2015 B
Samuel Sládek samo98 Slovakia 2015
Michal Sládeček misoxxx Slovakia 2015 B
Paulína Smolárová paulinia Slovakia First Participation
Jan Olivetti Auladell OneStone Spain First Participation
Jordi Calstellví Foguet jcastellvi Spain 2015
Jordi Rodríguez Manso JordiR Spain First Participation
Miquel Ortega Sánchez-Colomer metatron Spain 2015
Joakim Blikstad Xylofo Sweden 2014 B — 2015 S
Fredrik Hernqvist Freda Sweden 2015
Karl Lundstig lundstig Sweden 2015
David Wärn _h_ Sweden 2015 B
Mahmoud Hassan tweety Syria First Participation
Besher Massri besher Syria 2015
Muhammed Dwik Bug Syria 2015
Samir Aldroubi Sgauwjwjj Syria First Participation
Ta Jui Ho darry140 Taiwan First Participation
Bo Shi Yu fsps60312 Taiwan First Participation
Jui Nan Yen gkevinyen5418 Taiwan First Participation
Hao Cheng Yang howard41436 Taiwan First Participation
Farhod Farmon Farhod Tajikistan First Participation
Nodir Daminov Nodir.Daminov Tajikistan 2015
Nozim Safarov deleteeeeeeeeed Tajikistan First Participation
Farrukh Karimov Barsic Tajikistan First Participation
Adem Khachnaoui ademkhachnaoui Tunisia 2015
Mohamed Fadhel Omar baal-hammon Tunisia 2015
Ahmed Rekik rekikahmed Tunisia First Participation
Ahmed Selmi ahmedselmi Tunisia First Participation
Mustafa Erdem Kirez kalimm Turkey First Participation
Murat Ekici muratt Turkey First Participation
Osman Orhan Uysal osmanorhan Turkey First Participation
Yasin Kaya ykaya Turkey First Participation
Bayram Guvanjov bayram98 Turkmenistan 2014
Bekmyrat Atayev Bekmyrat.A Turkmenistan First Participation
Kerim Kochekov Kerim.K Turkmenistan First Participation
Perman Atayev PermanAtayev Turkmenistan First Participation
Aslandukov Matvey BigBag Ukraine 2015 S
Tsypko Anton arsijo Ukraine First Participation
Machula Maksym mHuman Ukraine First Participation
Minakov Stanislav stas99 Ukraine First Participation
Daniel Chiu waterfalls United States of America 2015 G
Calvin Lee negativebplusorminus United States of America First Participation
Lawrence Li lawrenceli United States of America First Participation
Dhruv Rohatgi pacu United States of America First Participation
Phan Duc Nhat Minh minh141198 Vietnam 2015 S
Pham Cao Nguyen natsukagami Vietnam First Participation
Le Quang Tuan goodthingstaketime_._ Vietnam First Participation
Tran Tan Phat tanphatls987 Vietnam First Participation

Congratulations to those who qualified for IOI 2016! :)
Please post names of participants in comments or message me to add them. :D
I did add a future date for usernames for colors to keep updated, but looks like sometimes it's not working. For that I'll update the list after every ratings update.
Shout-out to Azret for making the table.

Some info about IOI 2016:



Don't forget to like their facebook page to not miss any news.

Full text and comments »

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

By tweety, history, 9 years ago, In English

Quick reminder:

COI is going to take place today at 14:00 GMT/UTC

Don't forget to register from here!

Let's discuss the problems after the contest ends!

Full text and comments »

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

By tweety, history, 9 years ago, In English

I'm a high school student. I started competitive programming last year and since then my school grades got significantly lower. Competitive programming (especially for a newbie like me) takes up your whole time. I would have thought that the level I got to is enough for now and I can continue practicing after finishing high school, but I feel like I shouldn't since I qualified for IOI this year.

Do you think that for someone like me competitive programming is more important than high school grades? Don't get me wrong, I do love maths and physics and I am good at them, I just can't manage to keep up with other subjects.

For skilled competitive programmers who are in high school. How do you keep up with school? Does competitive programming eat up more time than school, and do you consider it to be more important?

Full text and comments »

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

By tweety, history, 9 years ago, In English

I was going to write a short post asking you about your opinion on the importance of university degree but ended up writing a really long text about the education system in my country, and I don't want to delete so if you don't want to read much please skip to the last paragraph.

Next year is going to be my last in high school so I was thinking about attending university. The universities where I live (in Syria) are really bad.

In the city where I live (which is the capital) there is one very bad (but free!) public university and couple other much worse private universities. Before I tell you how bad they are let me first start by telling you how terrible the application process is here.

There is a final exam by the end of the last year in high school which decides what universities you can get into. There's one school book set that is taught in every single school of the country. Schools can't teach other book sets by law. The school exams test your ability on memorizing what's written in the books rather on your understanding.

For example, in the English exam there is a task to write a paragraph. The teacher tells us beforehand what the subject of the paragraph is going to be and writes a sample paragraph on the board. Everyone copies it and memorizes it, then writes it on the exam in the exact same way their teacher wrote. Of course you can write your own paragraph, but it's more guaranteed to write the one that our teacher gave us since our teacher himself is not good enough at English for grading your paragraph (although they think they are).

In mathematics exams they copy the exact tasks from our school books and just change variables. I don't know anyone in my school who's good at maths, they all memorize the solutions for all problems and they are only trained to be adaptable with variable changes. I was once proud of myself for solving a relatively hard problem in the exam then after the exam I realized that the exact same task was featured in our book.

On the biology exam there comes a question and you have to answer it exactly as it's answered in the book. If you only change the context but keep the meaning you might lose marks. (I know you may not believe me but it's really like this, you can ask any Syrian and they'd tell you the same)

The final school exams are made in like manner. The problem is in how important they are despite how wrong they are made. Your high grade is the only ticket to get you into the university. There are minimal grades (limits) for each faculty. For example, for Medicine you have to have a grade higher than 98%, for Computer Science 95%, Civil Engineering 92%. Yes as you see facilities are as if ranked from what they think is best to what they think is worse. Some of facilities that require lowest grades are Fine Arts, Biology and Philosophy. The university won't hear you story, nor will they hear anything from you. They only look at your grades. That leads to kids only aiming for Medicine Studies. You (almost) won't find any freshman in Computer Science studying his degree for having passion in it. They will be studying it because they weren't able to achieve a higher grade for Medicine (and I guess that is one of the reasons behind the very low number of competitive programmers in Syria).

When it comes to the educational system in our universities, they pretty much lack of the same problems of schools. It's all about memorizing stuff for the exams. I won't judge any faculty other than Computer Science since I only have friends from that facility, but from what they told me they don't really learn anything there, they learn everything by themselves from the Internet.

I can try admitting to universities abroad, but I guess it's going to be really hard especially considering our very low budget. But even if I could, is really worth it? From what I see you can learn pretty much everything you need from the Internet. The only thing that would interest me in the university (as of what I'm thinking right now) is the ACM-ICPC (especially since it's really easy to qualify from our region due to the small amount of skilled participants :D). But then comes the importance of getting a university degree for applying for jobs. But wouldn't experience (say if I spent 4 years working on a project instead of attending a university) be more worthy than the degree?

Full text and comments »

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

By tweety, history, 9 years ago, In English

It is really rare to see that there are no upcoming contests on Codeforces.

Full text and comments »

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

By tweety, history, 9 years ago, In English

I'm going to share with you some cool applications of matrix exponential that I learned recently.

Application 1: Counting the number of ways for reaching a vertex

You are given an unweighted directed graph (may contain multiple edges) containing N vertices (1 <= N <= 200) and an integer b (1 <= b <= 10^9). You are also given Q queries (1 <= Q <= 10^5). For each query you are given two vertices u and v and you have to find the number of ways for reaching vertex v starting from u after exactly b steps. (A step is passing through an edge. Each edge may be passed multiple number of times).

Solution

Let M1 be a matrix where M1[i][j] equals the number of edges connecting vertex i to vertex j. Let M2 be M1 raised to the power of b (M1^b). Now for any pair u and v, the number of ways for reaching vertex v starting from u after b steps is M2[u][v].

Practice problem: 621E


Application 2: Shortest path with a specified number of steps

You are given a weighted graph containing N vertices (1 <= N <= 200) and an integer b (1 <= b <= 10^9). You are also given Q queries (1 <= Q <= 10^5). For each query you are given two vertices u and v and you have to find the minimum cost for reaching vertex v starting from u after exactly b steps. (A step is passing through an edge. Each edge may be passed multiple number of times).

Solution

Let M1 be a matrix where M1[i][j] equals the cost of passing the edge connecting i to j (infinity if there is no edge). Let M2 be M1 raised to the power of b (but this time using the distance product for multiplication). Now for any pair u and v, the minimum cost for reaching vertex v starting from u after b steps is M2[u][v].

Practice problem: 147B




Application 3: Nth Fibonacci number in O(log n)

You are given Q (1 <= Q <= 10^5) queries. For each query you are given an integer N (1 <= N <= 10^9) and you are to find the Nth number in the Fibonacci sequence.

Solution

I won't copy-paste anything, you can read about it here.




In case you don't know how to multiply matrices, you can read about it here. After you know how to multiply matrices you can easily calculate the power of a matrix in O(log n) just like you do with integers.

Any corrections/suggestions/additions are welcome.

And please point out any English mistakes or sentences that can be improved. :D

Full text and comments »

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

By tweety, history, 9 years ago, In English

I think that it would be good if we saw in the Standings the number of successful hacks next to the number of successful submissions, because I (and I think many others) always find myself going to the first two pages of Standings to check whether someone was hacking in some problem in order to lock it. What do you think?

Full text and comments »

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

By tweety, history, 9 years ago, In English

As you may have already noticed, Codeforces introduced a cool new feature for friends list. You can now see a list of your friends (which was really annoying back when I had to go to a contest and click on friends standings in order to see them), and you can also see how popular you are be knowing how many people have you in their friends.
I'm a friend of 31 users, tourist is a friend of 4,710 users.

Just one comment about this feature. As you see in my profile I'm a friend of 31 user. In English, we say I'm a friend of 31 users, because 31 are many friends.

Full text and comments »

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

By tweety, history, 9 years ago, In English

Unlike IOI 2015 Kazakhstan who made their website only like one month before the contest day, this year's IOI seems really exciting. They already have an awesome website and they even made a video about Kazan and the contest.
Since it has very little amount of views, I thought maybe I'd share it with you.
Link to the page containing the video.

Full text and comments »

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

By tweety, history, 9 years ago, In English

I recently stumbled upon a problem which seems very easy, but I can't seem to find the solution.

If we have five positive numbers: { X1, X2, X3, X4, X5 }, we can form ten distinct pairs of these five numbers. Given the sum of each pair, you are asked to find the original five numbers.
All numbers are positive integers bellow 1,000,000,000.

Any hints or solutions would be appreciated. :D

Full text and comments »

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

By tweety, history, 9 years ago, In English

I need a website on which I can upload problems with their test data, and make virtual contests. The problems are in IOI's style (they have subtasks). I tried googling but I couldn't find anything. Do you know of any such website?

Full text and comments »

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

By tweety, history, 9 years ago, In English

If I had in my algorithm something like this:

for (int i = 0; i < n; i++) if (i % 2) continue; else { code code code... }

Will the time complexity be O(n) or O(n / 2)?

Full text and comments »

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

By tweety, 10 years ago, In English

Output: aedcbf. Answer: aedcbf. Checker comment: wrong answer 1st words differ : expected: 'aedcbf', found: 'aedcbf'

Full text and comments »

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