throwawayac2004's blog

By throwawayac2004, history, 4 months ago, In English

Hi, Can any one please tell what I might be missing in this which is giving RTE I have checked several times but I am unable to find the problem. Also my approach might be wrong as I was busy so I still have to see the editorial but I just wanted the error in my code only and not my logic so that is why I posted this. Thanks for reading and Sorry if it is not good to ask our silly doubts on codeforces as this is my first post.

https://codeforces.com/contest/1831/submission/207862201

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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

https://codeforces.com/contest/1831/submission/208108653

It seems to be name collision of read. The code couldn't even be compiled in my environment.

Try to read compilation results, add some compiler flags (-Wall, -fsanitize=...), or even use a debugger to find the problem yourself. It's also good to review your coding style.

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

    Actually I added all the compilation flags except fsanitize because it was showing can't find lubsan and I tried to search on internet but couldn't understand how to add it also can you please tell how did you get to know that there was name collision like which compilation flag gave error? And thank you so much for helping me

    • »
      »
      »
      4 months ago, # ^ |
      Rev. 2   Vote: I like it +1 Vote: I do not like it

      I am not a expert so I just try to answer your questions as I know. Maybe some of them are incorrect.

      I think just adding -fsanitize=undefined should be fine cause it's a compiler option. Otherwise, Google or maybe ask chatGPT about it with your OS and compiler.

      I just got a compile error since #include<bits/stdc++.h> included too many things I think. I am not sure about the environment of the judge but I think it just collides with something like linux read. Because it compiles with -static (https://codeforces.com/blog/entry/96040), read() called underlaying some functions you called will take the address of global variable read as a function. It might be okay if it runs with a shared object file (.so).

      compile error

      Btw, I recommend you can use more C++ stuff with this compiler flag, -D_GLIBCXX_DEBUG. Personally, I seldom use a global variable. Maybe add a namespace or change the nameing style if you still want many global variables.

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

        Thanks a lot dude you just saved my hours of debugging. I tried to understand as much as I can and from what I understood I added this -static in my gcc command line and then it also gave error but didn't gave prompt like yours So if you could just spare a minute and tell what compiler do you use and along with what command lines. by command line I means the -Wall -O2 type of things

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

          It's a error not a warning so there should be a prompt. I think maybe you got a link error since some library code have already be compiled and just be linked during compilation. (It's better to tell what you got instead of nothing.) Nevertheless, I use g++ with -std=c++17 -O2 -Wall -Wextra -Wshadow -fsanitize=address,undefined -D_GLIBCXX_DEBUG. Btw, in my opinion, I still think the way to avoid this kind of problem in the future is to change the way you code. Maybe try to refer to someone else who you think is good.