MikeMirzayanov's blog

By MikeMirzayanov, history, 9 years ago, translation, In English

The language of the round is Kotlin. Kotlin is a statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code. Its primary development is from a team of JetBrains programmers based in Saint Petersburg, Russia (the name comes from the Kotlin Island, near St. Petersburg).

Here is an example of the simplest program on Kotlin to print sum of two numbers:

fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(' ').map(String::toInt)
    println(x + y)
}

Here are some links to help you with Kotlin:

You can download standalone compiler (version 1.0.1) by the link http://s.codeforces.com/files/kotlin-compiler-1.0.1.zip Also you need JRE (virtual Java machine), you can find it by the link http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

The password from the archives with IDEA (IDE supporting Kotlin out of the box): c8bf9dd9b91ad9ff Links to IDEA are below or you can download it from the official website

Good luck!

====

UPD: You can predownload development pack (sorry, 300MB). In fact, you can take part without it — the Custom Invocation tab will be available during the contest. Also we will publish more compact tools 30 minutes before the start.

OS
Linux http://s.codeforces.com/files/683-linux.7z
Windows http://s.codeforces.com/files/683-windows.7z
Mac OS http://s.codeforces.com/files/683-macos.7z

All archives are encrypted. The password will be announced 30 minutes before the contest.

========

Surprise Language Round #8 will start on June 16, 16:00 (UTC). It will be unusual entertaining contest. Solutions on the only programming language will be allowed.

Thus, it is expected that during the round, participants can get acquainted with the language and solve a few simple problems. The language will be announced 30 minutes before the start of the round. At the same time (or earlier but encrypted archives) we will publish the archives with the tools to write programs in this language.

I am pleased to announce that the top 20 participants will receive an exclusive t-shirt, and another 10 random participants among those who solved at least three problems will receive an exclusive t-shirt too.

The rules of the contest are as follows:

  • The contest is unrated for everybody.
  • The round uses ACM ICPC rules: the standing is defined by the number of solved problems, ties are resolved based on penalty time. Initially the penalty is 0, and for each solved problem it is increased by submission time (since the start of the contest) + 20 minutes for each failed submission. The solution is considered to be correct if it passes all tests from a predefined test set; you know whether the solution is right immediately after sending it. There are no hacks.
  • The round will have 8-10 problems, sorted by estimated complexity, and you have 2 hours to solve it.
  • Solutions are accepted only in one language, which will be announced in 30 minutes before the contest.
  • Please reread this post at the beginning of the contest: we will announce the language and add instructions to install the compiler (the contest interface will provide an option to run your solutions online as well) and links to useful manuals. Other than that, learning the language is up to the competitor. You can use any resources to solve the problems (as long as you remember that this is an individual competition); you don't have to limit yourself to the manuals provided in the post.

Good luck!

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

| Write comment?
»
9 years ago, # |
  Vote: I like it +136 Vote: I do not like it

First SLR I'm eligible to participate in in 5 years.

9 am on a weekday in my time zone.

:-(

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

It is awesome that Surprise Language Round comes back since the previous Surprise Language Round was 21 months ago.

»
9 years ago, # |
Rev. 2   Vote: I like it -27 Vote: I do not like it

In fact, this contest is interesting, and I want to participant it.

My dream is going to get a T-Shirt. Can you pray for me?

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

Hi, I am new to CodeForces competitions, and this will be first one. Will the programming language be something completely new(like an unknown language)? Or will it be like a custom/madeup language?

thanks pimaster314

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

Tshirt! registered. :)

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

Really excited related to this contest, it will be fun to know a completely new language. Contest Like these makes coding and codeforces interesting.

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

Exclusive! Exclusive!. How this is exclusive?! Can we see it?

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

Not gonna lie, I registered for the T-shirts.

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

    Lol. I updated my Tshirt size, just in case ;-)

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

      LoL. Reminds me of the time when I hurried up in updating my Tshirt size after I won one. I never actually cared because I never though I'll get one ;)

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

        I never updated my T-shirt size on baylor site so I recieved an XL T-Shirt.
        I switched it with my team mate and he still doesn't know about it why did he got a XL T-shirt xD .

»
9 years ago, # |
Rev. 2   Vote: I like it -25 Vote: I do not like it

!!!

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

NO!!I haven't finished downloading it yet. Is there any way to get it faster?

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

First link, the wikipedia one, is broken I can't click on it, only copy and paste to address bar works.

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

which compiler should i select in custom test?

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

Kotlin? It seems that the next SLR is going to have C++ as the only language:) Btw, it surely will be a great surprise:)

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

    +1 This is so similar to Scala :/

    There isn't much of a surprise.

  • »
    »
    9 years ago, # ^ |
    Rev. 2   Vote: I like it +30 Vote: I do not like it

    +1

    They might be choosing Kotlin for introducing some harder task to SLR, but Kotlin is way too common (and too sane). Quite different from old SLRs by Nickolas.

    Well, next time you can do this for Rust, or Elixir, or whatever.

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

      Yeah, rust sounds pretty interesting.

  • »
    »
    9 years ago, # ^ |
    Rev. 2   Vote: I like it +45 Vote: I do not like it

    Kotlin is too common to be fair. People who are familiar with the language (or even with Java) has a clear advantage.

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

still cant figure out how to read input >_>

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

    Me too :(

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
       val (x, y) = readLine()!!.split(' ').map(String::toInt)
    

    this can solve the first problem,but i dont know how to read a string :(

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      var y = readLine()
      
      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Why var y = readLine()
        and not:
        val y = readLine()

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

          As I understand, we can't change the value of val

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

I am unable to compile my source code from given compiler. Any help?

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

    I guess you forget to add header files

    import java.util.*
    
»
9 years ago, # |
  Vote: I like it +4 Vote: I do not like it

I cant find any courses that tell me how to read a string or read input one by one:(

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

How to use the compiler? The IDE told me that I did not have Project SDK.

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

Random winners of 10 t-shirts will be determined using the following code (testlib is used). The code will be executed with two parameters in the command line: number of participants with at least 3 problems and penalty of the lowest among them.

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);

    int n = atoi(argv[1]);

    vector<int> places;
    for (int i = 21; i <= n; i++)
        places.push_back(i);
    shuffle(places.begin(), places.end());

    cout << "T-Shirt Random Winners:";
    for (int i = 0; i < 10; i++)
        cout << " " << places[i];
    cout << endl;
}
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

O(N lg K) was supposed to pass on G?

I got TLE on #21 :/

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

    You meant H? Not sure about O(NlgK), solved it with O(N).

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

      Yeah H, how in O(N).

      I used binary jumping for N lg K.

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

        Iterate over every student, build cycles for them — it is O(N)

        For every cycle get shift = K % cycle_len, for every student in cycle get his new book from (i — shift) pos in cycle (if lesser than 0 += cycle_len). It is O(N) too.

  • »
    »
    9 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Solved it with O(NlogK): 18526851. I'm guessing your solution is slower than mine because of large array.

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

      Ah! I made the mistake of storing the whole precalc table :/ Should have done it on the fly.

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

Ah, placed 25, so close.

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

What is wrong with this for C?

I get Runtime Error on test 17: 18529037

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

    You should try to write simpler code.

    http://codeforces.net/contest/683/submission/18525180

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

      I get it that this isn't the most elegant way to do it, but I had no idea about these contains functions, still what is wrong with my code? The thing I did was mostly straightforward, dont understand why it would get RE :/

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

        Probably, there were two consecutive space between numbers. You could filter them out or just don't convert a string to int: 18525267

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

        To add to what others have said, you read 2 chars per number, but the numbers can range from -1000 to 1000. So even if the input does not have consecutive spaces, you can end up with stringerA starting with a space, which then causes this exception. Even if it didn’t throw this exception though, you would still get a wrong answer because you’d parse the numbers wrongly.

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

Round is very interesting and educational.

Thank you.

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

I submitted solution for E, got TLE, so I decided to rewrite code from Java. I copy-pasted the Java code to the Kotlin file and IDEA asked: "Do you want to convert it to Kotlin code?". I clicked "Yes" and this way I got E accepted without writing a lot of Kotlin code. I wish I knew the copy-pasting rule from the beginning of the contest.

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

    Yea, sounds cheaty from the perspective of non-Java participant :)

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

      Definitely sounds like that. Before copy-pasting I was prepared for a long process of manual conversion from the language I knew into the language that I didn't know, so that wouldn't be so different if the source language was C++ (or any other language). The process would probably be errorprone and given the size of the SetWithCount class my initial thought was that the chances of successful conversion are slim but I had no better idea. After learning that one can convert code from Java to Kotlin I wrote solution to G in Kotlin without using Java. What's the fun of writing Java solution when it is a Kotlin contest?

      Anyway, the "conversion from Java to Kotlin" message was the big "WTF?!!! I was browsing the Reference manual for two hours, while I could have just written everything in Java and then convert?", so I guess the language wasn't the only surprise for me in this contest:)

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

Heh, before this round, I've just thought, "the author seems to be Mike, so it may be a way to battle-test a new language for regular rounds".

Will Kotlin be available for common rounds now as well?

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

Did someone used "Convert from java" button of http://try.kotlinlang.org/#/Examples/ ?

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

Do I get something wrong about J, or it is easier than I?

In J you don't have to find a minimal path, so you can just blow every single wall and exit. 100k actions is more than enough for that.

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

As a developer working on Kotlin at JetBrains, I'd like to present my solutions for today's problems (except H), maybe they will be of use for someone. (UPD: I did not take part in the round.)

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

    Your B solution looks great. I see that I could have just sorted the students instead of using HashMap<Int, MutableMap<String, Int>>. Such an overkill:) I had a lot of trouble with trying to use Map.computeIfAbsent, because IDEA kept coloring it red, and I finally gave up and used temporary variables. What I wanted to do:

    val s: NavigableMap<Int, Map<String, Int>> = TreeMap()
    val z = s.computeIfAbsent(height, { k -> HashMap() })
    z.put(name, z.getOrDefault(name, 0) + 1)

    Is there a way to use computeIfAbsent (or getOrElse or getOrPut or something else) to achieve the same effect without using temporary variables?

    • »
      »
      »
      9 years ago, # ^ |
      Rev. 2   Vote: I like it +3 Vote: I do not like it

      computeIfAbsent is not available in kotlin.Map currently because it breaks variance of Map's generic type parameters. I believe this is being discussed and worked on currently (link).

      I don't think there's a nice way to write this without using temporary variables :) I can only suggest something like the following:

          val s: NavigableMap<Int, MutableMap<String, Int>> = TreeMap()
          s.getOrPut(height) { HashMap() }.let { map ->
              map[name] = (map[name] ?: 0) + 1
          }
      
  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You don’t need the last capitalize call in F, do you?

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

      You're right, it's not needed. I've updated the solution. Thanks!

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

For problem I, I noticed something strange in some accepted solutions:

I thought we needed to minimize the number of pushes. It seems they are printing three pushes, while the optimal solution is only one push.

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

    Can you please share the submission id?

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

    Oh, it seems it is my bug. Thanks. And I did it 12 years ago!

    The problem is from Saratov local contest of 2004.

    BTW, it is fixed. We will not rejudge contest solutions, but all other solutions have been rejudged.

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

Regarding the language, I have one feedback comment for now.

When I want a specific construct, I usually Google for it. For the things in the standard library (for example, set or regular expressions), the first link usually invites to read the official API Reference. Its pages list all methods, but I didn't find any single example each time I got there. And it is hard(er) to learn using a construct without an example readily available. So, I usually scrolled the Google results down to find the first link to StackOverflow, and it helped.

The point is, for a new user, it would be nice if the examples came on the first link from a respective Google search. If that link is usually API Reference, it would be nice to have examples right in the API Reference.

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

Kotlin was indeed a fun language (no pun intended)