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

Автор 404Error, 10 лет назад, По-английски

I have recently tried to test the different kind of solution both on java 7 and java 8 and I found out that using Collection library or using class like BigInteger take less time in java 8 compare to java 7. But when you run normal program which has does not use class like HashSet, HashMap etc.

For example I will give you some small example I tested both on java 7 and java 8.

  1. Using BigInteger Class we all know this class is very helpful sometimes for Java users. So I did some multiplication and addition and subtraction for 20000 times to check how much time it takes on codeforces platform to run. 8371132 it runs in Java 8 and takes 826ms displaying 3192KB memory 8371128 same code in Java 7 takes 2292 ms displaying 0 KB memory

  2. In practice I solved 271D - Good Substrings using Java Library HashSet on String instead of trie data structure.

8356449 this code got accepted in java 8, and that time codeforces does not have Java 8 environment.

8356450 same code got TL in Java 7.

I don't know its Java 8 optimization or it is codeforces server.

Some more example using ArrayList of Integer and String java 8 — 8371287 685 ms with 0 KB memory displaying java 7 — 8371288 951 ms with approx 33 MB memory

So using Java 8 in big data is really helpful in codeforces. You can try on your own and use it accordingly.

I hope this article will helpful for those who are solving problems in java and sometimes their code get TL because their code is not that much optimized. If you are using Collection library Java 8 at codeforces gives you little freedom in terms of run time at least.

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

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

I think, this is the bad line:

String l = s.substring(j, j + i);

In java 6 substring works in O(1), but in java 7 it works in O(n). May be in java 8 they fix this.