KP56's blog

By KP56, history, 4 years ago, In English

I don't have a lot of experience with c++, but decided to give it a try since I heard it's very good for competitions. My code when used with an older compiler gives a wrong answer and with the new one the solution is correct, but it fails due to a runtime error in test 2. I couldn't find any issue in my code. Am I missing something?

https://codeforces.me/submissions/KP56

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

| Write comment?
»
4 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

You missing link to any code to watch at:)

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

    I have a question.

    whenever i write recursive lambda function. it does not work for long long. Like what if i need to return long long type in a dp problem.

    for example:-

    example code

    I don't want to write a blog for it that's why i asked here. Is there anyone who can tell the reason.

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

      instead of if(l>r)return 0;

      try to do if(l>r)return 0LL;

      also all the return should have same return type so make sure they are all long long

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

        You can also use the following

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

          I was submitting my code for two sets(II) on cses. and it's giving runtime error. Can you tell me the reason. code

          Edit:- maybe i am getting error because of something else.

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

            The first dimension of your dp has size of $$$505$$$,

            const int N = 505;
            int dp[N][252500];
            

            but you used it out of bound

            if(i==n+1)
            {
                return (tot/2==sum);
            }else if(dp[i][sum] != -1)return dp[i][sum];
            
»
4 years ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it
  • »
    »
    4 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Thank you very much for this link. I've actually always thought when coding in java (my primary language) that HashMaps (or unordered_maps in this case) operations are always O(1).

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

      Did you tried just with a regular map? Most of the time you don't need hashmaps