vanishing's blog

By vanishing, history, 8 years ago, In English

I was trying to solve 940E. The code is doing well on my computer, but i keep getting RUNTIME_ERROR. Can anyone kindly help me to find out the problem? The code is here Thanks

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

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

Look at the diagnosics: The AdressSanitizer claims an error, that means you try to access non-allocated memory. Here you try to access data[4] (in the first test case), but you only allocated a vector of length 4.

for(long long i=1;i<=k-1;i++)   {dp[i]=subsum[i];
         tmp.insert(data[i]);}
  • »
    »
    8 years ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    It's weird but the problem solved once I choose g++14 as the complier...

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

      I don't think that this is that strange. Accessing unallocated behaviour is undefined behaviour. So the program can crash, it can give wrong results, it can work without any problems if the accessed memory isn't important, ... And every compiler can give different results. Basically everything can happen.