Блог пользователя hulm

Автор hulm, история, 8 месяцев назад, По-английски

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://codeforces.com/problemset/submission/580/226466440

Thanks for your consideration.

  • Проголосовать: нравится
  • +28
  • Проголосовать: не нравится

»
8 месяцев назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

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().

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Very BIG thanks. You helped me a lot.

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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?

    • »
      »
      »
      8 месяцев назад, # ^ |
        Проголосовать: нравится +9 Проголосовать: не нравится

      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.

»
8 месяцев назад, # |
  Проголосовать: нравится -31 Проголосовать: не нравится

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.

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится +17 Проголосовать: не нравится

    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.