ajecc's blog

By ajecc, history, 8 years ago, In English

Ok, so I solved this problem: http://codeforces.net/contest/91/problem/A. The interesting thing is that I submitted 2 buggy solutions before: 27178776 and 27178719. They are exactly the same, but one is compiled on C++11 and the other on C++14. My question is: why is there a difference? Does it have to do with the way C++11 and C++14 handles the way a vector works when you access the vector.size()th element (which doesn't exist)?

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

I think, problem is in that line, where you have put "auto", sometimes it doesn't work in cpp 5.1.0 and 14.6.2.0, but I haven't seen this problem in my codes. sorry for poor English

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

v[v.size()] is undefined so different compilers might behave differently.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yeah, I think that might be it. It's still pretty annoying that you don't get a runtime error when something like this happens.

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

I found one more mistake "int cur = upper_bound(all(pos[i — 'a']), ante) — pos[i — 'a'].begin();", you didn't look at case — if upper_bound will be equal to pos[i-'a'].end(), it's big mistake, I think thats all:)