By MikeMirzayanov, 35 hours 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.

Read more »

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

By Chilli, history, 2 days 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.

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.

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): http://codeforces.com/contest/264/problem/C
Solution with unordered_map: http://codeforces.com/contest/264/submission/40542899 (TLE on test case 8)
Solution with policy hash table directly substituted in: http://codeforces.com/contest/264/submission/40573491 (TLE on test case 26)
Solution with unordered_map, rewritten to not use clears: http://codeforces.com/contest/264/submission/40590437 (TLE on test case 26) Solution with policy hash table and rewritten to not use clears: http://codeforces.com/contest/264/submission/40574196 (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) { return hash<int>{}(x ^ RANDOM); }
};
gp_hash_table<key, int, chash> table;

Thanks to adamant for his post that revealed to me the existence of policy data structures, and thanks to tonynater 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, use typedef cc_hash_table< int, int, hash<int>, equal_to<int>, direct_mask_range_hashing<int>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;, and you should be able to resize and set load factor manually as well.

Code for the benchmarks can be found here: https://ideone.com/ZkNMbH

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.

Read more »

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

By Gassa, history, 3 days 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!

Read more »

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

By Vovuh, history, 8 days 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 PikMike Piklyaev, Maksim Ne0n25 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 HighPressure 6 236
2 LividFox 6 237
3 Rzuji 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 ducdien2267 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 thidailoc 0:07
D MoreThanANoob 0:23
E Student_of_Husayn 0:07
F NoTrolleNoLife 0:18

UPD3: Editorial is published.

Read more »

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

By PikMike, history, 10 days 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 Ne0n25 Mescheryakov, Aslan ag2cidk 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: hello@harbour.space

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 e-pluszak 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 Marcel_Ib 20:-1
4 Ali_Pi 16:-3
5 20180616sG 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 AuroraGarden 0:01
B eddy1021 0:05
C e-pluszak 0:09
D hmc 0:09
E Roundgod 0:19
F radoslav11 0:15
G chemthan 0:28

UPD: The editorial is posted

Read more »

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

By SirShokoladina, history, 2 weeks 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 SirRembocodina, the contest was also prepared with the help of TeaPot, GrumpyKitten, 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
Oliveira_medalha_de_ouro, +104
luismo, +94
zubec, +72
yagyanshbhatia, +70

UPD5. Congratulations to winners!

Div1:

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

Div2:

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

UPD6. The editorial was published!

Read more »

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

By MikeMirzayanov, 2 weeks 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 _kun_ for poining it) and I removed them and wrote a new problem.

Codeforces Round #496 (Div. 3) will start on Jul/09/2018 18: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 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, _kun_, 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.

Read more »

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

By Nickolas, 3 weeks 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.

Read more »

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

By arsijo, 3 weeks 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 _kun_ 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

Read more »

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