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

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

In recent codeforces div 2 contest I got wa because of this in problem C — counting orders

I don's understand what is difference between two ,Aren't they both same ?

Here is my submission for which got wa

https://mirror.codeforces.com/contest/1828/submission/205934626

Here is same submission for which got ac by changing ans = ans* something

https://mirror.codeforces.com/contest/1828/submission/205934493

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

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

Both of them are already accepted??? you have provided the same link twice

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Learn modular arithmetic properly. While you did ans *= something % MOD; in your WA submission it gets overflow because multiplication operation doing first. In your AC submission you did ans = ans * something % MOD; Here "something" is reducing first then it multiplying. Hope you get it.

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

The other comments are wrong. * and % have the same precedence. The left-most operator takes priority. Check this link.

Your line works (ans = ans * (max ( 0LL , k - sub)) % MOD;) because the last operation done is %, so at the end of the operation ans < 1e9 + 7.

This (ans *= (max ( 0LL , k - sub)) % MOD;) doesn't work because *= has a lower priority than %, so at the end of the operation we can't guarantee ans < 1e9 + 7.

This (ans = ans * (max ( 0LL , k - sub)) % MOD;) would have worked even if ans was declared as an integer, because the * operation is performed between a ll (result of std::max) and an int (ans) that will be casted to ll. The result of % will also be ll, but since it is lower than 1e9 + 7, it will be casted correctly back to int when attributing it back to ans.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

when you have to modulo the value, you can write it as ans*=j%mod, rather you will have to write it as ans=(ans*j)%mod;

»
3 года назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

You should use (ans *= k) %= MOD;.

That's the correct code for multiplication and moduling.