ComboGirl's blog

By ComboGirl, history, 8 months ago, In English

In the following two submissions 224059045 and 224058953 the only difference is one line where I replaced

memset(dc, n+5, sizeof(dc));

with

for(int i=1;i<=n;i++) dc[i] = n+5;

and it WA on the first but AC with the latter. I'm not sure why this is happening. Any ideas?

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

»
8 months ago, # |
  Vote: I like it +13 Vote: I do not like it

Memset basically fills each byte in the range with the specific value given. With your memset you are putting value n+5 in each of the four bytes in dc[i]. That integer dc[i] is not equal to n+5 but something completely different.

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

for values which is not 1 byte, use std::fill instead of std::memset