[SOLVED] Need help with problem 1822G2

Revision en3, by nairarjun1997, 2023-07-07 03:13:39

I'm trying to solve https://mirror.codeforces.com/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://mirror.codeforces.com/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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English nairarjun1997 2023-07-07 03:13:39 176
en2 English nairarjun1997 2023-07-07 00:42:18 122
en1 English nairarjun1997 2023-07-06 23:35:27 1354 Initial revision (published)