By JetBrains, 6 years ago, In English

Hello, Codeforces!

We are happy to announce that in partnership with Codeforces to promote Kotlin programming language we are launching a series of "Kotlin Heroes" programming contests.

Kotlin programming language was introduced by JetBrains in 2011 and reached its first stable version 1.0 in 2016. The current language version is 1.3.31. The language is focused on solving the needs of application developers in various domains. Kotlin is a statically typed language that is designed for writing concise code, with less ceremony and more substance in it, and to scale from applications of just a few lines long to multi-million-lines projects.

While not being specifically designed for competitive programming, it incidentally fits well in this domain, reducing the typical amount boilerplate that a programmer needs to write and read while working with the code almost to the level offered by dynamically-typed scripting languages, while having tooling and performance of a statically-typed language.

The first "Kotlin Heroes" competition will be hosted at Codeforces platform on May/28/2019 17:35 (Moscow time). The contest will last 2 hours 30 minutes and will feature a set of problems from simple ones, designed to be solvable by anyone, to hard ones, to make it interesting for seasoned competitive programmers. Top three winners will get prizes of $512, $256, and $128 respectively, top 50 will win a Kotlin Heroes t-shirt and an exclusive Kotlin badge, competitors solving at least one problem will enter into a draw for one of 50 Kotlin Heroes t-shirts.

The round is held in accordance with slightly modified ICPC rules:

  • The round is unrated.
  • The contest will have 6-10 problems of various levels of complexity.
  • You are only allowed to use Kotlin to solve these problems.
  • Participants are ranked according to the number of correctly solved problems.
  • Ties are resolved based on the lowest total penalty time for all problems, which is computed as follows. For each solved problem, a penalty is set to the submission time of that problem (the time since the start of the contest). An extra penalty of 10 minutes is added for each failed submission on solved problems (i.e., if you never solve the problem, you will not be penalized for trying that problem).

Registration is already open and available via the link. It will be available until the end of the round.

REGISTER →

To help you get familiar with Kotlin we have prepared a tutorial on competitive programming in Kotlin and a practice round, where you can try to solve a few simple problems in Kotlin. All solutions are open, it means that you can look at a solution even if you haven't solved a problem yet. The practice round is available by the link.

We wish you luck and hope you enjoy Kotlin.

UPD 1: Many thanks to the testers elizarov, Benq, cdkrot, nhho, ksun48. Also KAN helped a lot with suggestions to the problems. And to all the participants warm greetings from authors MikeMirzayanov, vovuh, adedalic and pashka — they invented and prepared the problems for you!

Announcement of Kotlin Heroes: Episode 1
  • Vote: I like it
  • +280
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Hmmm,a contest after a long time!

»
6 years ago, # |
  Vote: I like it +13 Vote: I do not like it
Hack for Java programmers
»
6 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Btw, you are also welcome to join the Slack channel for discussion. Use http://slack.kotl.in to get an invite and join #codeforces channel. That would be the best place to ask questions about Kotin's use at Codeforces.

»
6 years ago, # |
  Vote: I like it +12 Vote: I do not like it

Would even use it as a main language immediately if creating a n-matrix is easier in Kotlin :'( .

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    That's coming in the near future, but voting for it would still help: https://youtrack.jetbrains.com/issue/KT-26577

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I regulary use following function:

        inline fun <reified E> arrOf(size:Int, init:(Int)-> E ):Array<E> {
            val a= arrayOfNulls<E>(size)
            for(i in a.indices)
                a[i]=init(i)
            return a as Array<E>
        }
    

    Use it like:

        // example of 3-dimensional array of Long
        val NMAX=200
        val dp = arrOf(NMAX) { arrOf(NMAX) { LongArray(NMAX) }}
    
    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it +42 Vote: I do not like it

      Why would you define it yourself? There is a Array function in the standard library that does the same:

      val NMAX = 200
      val dp = Array(NMAX) { Array(NMAX} { LongArray(NMAX) }}}
      
»
6 years ago, # |
  Vote: I like it +1 Vote: I do not like it

It seems that all solutions are closed. Or am I wrong? I tried to open solution of problem A and couldn't do it.

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

What about Kotlin input\output speed? What tools should be used to do it fast?

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey, JetBrains, ever thought of adding CP-algorithms classes to the language itself? Like almost copy-and-paste from there.

That would cause a nice butthurt from the community of competitive programmers.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I think Kotlin is a language for industry, not for programming contests :) It would be nice to maintain a succinct standard library ;)

  • »
    »
    6 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Most of them are extremely domain-specific. Kotlin is a general-purpose application development language, so the goal of Kotlin standard library is provide a set of basic primitive and algos for a wide range of uses and also ensure that they are not single-purpose but composable. However, one of the reasons to host these Kotlin Heros series of contests on Codeforces is to gather feedback from sports programming community. We do hope that some things that are useful here might be useful elsewhere, too.

»
6 years ago, # |
  Vote: I like it +27 Vote: I do not like it

»
6 years ago, # |
  Vote: I like it -44 Vote: I do not like it

Rated or Unrated?

»
6 years ago, # |
  Vote: I like it -9 Vote: I do not like it

I've heard of the language, but this was a good opportunity to give it an actual chance. I actually really love it so far! I've only done 1 problem, but writing functional code is so much funner than writing normal code. Plus, you've gotta love functions like joinToString... every time I print something out in java I need an edge case at the start or end so there isn't extra whitespace. 10/10, it's like python in java

»
6 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Speaking of JetBrains contests, what was the answer to the question:

Last year, a renowned painter's monument in London had three items taken out for safety. What was the sharpest one?

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

any useful website where i can get all syntax related info like a cheatsheet?

»
6 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Thanks for the post, it's great to see Kotlin in competitive programming!

I have recently taken a look to Kotlin after hearing from few folks. Watched a bit of coursera course on Kotlin, then talked to Jetbrains people on Devox UK 2 weeks ago, and attended a session in the conference on its advanced features. As a Java Engineer, I find it "nice Java" with built-in lombok :) and I think it has great future with its first class support for Android, upcoming iOS development with Kotlin, running on JVM, Kotlin native, compiles to Javascript and so on.

About a week or so ago, I decided to give it a go and start my first program in Kotlin and thought solving some problems in codeforces offline might be a good idea. And I solved some problems both in Java and Kotlin to see the difference on performance, memory and code length. In terms of code length, it's much much shorter than Java like 19-20 lines of code for a graph problem which is great! In regards to performance, it was less performant than Java, maybe I'm using my own readers/writers and primitives with Java, but with Kotlin more like functional programming. Not sure how would Java Stream API compare to it, I normally avoid them in contests. Below few examples of solutions to the same problems in Java and Kotlin:

I think Kotlin's extension methods can be very helpful in competitive programming.

»
6 years ago, # |
  Vote: I like it +11 Vote: I do not like it

I tried switching to Kotlin for 90 days recently. I've noticed that my productivity has improved as well as my motivation and concentration levels. I also now feel more confident around programmers. I'm convinced that everyone should try it.

»
6 years ago, # |
  Vote: I like it -28 Vote: I do not like it

Please make program language that suits to CP.

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

Why I need additional functions again ?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +20 Vote: I do not like it

    Why a language specifically targeted to CP shall exist? Maintaining language and tools around it is a lot of effort that is worth doing only for big numbers of users. Kotlin is a pragramtic language for application developers so it would be strange if it had functions specifically for reading CP-style input which you would not find outside of CP.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Probably, it is the task for a platform to provide the some IO code/module. This was one of the ideas I liked in topcoder (and, probably, in HackerRank). Though the implementation in former case was not very successful.

»
5 years ago, # |
  Vote: I like it +15 Vote: I do not like it

rng_58 btw please update kotlin in atcoder

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Why downvotes? Today I tried kotlin in beginner contest got 7 unsuccessful submissions because of language version

»
5 years ago, # |
  Vote: I like it +44 Vote: I do not like it

The description should say "You are only allowed to use Kotlin", not "You are allowed to only use Kotlin". As it is now, it is implying that we might be able to use any language we want, and also that we will not be forced to use languages other than Kotlin.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Maybe... that IS what they mean. You're just ASSUMING that you aren't allowed to use other languages.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It is what it is. Only Kotlin allowed to use you are. :)

  • »
    »
    5 years ago, # ^ |
      Vote: I like it -49 Vote: I do not like it

    Actually, it doesn't. It means you are only allowed to use Kotlin.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I don't think it matters or is important but yes it certainly does.

      "You are allowed to only use Kotlin" means that you have a right to use Kotlin, but doesn't restrict other programming languages.

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it -19 Vote: I do not like it

        Nvm, I thought he was complaining about the first phrase, not the second one. Reading while asleep 101. ¯\_(ツ)_/¯

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +20 Vote: I do not like it

    Not fond of this kind of discussion (being a mathematician on linguistics), but I do think the first comment has the point.

    Consider the following sentences (equivalent, apart from the definition of the word vegan).

    You are allowed to only eat vegetables. You are allowed to go vegan.

    In the same way:

    You are allowed to only use Kotlin. You are allowed to go with a Kotlin-only policy.

    Everybody but please don't do this offline, it embarrasses others.

»
5 years ago, # |
  Vote: I like it -29 Vote: I do not like it

why the contest is unrated??

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Because you have to use Kotlin, so a lot of the contest tests your familiarity with Kotlin, rather than your ability to solve problems in the language of your choice. How well you perform in this contest is not a good indicator of how well you will perform in a usual CF contest.

»
5 years ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it

Top three winners will get prizes of 512, 256, and 128 dollars, then participant in $$$i$$$-th place would get $$$2^{10-i}$$$ dollars?

»
5 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Traditionally, we publish algorithm of selecting random winners before the round.

randgen.cpp

#include "testlib.h"
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
    int seed = atoi(argv[1]);
    int len = atoi(argv[2]);
    int nwinners = 50;
    rnd.setSeed(seed);
    
    set<int> winners;
    while (winners.size() < nwinners)
        winners.insert(50 + rnd.next(1, len));
    
    for (auto winner: winners)
        cout << winner << " ";
    cout << endl;
}

The seed will be the total penalty best participants of this contest, the parameter length will be the total number of participants solved at least one problem minus 50.

»
5 years ago, # |
Rev. 4   Vote: I like it +2 Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I needed another minute for F 54766100

I'm 54th.

Kill me

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    I had to leave contest 30 minute early and was almost done with F... I'm 51st. Kill me

»
5 years ago, # |
  Vote: I like it +32 Vote: I do not like it

What's the reason for TL 45 in F? My only guess is that it is because LongArray.sort() works in $$$O(n^2)$$$ just like in Java. But why include such tests in Kotlin-only contest?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I doubt it; my Array<Pair<Int, Int>>.sortWith(compareBy(...)) worked fine in B.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +27 Vote: I do not like it

      Well, in Java arrays of objects are sorted in $$$O(n\log(n))$$$ with merge sort and only arrays of primitive type are sorted with bad quick sort.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Your guess is correct. Same for me.
    TL 45 54766357
    AC 54766461

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I used .sorted() and it worked fine. Is there any Kotlin sort function that is $$$O(n^2)$$$? I thought Kotlin sorts are fine, but I don't have proof.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +35 Vote: I do not like it

      It would be nice if they put in reference time complexity and which algorithm is used like in C++ reference.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

cf-Error
Can someone explain this?
I haven't solved even a single question, in fact I don't even know Kotlin programming language.
If I go to "My submissions" section of the contest, there are no submissions (which makes it clear that my account wasn't hacked).
Is it a bug? Am I the only person who is facing it?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    The problems are all reused from old contests, so if you've solved it in the old contest, the it still counts as "solved" (just like Div 1 and Div 2 sharing problems).

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Understood, thanks for the clarification.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +36 Vote: I do not like it

    I used the problems from other rounds to make the practice contest, you solved them previously.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +12 Vote: I do not like it

      Yes I didn't realize that, thanks.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    Those problems are taken from other contests you may have solved previously, if you open a task you may recognise it.

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, I just checked it and realized I have solved em early. Thanks.

»
5 years ago, # |
  Vote: I like it +11 Vote: I do not like it

I spent a good 2 hours understanding problem E, only to realize the compartments having the door are closed, not opened.

There goes the T-shirt :(

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Same here, lol.

    I have been confused about it for about 15 minutes, and barely got it by asking the question.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is system testing of practice round still not over?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

MikeMirzayanov elizarov It would be great if we could now make submissions for the contest in other programming languages to compare performance against Kotlin.

»
5 years ago, # |
  Vote: I like it +18 Vote: I do not like it

Is there a way to get a tracking number for the shirt delivery?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    You will receive the tracking number automatically within several days after sending.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

hey elizarov, the only concern I feel right now with kotlin for CP is the huge runtime. I would love to read about the reason behind it, I felt it shouldn't be much different from JAVA yet we can see a huge difference between them.

I understand in CP the time will be adjusted based on the language but a general curiosity. Asgar has posted his solution in both java and kotlin and we can see a difference of more than 600ms.

java & kotlin

java & kotlin

I have observed the same while practising problems in kotlin on other platforms too.

Just want to know the theory behind it. And are there any plans in tackling them, and also will it effect products in real life which may require heavy computations.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    These submissions have completely different code so it's no surprise they take different time to run. As an exercise, you can convert Java code to Kotlin to see that it gets the same runtime and vice-versa (this conversion can even be done mostly automatically by IDEA!), and you can also convert Kotlin code Java and it will, again, have the same runtime.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it