hulm's blog

By hulm, history, 15 months ago, In English

Good morning/afternoon/evening/night dear codeforces community!

I have been learning Go language to start developing in Back-end, so I decided to practice it by solving simple problems from codeforces. However, I am facing a problem in this problem. Initially I implemented sorting by my own comparator to sort the paired(implemented via struct) array. However I got TLE. After that, I implemented merge sort by my own, and even after this I got TLE again. I thought that problem was in binary seacrh(maybe I write something wrong), so I replaced it with two-pointers method. Unfortunately I got TLE again. Can you tell me, is it possible to get "Accepted" in this problem using Golang?

The final version of code is right here -> https://mirror.codeforces.com/problemset/submission/580/226466440

Thanks for your consideration.

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

»
15 months ago, # |
  Vote: I like it +24 Vote: I do not like it

As in many languages the easiest way to do IO isn't the fastest.

226471399 is your first version with the input done using bufio.scanner (140ms). There are further optimizations possible involving scanner.Bytes() instead of scanner.Text().

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Very BIG thanks. You helped me a lot.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Your method allows to input data only separated by a line. I want to read an array in one line, is there a solution for it?

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

      Idk if my submissions can help, but I was using go for quite some time. Look for any of my submissions in Go, there will be fast IO functions.

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks, it works now <3

»
15 months ago, # |
  Vote: I like it -31 Vote: I do not like it

Actually it's recommended to use C/C++ to do competitive programming, for other languages are not made for pure efficiency. In my opinion, in your situation it's not a very good idea to practice simple problems on CF. Use a training site instead. However, if you really want to stick to CF, use a macro template so you don't have to do those tricky optimization every time.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yeah I know. As I said before, I am only learning it, and I am solving problems to get used to its syntax.

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

    Well I've used Go a lot and haven't had many issues related to performance. If you have good knowledge of how the language works, you can easily use it. Plus it's incredibly fun.