Блог пользователя KP56

Автор KP56, история, 2 года назад, По-английски

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.com/submissions/KP56

  • Проголосовать: нравится
  • -19
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You missing link to any code to watch at:)

  • »
    »
    2 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      2 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      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

      • »
        »
        »
        »
        2 года назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        You can also use the following

        Example
        • »
          »
          »
          »
          »
          2 года назад, # ^ |
          Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

          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.

          • »
            »
            »
            »
            »
            »
            2 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            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];
            
»
2 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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).

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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