iamstg's blog

By iamstg, history, 8 years ago, In English

With reference to the problem, http://codeforces.net/contest/721/problem/C

http://codeforces.net/contest/721/submission/21096367 -> This submission with memset giving value of 1e9+7 to 2D array gives WA on test10

whereas the same code with memset removed and the 2D array given value manually of 1e9+7 ->http://codeforces.net/contest/721/submission/21096181 gives AC.

I am completely not able to understand why?? Does anyone have any idea??

  • Vote: I like it
  • -8
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it -12 Vote: I do not like it

memset works only when we have to initialise the array with 0 or -1 for rest it doesn't work

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

You don't know how memset works. It works byte by byte not word (4 bytes) by word.

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

http://www.cplusplus.com/reference/cstring/memset/

memset Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).

»
8 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Memset works by writing values byte by byte based on the given value. Check out the documentation here!

By the way, if you want to set an array to large values, use memset with 63, this will set all values to ‭1,061,109,567‬