Vedkribhu's blog

By Vedkribhu, history, 6 years ago, In English

For some testcases I am getting a run time error while it runs fine on my local machine. Problem code. Any help would be awesome.

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

| Write comment?
»
5 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

you might be declaring a 1-d or 2-d array of size>2*10^6. so for lower values it work fine on local compiler but solution can't be accepted due to size overflow.

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

    Given that it's been 6 months, I'm not sure the OP still needs help. But I would like to point out that 2 * 106 fits comfortably in 512MB.

    You were still right about the error though. The OP is creating an array of size N * X. N ≤ 103 and X ≤ 105, which means that 108 long longs will be created. This will cause MLE.

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

if u are writing a cpp code just dont use long long int , instead use int which takes less memory since MLE is the reason for runtime error . I did the same and it worked , thanks for this post though :)

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

    if u are writing a cpp code just dont use what you don't understand. long long is a 64-bit integer type while int is a 32-bit integer type (on most computers). This means an int can contain whole numbers up to an order of $$$10^9$$$ while long long can contain numbers up to something like $$$10^{18}$$$. If your solution may use numbers larger than $$$10^9$$$, you have to use long long.

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

      what you are saying is exactly correct , but the question he is talking about can be solved easily with int , which is why I suggested it , I suggested him to write int for the specific code, not in general. Although now that i am reading my own post it sounds wrong , nvm my bad. thanks