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

Автор rohantrix, история, 2 года назад, По-английски

In today's Codeforces Round (#763) problem B, I tried finding a pair object in a HashSet. Even after overriding equals() and hashcode() methods, I still ended up with WA on test 4. Here is the link to my solutions:

1) WA Submission using HashSet

2) Working Solution using 2D matrix

Please let me know of a good fix for this.

vinam SecondThread

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

»
2 года назад, # |
Rev. 3   Проголосовать: нравится +15 Проголосовать: не нравится

Use Integer.equals instead of == in your pair.equals, otherwise you get false when comparing two objects with the same value but different references. Btw, same bug in the pair.compareTo method.

Check this AC solution: https://codeforces.com/contest/1623/submission/140959789