By VladProg, 6 years ago, translation, In English

I invite you to participate in the rated Codeforces Round #499. Date and time of the round: Jul/26/2018 18:05 (Moscow time).

Those whose rating is not less than 1900 can participate in the round Div.1. Other can participate in the round Div.2.

Do not skip this contest, because the next Codeforces Round (Div.1, Div.2, or Div.3), which number begins with the digit '4', will be through the 3501 rounds!

This is the first competition I proposed. I hope that you will enjoy it.

The round will have 6 problems for each division (4 problems are common). The contest will last for 2 hours.

The main heroine of the competition is astronaut Natasha, Mars researcher. If you solve all problems, her flight will pass successfully.

Five problems of the contest are invented by me, Vladislav Zavodnik (VladProg), problems Div2.A and Div2.B are invented by Mike Mirzayanov (MikeMirzayanov), and problem Div1.F is invented by Ildar Gainullin (300iq) and Dmitry Sayutin (cdkrot).

Also thanks to:

Scoring distribution will be announced later.

I wish you a high rating and I am looking forward to see you at the competition!

UPD1

Pay attention: count of problems at the round was changed. The round will have 6 problems for each division (4 problems are common).

The round will have one interactive problem for both divisions. Please, read the post about it here: Interactive Problems: Guide for Participants.

UPD2. Scoring distribution:

Div.2: 500, 1000, 1250, 1500, 2000, 2500

Div.1: 500, 750, 1000, 1500, 2250, 2750

UPD3. The contest is over. Congratulations to the winners!

Div.1:

  1. Kostroma

  2. molamola.

  3. Benq

  4. Petr

  5. scott_wu

Div.2:

  1. mayaohua2003

  2. SqwrIwy

  3. _yesname

  4. llgyc

  5. Sakits_tjm

UPD4. Editorial is published.

Full text and comments »

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

By Gassa, history, 6 years ago, translation, In English

Hi all!

I invite you to take part in Codeforces Marathon Round 2. The contest will start on Tuesday, July 24, 2018 at 15:00 MSK, and will last for 7 days. There will be one problem based on game mechanics of a couple of board games for children. The problem most likely does not have a fast and full solution. So the solutions will be given scores, and the winner will be the one who gets the highest total score.

The contest will be unrated because the problem is considerably different from the problems of rated rounds.

During the time of the contest, the solutions will be checked on examples and preliminary tests. After the contest is over, the final solution of each contestant will be checked on the final test set, and the total score for this test set will determine the final scoreboard. The contest will take place on Codeforces platform and is supported by the Community Of Master Programming at St. Petersburg State University (link in Russian) and 90.01 Group.

The Codeforces platform has seen only few marathons so far. So, if something breaks, don't be upset, just write about it, and we will try to fix it.

Good luck in the contest!

Full text and comments »

Announcement of Codeforces Marathon Round 2
  • Vote: I like it
  • +266
  • Vote: I do not like it

By MikeMirzayanov, 6 years ago, translation, In English

Hello, Codeforces.

This is a short blog to introduce you recent updates in Testlib and Polygon.

Testlib

Generate a Permutation

Now, you can easily generate a permutation with codes like this:

Code Result
vector<int> p = rnd.perm(n); Generates 0-indexed permutation of size n
vector<int> p = rnd.perm(n, 1); Generates 1-indexed permutation of size n

Function println

Now, you can easily print space-separated lines in a generator. A println uses cout, thus prefer faster method if you print huge data.

Some examples:

Code Result
println(5); Print 5 and line break
println(1, 2, 3); Print 1 2 3 (three space separated integers) and line break
println("one", "more", 5.5); Print one more 5.5 (three space separated items) and line break
vector<int> a; ...; println(a); Print vector a (separate elements with spaces) and line break
vector<int> a; ...; println(a.begin(), a.end()); Exactly the same as above
string b[5]; ...; println(b, b + 5); Print array b (separate elements with spaces) and line break

Here is the example of a generator to print a permutation:

#include "testlib.h"

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);
    
    int n = atoi(argv[1]);
    println(n);
    println(rnd.perm(n, 1));
}

Function readInts and similar

Just as a reminder. Use functions readInts/readLongs/readStrictDoubles or readTokens/readLines in a validator to read and validate a sequence of values. To read a size of an array and array itself, use:

int n = inf.readInt(1, 200000, "n");
inf.readEoln();
inf.readInts(n, 1, 1000000, "a");
inf.readEoln();
inf.readEof();

Polygon

Example Problems

I've introduced three example problems. Each Polygon user has READ-access to them. Please, use them as examples how to write a problem in Polygon. They are:

  • example-a-plus-b: simple A+B problem
  • example-almost-upper-bound: simple problem to illustrate non-standard checker (always consider to use readAnswer function like in the example), generators and stress tests
  • example-interactive-binary-search: simple interactive problem on a binary search

Other Small Fixes

  • Allow to upload files (for example, images) as a contest property/file to use them in the statements.ftl. File names should start with 'statements-'.
  • API has been improved to support general description, general tutorial, tags, test groups and points.
  • Show problem ID on the summary box (on the righmost top block).
  • Replace UTF-8 typographic characters to their ASCII equivalent (for example, replace em dash — with ---).
  • Caching issue has been fixed. Previously, it could show RJ on tests even if the reason has been fixed.

Thanks to fcspartakm for implementing most features in Polygon.

Full text and comments »

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

By Chilli, history, 6 years ago, In English

TL;DR

The Policy Hash Table has 3-6x faster insertion/deletion and 4-10x increase for writes/reads. As far as I can tell, there are no downsides. The policy hash table (specifically the open-addressing version), beats out unordered_map in all my benchmarks.

PS: Make sure you read the section a better hash function and use it — I'd recommend this one: https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/HashMap.h

Background

I've often been irritated by how slow unordered_map is in C++. Too often, I have something that runs fast enough in terms of complexity, but the constant factor from unordered_map slows down the solution too much. Yesterday though, after using the useful order statistics tree from https://codeforces.com/blog/entry/11080, I was curious if there were any other useful data structures hiding in the Policy STL. And lo and behold, I found a hash table.

Benchmarks

Well, enough backstory, let's look at some numbers. All benchmarks below are compiled with C++14 -O2.

unordered_maplinear insertion:                                  0.689846
cc_hash_tablelinear insertion:                                  0.408233
gp_hash_tablelinear insertion:                                  0.256131

unordered_maplinear read/write:                                 1.69783
cc_hash_tablelinear read/write:                                 0.202474
gp_hash_tablelinear read/write:                                 0.26842

unordered_maprandom insertion:                                  2.90184
cc_hash_tablerandom insertion:                                  3.15129
gp_hash_tablerandom insertion:                                  0.56553

unordered_maprandom read/write:                                 2.02336
cc_hash_tablerandom read/write:                                 0.333415
gp_hash_tablerandom read/write:                                 0.403486

While for linear insertions, the policy hash table gives modest improvements, the policy hash table blows the unordered_map out of the water when it comes to reads/writes. These are order of magnitude improvements that make hash tables usable when they previously weren't. "Official" benchmarks done by the DS authors can also be found here

Example

Benchmarks of course, don't always reflect the real world. So here's an example of it allowing a solution to be accepted that TLE's with unordered_map.

Example problem (5000 ms time limit)
Solution with unordered_map: (TLE on test case 8)
Solution with policy hash table directly substituted in: (TLE on test case 26)
Solution with unordered_map, rewritten to not use clears: (TLE on test case 26)
Solution with policy hash table and rewritten to not use clears: (AC with max time of 3180 ms)

Usage

To use this data structure:

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> table;

From there, the API seems almost exactly the same.

Defeating Anti-Hash tests

One weakness of hash tables is that mean people can find hash collisions offline and blow up the complexity of your hashmap. In my opinion, the easiest way of solving this is below. There's no need to define your own custom hash function.

const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
gp_hash_table<key, int, chash> table;

Why is it so much faster?

See my comment here

A better hash function

There is one issue with using policy hash tables as is. The default hash function for numerics in C++ is just the identity. This is especially problematic for using hash tables for something like a fenwick tree, especially since the default bucket structure for policy_hash_tables is based of powers of 2 and not primes. If you're using policy hash tables for fenwick trees, you have 2 options. 1. Choose to use prime table sizes, as done here. 2. Choose a better hash function for integers, as done here.

Thanks to adamant for his post that revealed to me the existence of policy data structures, and thanks to ed1d1a8d for the discussion.

PS: In other posts for unordered_map, I've seen people claim that reserve and max_load_factor could increase performance drastically. They didn't seem to do much for me. However, if you want to do something similar for these hash tables, check out the example here

Code for the benchmarks can be found here

EDIT: I realized that gp_hash_table is the way to go, not cc_hash_table. gp_hash_table sacrifices ~10% reading/writing speed to gain 3-6x in insertion/deletion/clearing. I updated the post to reflect the new numbers.

Full text and comments »

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

By vovuh, history, 6 years ago, translation, In English

Hello!

Finally I am freed from the big part of summer cares and I can continue the preparation of Div. 3 rounds! I decided to add something written by me to this blog because TryToKnowMe (and many others, i think) noticed that i am really copy and paste this text from one announcement to another changing only contest name and start time. But... Who knows, may be this time which is saved by copy-pasting the announcement allows me to prepare the problems better?... Let it stay a mystery. So, let's go.

Codeforces Round 498 (Div. 3) will start at Jul/16/2018 17:35 (Moscow time). You will be offered 6 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. Probably, participants from the first division will not be at all interested by this problems. And for 1600-1899 the problems will be too easy. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

  • take part in at least two rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

UPD: Also great thanks to the testers uwi, mareksom and ivan100sic for their invaluable help with the round preparation!

UPD2: Results table!

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 wendy_virgo 6 236
2 TwentyOneHundredOrBust 6 237
3 zwgtxdy 6 265
4 Syvail 6 273
5 khadgar1998 6 279

Congratulations to the best hackers:

Rank Competitor Hack Count
1 jhonber 131:-7
2 antguz 9
3 pye 9:-3
4 djm03178 6:-1
5 imlk 4

199 successful hacks and 232 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A eggmath 0:01
B eggmath 0:06
C vangtrangtan 0:07
D MoreThanANoob 0:23
E Student_of_Husayn 0:07
F NoTrolleNoLife 0:18

UPD3: Editorial is published.

Full text and comments »

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

By awoo, history, 6 years ago, translation, In English

Hello Codeforces!

On Jul/14/2018 17:35 (Moscow time) Educational Codeforces Round 47 will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extented ACM ICPC rules. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 7 problems and 2 hours to solve them.

The problems were invented and prepared by Ivan BledDest Androsov, Vladimir vovuh Petrov, Maksim Neon Mescheryakov, Aslan Timurovich Tamaev and me.

Good luck to all participants!

I also have a message from our partner, Harbour.Space University:

Hi Codeforces!

We want to remind everyone that the Hello Barcelona Programming Bootcamp is right around the corner, and we’d love to see you there!

Our boot camp will once again feature the all-time greats Mike MikeMirzayanov Mirzayanov, Andrey andrewzta Stankevich, Michael Endagorion Tikhomirov, Gleb GlebsHP Evstropov, Artem VArtem Vasilyev, Ivan ifsmirnov Smirnov and other world renowned Russian coaches to train the participants.

We would also like to extend a welcome to some of the newest teams to join us from Colorado School of Mines, University of British Columbia and Reykjavík University.

Be sure to register before August 1st so everyone has time to get visas if needed, and of course for the Early Bird Discount of 15% or the Loyalty Discount* of 20% off registration for the boot camp!

*The loyalty discount is offered to universities and individual participants that took part in Hello Barcelona Bootcamps and Moscow Workshops ICPC.

Learn more about Barcelona ICPC Bootcamp

You can ask any questions by email: [email protected]

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 tribute_to_Ukraine_2022 7 159
2 hohomu 7 274
3 guille 7 338
4 radoslav11 7 580
5 waynetuinfor 6 148

Congratulations to the best hackers:

Rank Competitor Hack Count
1 halyavin 689:-132
2 2014CAIS01 91:-13
3 Al-Merreikh 20:-1
4 Ali_Pi 16:-3
5 gsparken 15:-3
978 successful hacks and 798 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A Harpae 0:01
B eddy1021 0:05
C tribute_to_Ukraine_2022 0:09
D BARPITF 0:09
E Roundgod 0:19
F radoslav11 0:15
G chemthan 0:28

UPD: The editorial is posted

Full text and comments »

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

By SirShokoladina, history, 6 years ago, translation, In English

Hello, everyone!

We are a Death Metal band Skyglow. Recently we released our first album. And since we happen to be sport programmers, we decided to make a Codeforces round in honor of this!

The round will take place on Jul/13/2018 17:35 (Moscow time). There will be five problems for each division, three of them will coincide. The problems were made up by me and rembocoder, the contest was also prepared with the help of TeaPot, slavik, mingaleg and niyaznigmatul. Thanks to demon1999 and winger for testing, our coordinator arsijo and, of course, MikeMirzayanov for Codeforces and Polygon platforms.

You can listen to the album by following the link:

It would be a great help if you repost us, even if you don't listen to this kind of music.

We will present an album on a CD to every contestant who expresses a wish. (If there are many of such, we will choose several of them with the best result in the round). Write me a private message.

Good luck on the contest!

UPD1. We will present an album on a CD to the top 10 contestants who would like to get one. Just send me a private message before the contest with your address, postal code and full name.

UPD2. Scoring distribution is as follows:
Div2: 500-1000-1500-2000-2500
Div1: 500-1000-1500-2250-2500

UPD3. We are still deciding if we should make this round rated or not. You can share your opinion about the round in the Mike's blog.

UPD4. We decided to sort the participants by the rating change. So the following users will receive a CD:
riela, +332
DongwonShin, +278
Erdenebayar, +176
DOlaBMOon, +148
Muhimin_Osim, +121
ciphereck, +117
Dotiros, +104
luismo, +94
MaxZubec, +72
whybee, +70

UPD5. Congratulations to winners!

Div1:

  1. yosupo
  2. Egor
  3. fateice
  4. Um_nik
  5. ksun48
  6. wxh010910
  7. zemen
  8. shpsi
  9. mareksom
  10. mmaxio

Div2:

  1. riela
  2. Kato_Megumi
  3. luis.trivelatto
  4. yukuai26
  5. _D41_
  6. gls1196
  7. TaoSama
  8. chenyuqi0215
  9. DearMargaret
  10. Rena_Takeda

UPD6. The editorial was published!

Full text and comments »

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

By MikeMirzayanov, 6 years ago, In English

Hello!

This time decided to fill myself in the shoes of the problem writers. It is very exciting! My challenge was to prepare a round in one day. It's really incredible pleasure to surrender to my passion and all day just work on problems!

Despite the fact that in total I've wrote 8 problems, I made it in time. Initially, I prepared 7 problems, but two of them were found to be used before (thank you, 300iq and cdkrot for poining it) and I removed them and wrote a new problem.

Codeforces Round 496 (Div. 3) will start on 09.07.2018 18:35 (Московское время). You will be offered 6 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. Probably, participants from the Div. 1 not be at all interested by this problems. And for 1600-1899 the problems will be quite easy. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 problems and 2 hours to solve them.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

  • take part in at least two rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Many thanks to the testers: kevinsogo, 300iq, cdkrot, arsijo and adedalic. You really helped to make this round!

Good luck!

UPD 1: The round is over. Thank you for participation!

Official Top-5 (trusted only)

Unofficial Top-5 (+ untrusted)

UPD 2: The editorial is available by the link.

Full text and comments »

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

By Nickolas, 6 years ago, In English

Microsoft's Quantum Team and Codeforces are excited to invite you to Microsoft Q# Coding Contest — Summer 2018!

The contest will run from July 6 — 9 and will consist of increasingly challenging tasks on introductory topics in quantum computing: superposition, measurement, oracles and simple algorithms. The top 50 ranked participants will receive a Microsoft Quantum T-shirt!

As a reminder, last weekend we help a warmup round with easier tasks which covered the same topics. The results were quite impressive: 167 participants solved all tasks! You can see the tasks here, and the solutions with explanations here.

Several useful reminders:

  • The contest is unrated.
  • Solutions are accepted in Q# only.
  • Participants are ranked according to the number of correctly solved tasks, with penalty time as a tiebreaker.
  • The tasks are grouped by topic, and the tasks within one topic are ordered in approximate order of increasing difficulty. If you find a problem too hard, don't forget to check the next problems in this topic and problems from different topics, they might turn out to be easier.
  • Unlike the warmup round, you're not allowed to discuss the tasks during the contest.
  • By popular demand, we have added Custom Invocation to allow you to run Q# code on Codeforces servers. Here is the signature of the code you should use to run it (note that the namespace and operation name have to match this code exactly):
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    // ------------- Operation which is called from C# -------------------
    operation RunQsharp () : Bool
    {
        body
        {
            Message("Hi");
            return true;
        }
    }
}
  • For tasks which require you to create a certain quantum state or to implement a unitary transformation, any kind of error gives verdict "Wrong Answer". For tasks which have classical return, I tried to differentiate verdicts "Wrong Answer" (your return value was incorrect) and "Runtime Error" (array index out of bounds, qubits released are not in zero state, oracle called too many times etc.).
  • NO PURCHASE NECESSARY. Must be 16 years of age or older. Game ends 7/9/18. For details, see Official Rules.

You can find the discussion of the warmup round and pointers to Q#/quantum computing materials here.

For first time Codeforces users:

  1. Create user account here.
  2. Register for the contest here.
  3. Once the contest starts on July 6, access the problems here.

Good luck! We hope you enjoy the contest!

Update. The contest is over. Editorials are published.

Full text and comments »

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

By arsijo, 6 years ago, translation, In English

Hi everybody!

Summer... It is a wonderful time for traveling, walking with friends, new discoveries and, of course, writing new exciting contests at Codeforces. Thus, I bring to your attention my new Codeforces Round #495 (Div. 2) with interesting tasks that will take place on Jul/05/2018 19:35 (Moscow time). If your rating is less than 2100, this round will be rated for you; otherwise, you can participate out of competition.

I would like to thank Mike MikeMirzayanov Mirzayanov for his help with problems preparing and for Codeforces and Polygon platforms. Also, Ildar 300iq Gainullin, Dmitry cdkrot Sayutin, Daniil danya.smelskiy Smelskiy, Chin-Chia eddy1021 Hsu, and Kevin ksun48 Sun for the problems testing.

You will be given 6 problems and 2 hours to solve them. Scoring distribution will be announced later.

In this round, you will have to help Sonya with her daily problems. Good luck!

UPD. Scoring 500-1000-1500-2000-2500-3000.

UPD. Congratulations to winners!!!!

Rank Nickname Score
1 EZ_fwtt08 7892
2 milisav 5550
3 VisJiao 5294
4 Jatana 4832
5 wasyl 4762

Full text and comments »

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