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
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | adamant | 152 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 144 |
| 5 | errorgorn | 141 |
| 6 | cry | 139 |
| 6 | Proof_by_QED | 139 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 9 | TheScrasse | 134 |
| Name |
|---|



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.It's weird but the problem solved once I choose g++14 as the complier...
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.