adityav664's blog

By adityav664, 2 years ago, In English

I'm getting runtime error again and again and i can't seem to find any issue with my code as codeforces custom test compiler is also printing output just fine but when i submit code i get runtime error plz help, these 1 are questions that i'm getting issue with. 1. 120B - Quiz League 178911312

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

| Write comment?
»
2 years ago, # |
  Vote: I like it -9 Vote: I do not like it

I suggest that you learn about Undefied Behaviour. On C++ there are some (actually many) operations for which there is not a guaranteed behaviour for all environments. As the C++ committee is not the ones who make compilers, nor ones who make computer architectures, they can't enforce it for every existing compiler or architecture, otherwise it would be a real pain deciding what behaviour is effective for every environment. Thus, they put it as an undefined behaviour, so you cannot ensure them to work the way you expected on every environment.

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

i am not a pro but i think this question wants input and output from a file. so write this after main function is declared :

#ifndef ONLINE_JUDGE
 
    // For getting input from input.txt file
    freopen("input.txt", "r", stdin);
 
    // Printing the Output to output.txt file
    freopen("output.txt", "w", stdout);
 
#endif

and then when you submit your code, it will throw a time limit exceeded error, which i think you can solve on your own by changing your program.

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

    Modified submission — 179137435

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

      Didn't notice that — you're right. Maybe I forgot that back in the old contests, using STDIN/STDOUT was not very common (or at least that was the case for Korea until 2014)

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

    179140457 why do i getting output not found now, and i can't see why i'm getting tle in your submission

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

      In this case we do not want the #ifndef, we want the File I/O to run on the online judge. You can change it to #ifdef instead.

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

        Thanks it works, so whenever i have to solve old questions do i have to use this? cause i never encounter this issue till now even solving beta contests from the codeforces beginning why do i get this issue now?

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

          Under the time/memory limits there were two lines input:input.txt, output:output.txt so I think you can use File I/O whenever you see this.