Zahra.H's blog

By Zahra.H, history, 7 years ago, In English

Hi everyone :) i was submitting
Educational Codeforces Round 17 problem A but on test 9 it gives me the correct answer but CF judge says different !! what should i do ?24222811

thanks :) Good day :)

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

| Write comment?
»
7 years ago, # |
Rev. 2   Vote: I like it +23 Vote: I do not like it

v.size() is an unsigned integer, when it equals 0, v.size() — 1 will be a large integer. So accessing v[i] would be undefined behaviour.

AC code (changing v.size() to (int)v.size()):

http://codeforces.com/contest/762/submission/24223520

»
7 years ago, # |
  Vote: I like it +17 Vote: I do not like it

v.size() - 1 is unsigned, so when v is empty it becomes equal to 4,294,967,295. Use (int) v.size() - 1 to make it work.

Also, you might want to enable compiler warnings locally, so that the compiler reminds you about similar issues in the future.

»
7 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Probably you're not using the same compiler as codeforces!

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    yes that seemed to be the problem thx :)

»
7 years ago, # |
  Vote: I like it -22 Vote: I do not like it

use -->0 operator for(size_t i = v.size(); i -->0 ; ){ ... }