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

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

I'm trying to solve https://codeforces.net/contest/1822/problem/G2.

My approach was to count the triplets by splitting the set of triplets by the largest value of the triplets. So, I count for every possible largest value in a triplet. Let's call a given possible largest value "n". I broke down the problem into the following cases:

  1. n / b^2 == sqrt(n). In this case, b == fourthroot(n). So, we count that if b is valid.
  2. n / b == sqrt(n). In this n / b == sqroot(n), and n / b^2 == 1, so we count that, if b is valid.
  3. n / b^2 > sqrt(n). In this case, b < fourthroot(n), so we try all possible b.
  4. n / b^2 < sqrt(n) and n / b > sqroot(n). In this case, we get constrains b < sqrt(n), b > fourthroot(n).
    • We split the fourth case into two more cases:
      1. n / b^2 < b. In this case, b^3 > n, so b^2 > n^(2/3), so b^2/n > n^(2/3)/n, so n/b^2 < n^(1/3). So, we count all possible values of n/b^2.
      2. n / b^2 >= b. In this case b^3 <= n, so we try all b.

I'm looking for help with a case I missed, since it looks like I'm undercounting. Maybe I have some sort of overflow, but I don't see where that would be possible.

Here's my submission which fails the third test case: https://codeforces.net/contest/1822/submission/212470854. The submission is a real mess.

I also tried randomly generating some arrays, and comparing the output with a bruteforce solution, but no luck so far.

Solution: You can't iterate over an unordered map while also accessing elements which don't exist in the map. It changes the size of the map in some compilers.

Полный текст и комментарии »

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