manoj9april's blog

By manoj9april, 5 years ago, In English

problem MEXUM(problem_link)

My sol(sol_link) is giving WA. I could not figure out, why is this happening. Someone please help me find out the error.

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by manoj9april (previous revision, new revision, compare).

»
5 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

In your code, I found these three lines will get overflow.

line 111 -> ans = (ans + (i*(mul*po2[n-sum])%mod)%mod )%mod;

line 114 -> ans = (ans + (i*(mul*po2[n-sum])%mod)%mod )%mod;

line 119 -> mul = (mul * (po2[fre[i]]-1+mod)%mod)%mod;

I changed these three lines as follow and got AC:

line 111 -> ans = (ans + (i*((mul*po2[n-sum])%mod))%mod )%mod;

line 114 -> ans = (ans + (i*((mul*po2[n-sum])%mod))%mod )%mod;

line 119 -> mul = (mul * ((po2[fre[i]]-1+mod)%mod))%mod;

(a*(b*c)%mod)%mod is equivalent to (a*b*c)%mod. Sorry for my bad English, Hope this will help you in the future.

your modified code solution link: https://www.codechef.com/viewsolution/32300055