By JetBrains, 22 months ago,

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 • +280  » 22 months ago, # | ← Rev. 3 → 0 Hmmm,a contest after a long time! •  » » 22 months ago, # ^ | +44 Did you not read that it's unrated? •  » » » 22 months ago, # ^ | -10 Thanks, edited  » 22 months ago, # | +13 Hack for Java programmers Setup IntelliJ Code your solution in Java. Convert it to Kotlin. •  » » 22 months ago, # ^ | +43 It is not a hack. It is implemented to simplify Kotlin learning for Java developers. I also mention it in the official tutorial that you are quite welcome to read: https://kotlinlang.org/docs/tutorials/competitive-programming.html •  » » » 21 month(s) ago, # ^ | -16 In contest Java user will have benefits :( •  » » » » 21 month(s) ago, # ^ | -36 User can directly submit java solution and win contest •  » » » » 21 month(s) ago, # ^ | +35 Come to think about the benefit Kotlin users will have! :) •  » » » » » 21 month(s) ago, # ^ | -24 I mean that contestant can write solution after he can convert solution to kotlin and win a contest :) •  » » » 21 month(s) ago, # ^ | 0 Thanks for the article.Here is a bunch of helper input reading functions that extend those examples for reading different types, lists and arrays, etc: https://stackoverflow.com/questions/41283393/reading-console-input-in-kotlinHope that in some future Kotlin release stdlib would comprise something similar in addition to sole readLine().  » 22 months ago, # | +15 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.  » 22 months ago, # | +12 Would even use it as a main language immediately if creating a n-matrix is easier in Kotlin :'( . •  » » 21 month(s) ago, # ^ | +15 That's coming in the near future, but voting for it would still help: https://youtrack.jetbrains.com/issue/KT-26577 •  » » 21 month(s) ago, # ^ | 0 I regulary use following function:  inline fun arrOf(size:Int, init:(Int)-> E ):Array { val a= arrayOfNulls(size) for(i in a.indices) a[i]=init(i) return a as Array } Use it like:  // example of 3-dimensional array of Long val NMAX=200 val dp = arrOf(NMAX) { arrOf(NMAX) { LongArray(NMAX) }}  •  » » » 21 month(s) ago, # ^ | +42 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) }}}   » 21 month(s) ago, # | +1 It seems that all solutions are closed. Or am I wrong? I tried to open solution of problem A and couldn't do it. •  » » 21 month(s) ago, # ^ | +20 Fixed. Open now.  » 21 month(s) ago, # | 0 What about Kotlin input\output speed? What tools should be used to do it fast? •  » » 21 month(s) ago, # ^ | 0 I'd like to see the comparison of the Kotlin performance (with these wow-features) vs. other languages. Syntactic sugar is good for developing, but often causes TLE on contest tasks. As I experienced, even a simple using of streams in Java may just kill your solution. •  » » » 21 month(s) ago, # ^ | 0 You are welcome to read tutorial. I've explicitly covered input/output there. https://kotlinlang.org/docs/tutorials/competitive-programming.html I'd be happy if you do measurement and share them here, too. •  » » 21 month(s) ago, # ^ | 0 You can code literally in Java, with some syntax exceptions like int[] -> IntArray.For IO, use BufferedReader, StringTokenizer and PrintWriter. •  » » » 21 month(s) ago, # ^ | +12 You can, but idiomatice Kotlin code really looks nicer and requires less code to write. I would recommend to read tutorial on that: https://kotlinlang.org/docs/tutorials/competitive-programming.html  » 21 month(s) ago, # | 0 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. •  » » 21 month(s) ago, # ^ | +8 I think Kotlin is a language for industry, not for programming contests :) It would be nice to maintain a succinct standard library ;) •  » » 21 month(s) ago, # ^ | +10 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.  » 21 month(s) ago, # | +27  » 21 month(s) ago, # | -44 Rated or Unrated? •  » » 21 month(s) ago, # ^ | -8 Unrated  » 21 month(s) ago, # | -9 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  » 21 month(s) ago, # | +13 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? •  » » 21 month(s) ago, # ^ | +18 Razor •  » » 21 month(s) ago, # ^ | 0  » 21 month(s) ago, # | 0 any useful website where i can get all syntax related info like a cheatsheet? •  » » 21 month(s) ago, # ^ | +3 Basic Syntax is a good place to start from.  » 21 month(s) ago, # | +9 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: Java vs Kotlin Java vs Kotlin (graph problem) I think Kotlin's extension methods can be very helpful in competitive programming.  » 21 month(s) ago, # | +11 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.  » 21 month(s) ago, # | -28 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 ? •  » » 21 month(s) ago, # ^ | +20 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. •  » » 21 month(s) ago, # ^ | +1 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.  » 21 month(s) ago, # | +15 rng_58 btw please update kotlin in atcoder •  » » 21 month(s) ago, # ^ | +1 Why downvotes? Today I tried kotlin in beginner contest got 7 unsuccessful submissions because of language version  » 21 month(s) ago, # | +44 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. •  » » 21 month(s) ago, # ^ | +5 Maybe... that IS what they mean. You're just ASSUMING that you aren't allowed to use other languages. •  » » 21 month(s) ago, # ^ | 0 It is what it is. Only Kotlin allowed to use you are. :) •  » » 21 month(s) ago, # ^ | -49 Actually, it doesn't. It means you are only allowed to use Kotlin. •  » » » 21 month(s) ago, # ^ | 0 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. •  » » » » 21 month(s) ago, # ^ | ← Rev. 2 → -19 Nvm, I thought he was complaining about the first phrase, not the second one. Reading while asleep 101. ¯\_(ツ)_/¯ •  » » 21 month(s) ago, # ^ | +20 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. •  » » » 21 month(s) ago, # ^ | ← Rev. 2 → +10 Thanks, fixed.  » 21 month(s) ago, # | -29 why the contest is unrated?? •  » » 21 month(s) ago, # ^ | +8 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.  » 21 month(s) ago, # | ← Rev. 3 → +3 Top three winners will get prizes of 512, 256, and 128 dollars, then participant in $i$-th place would get $2^{10-i}$ dollars? •  » » 21 month(s) ago, # ^ | ← Rev. 3 → +16 If so, I would get 0.006103515625 cents.  » 21 month(s) ago, # | +26 Traditionally, we publish algorithm of selecting random winners before the round.randgen.cpp #include "testlib.h" #include 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 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. •  » » 21 month(s) ago, # ^ | ← Rev. 2 → +11 [EDIT] — Nvm, I was getting seg fault because of alias set on my system. •  » » » 21 month(s) ago, # ^ | ← Rev. 2 → +8 According to this seed(398) and len(824) value, these are the winners 77 , 133 , 135 , 145 , 162 , 165 , 175 , 181 , 197 , 200 , 211 , 212 , 221 , 234 , 236 , 262 , 270 , 300 , 344 , 347 , 348 , 360 , 378 , 380 , 384 , 398 , 458 , 481 , 494 , 537 , 554 , 578 , 580 , 581 , 583 , 639 , 646 , 666 , 676 , 690 , 703 , 721 , 745 , 760 , 774 , 783 , 787 , 811 , 835 , 854 •  » » » » 21 month(s) ago, # ^ | 0 Is this the reel results? •  » » » » » 21 month(s) ago, # ^ | 0 Yes you can see the comment by Mike below •  » » » 21 month(s) ago, # ^ | +3 the total penalty best participant s? •  » » 21 month(s) ago, # ^ | +16 How are ties broken? •  » » » 21 month(s) ago, # ^ | 0 very curious too • » » 21 month(s) ago, # ^ | Rev. 2 +54 I'm glad to announce the winners (tie are resolved by last accepted submission time as in ICPC): Place Name 1 Petr 2 ecnerwala 3 eatmore 4 tourist 5 ko_osaga 6 Golovanov399 7 uwi 8 Deemo 9 betaveros 10 aid 11 majk 12 300iq 13 tiansu 14 Heltion 15 Quang 16 SYury 17 moss3s 18 niyaznigmatul 19 DmitryGrigorev 20 teleport 21 knightL 22 khsoo01 23 Smoge 24 WaterColor2037 25 Romka 26 Subconscious 27 vadimmm 28 ErdemKirez 29 final_child 30 Jatana 31 CrafterKolyan 32 nk.karpov 33 mariand 34 shilov 35 gs12117 36 darnley 37 Mjgonzales 38 xiaowuc1 39 Kurpilyansky 40 webmaster 41 pitfall 42 ekzhang 43 Nebuchadnezzar 44 armoking 45 LamoreauxAJ 46 NighTurs 47 marat.snowbear 48 J.T.J.L. 49 bicsi 50 arknave 77 ggawryal 133 yakamoto 135 n3o59hf 145 icypiggy 162 blole 165 yevhenii_kanivets 175 stanm 181 viper509 197 bohuss 200 algmyr 211 baolidakai 212 ibrahim_habib 221 avankyankit 234 simonm 236 procrastinate7 262 ac517 270 OceanDiver 300 Mohamed.Sobhy 344 albert0s 347 mdg 348 kuribohwithwingss 360 miniac 378 DarkElf 380 ncls.m 384 RNR 398 RenbouPufel 458 pie_flavor 481 cavi4762 494 fridon 537 vivace1 554 Tijee 578 sevlll 580 CoubeX 581 flaviu2001 583 rahulg96 639 piyz 646 epicurean 666 clovis-ai 676 Rdpaula 690 southforwinter 703 omeravci372742 721 bugdone 745 ahmat 760 fc-lib-xyz 774 DeividasM 783 gtx1080 787 nable0111214292 811 nightcode 835 cly753 854 luiX •  » » » 21 month(s) ago, # ^ | -7 I am 580 place too :( •  » » » 21 month(s) ago, # ^ | +9 I missed a tshirt by 5 secs :( •  » » » 21 month(s) ago, # ^ | +11 I'm stoked. I think it's the first time I win something lol. •  » » » 21 month(s) ago, # ^ | +9 wow! •  » » » 21 month(s) ago, # ^ | +3 When will we receiving our t-shirts? •  » » » » 21 month(s) ago, # ^ | +7 Hello! T-shirts will be manufactured and shipped when all the winners fill in the full relevant information (for that they have one more day). •  » » » » » 20 months ago, # ^ | 0 Do you have any news about the T-shirt? •  » » » » » » 20 months ago, # ^ | +6 T-shirts are produced now. But we will try our best that all the winners get their prizes as soon as possible. •  » » » » » » » 20 months ago, # ^ | -7 Any updates?? •  » » » » » » » 20 months ago, # ^ | +13 I got my T-shirt but without exclusive badge. Do I get it with another parcel? •  » » » » » » » » 19 months ago, # ^ | 0 Do you know where is the T-shirt being shipped from? Did you get a tracking number for yours CrafterKolyan? •  » » » » » » » » » 19 months ago, # ^ | 0 Yes, from Saratov. I did get my tracking number. I've already received a parcel but without Kotlin Badge. •  » » » » » » » » » 19 months ago, # ^ | 0 Hmmm. I didn't get a tracking number yet. But I am in the US, I looked up what it costs to ship from US to Russia figuring it'll be about the same the other way, yeah its like$70, worth more than the T-Shirt about 7x. But I did find out its illegal, among other things, to mail things from here to Russia, I kid you not, containing "Information about the Earth’s interior."Apparently my government really doesn't want you guys to know there be elves down there.
•  » » » » » » » » » 19 months ago, # ^ |   0 Canada, and got the tracking number a few days ago.
•  » » » » » » » » » 19 months ago, # ^ | ← Rev. 2 →   0 Hmm, I searched my Inbox and Spam and couldn't find it. It came from codeforces.com?You Deemo and CrafterKolyan are in top 50, I am in the raffle bottom 50, maybe they send those out later.Maybe Una_Shem knows.Thanks.
•  » » » » » » » » » 19 months ago, # ^ |   0 No problem. They send you a message on Codeforces. It's hard to miss.
•  » » » » » » » » 19 months ago, # ^ |   0 Hello! Sorry for the late reply. Yes, badges will be sent later.
•  » » » » » » » » » 19 months ago, # ^ |   0 Hi, I was in the raffle bottom 50 who won a T-shirt, but I didn't get a tracking number or a t-shirt yet, have they all been sent out yet? I made sure my address was filled out in CF the day I won.
•  » » » » » » » » » 19 months ago, # ^ |   +8 I have received my t-shirt.
•  » » » » » » » » » 19 months ago, # ^ |   +8 That's good news! Hope to see you taking part in the next contests! :)
•  » » » » » 19 months ago, # ^ |   0 It appears that my package has gotten stuck somewhere in the process (according to my tracking link, the last update was about 2 weeks ago that it passed customs in the US, but I have heard no further news nor received anything locally to indicate it has been delivered). Is this expected?
 » 21 month(s) ago, # |   -41
 » 21 month(s) ago, # |   -51
 » 21 month(s) ago, # | ← Rev. 4 →   +2
•  » » 21 month(s) ago, # ^ |   +10 I think, you wouldn't be.
 » 21 month(s) ago, # |   +5 I needed another minute for F 54766100I'm 54th.Kill me
•  » » 21 month(s) ago, # ^ |   +5 I had to leave contest 30 minute early and was almost done with F... I'm 51st. Kill me
 » 21 month(s) ago, # |   +32 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?
•  » » 21 month(s) ago, # ^ |   0 I doubt it; my Array>.sortWith(compareBy(...)) worked fine in B.
•  » » » 21 month(s) ago, # ^ |   +27 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.
•  » » » » 21 month(s) ago, # ^ |   0 Oof
•  » » 21 month(s) ago, # ^ |   0 Your guess is correct. Same for me. TL 45 54766357 AC 54766461
•  » » 21 month(s) ago, # ^ |   0 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.
•  » » » 21 month(s) ago, # ^ |   +35 It would be nice if they put in reference time complexity and which algorithm is used like in C++ reference.
•  » » » » 21 month(s) ago, # ^ |   +9
 » 21 month(s) ago, # |   0 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?
•  » » 21 month(s) ago, # ^ |   +13 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).
•  » » » 21 month(s) ago, # ^ |   0 Understood, thanks for the clarification.
•  » » 21 month(s) ago, # ^ |   +36 I used the problems from other rounds to make the practice contest, you solved them previously.
•  » » » 21 month(s) ago, # ^ |   +12 Yes I didn't realize that, thanks.
•  » » 21 month(s) ago, # ^ |   +6 Those problems are taken from other contests you may have solved previously, if you open a task you may recognise it.
•  » » » 21 month(s) ago, # ^ |   0 Yes, I just checked it and realized I have solved em early. Thanks.
 » 21 month(s) ago, # |   +11 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 :(
•  » » 21 month(s) ago, # ^ |   0 Same here, lol.I have been confused about it for about 15 minutes, and barely got it by asking the question.
 » 21 month(s) ago, # |   0 Why is system testing of practice round still not over?
 » 21 month(s) ago, # |   0 MikeMirzayanov elizarov It would be great if we could now make submissions for the contest in other programming languages to compare performance against Kotlin.
 » 21 month(s) ago, # |   +18 Is there a way to get a tracking number for the shirt delivery?
•  » » 21 month(s) ago, # ^ |   +15 You will receive the tracking number automatically within several days after sending.
•  » » » 21 month(s) ago, # ^ |   +18 Cool. Thanks!
 » 21 month(s) ago, # |   -10 Will there be another contest like this ?
 » 17 months ago, # |   0 Could you please open virtual participation for Practice 1 and Practice 2 contests?
 » 10 months ago, # |   0 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.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.
•  » » 10 months ago, # ^ |   0 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.
 » 10 months ago, # |   0