Herothenewdominator's blog

By Herothenewdominator, history, 8 months ago, In English

Can anyone plese help me out what is the issue in my code, just couldnt understand why is it giving wrong answer for this, logic seems to be correct I guess

My submission https://mirror.codeforces.com/contest/2116/submission/336427692

The problem https://mirror.codeforces.com/contest/2116/problem/B

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This line" ll sum = max(raw1, raw2) % 998244353; might be the problem

I don't think you can just take the max of raw1 and raw2, because both of those values are the result of a MOD operation. Just consider this tiny example:
a = 17, b = 14, mod = 15
now a > b, but a % mod < b % mod

This example would fail in your code

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Don't compare numbers after taking modulo, compare them before taking modulo.

In this case, it's 2^i+2^j versus 2^x+2^y. Compare them lexicographically to see which number is bigger, then and only then take modulo.