sajidhasan2021's blog

By sajidhasan2021, history, 4 years ago, In English

I was solving Div.2 116B using GNU C++11 and getting WA for test case 41. After changing the language to GNU C++17, my code was accepted.My question is why I got WA even though there was nothing wrong with the code. I also checked with C ++ 4.3.2 on ideone and got the correct answer for that test case.A very simple code having only loops and arrays..... what makes it WA in C++11.

WA : GNU C++11 submission

Accepted : GNU C++17 submission

Thank you.

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

| Write comment?
»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Here: if(A[a][b]=='W') if a or b is 10 you read uninitialized memory.

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

    then should it be also wrong in c++17?

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

      Why does the output have to be wrong? Wrong code often produces right answers. Reading uninitialized memory is undefined behavior, so anything can happen including your program appearing to work.