mathturbator's blog

By mathturbator, 10 years ago, In English

Hi,

I dont know whom to send my query regarding this contest, so am just posting it here thinking i will get an explanation. I gave div2 contest today ( contest 284 ), and for problem C ( Crazy Town ), I made multiple submissions just because of a mistake that i think is because of the compiler. { if (val1>0 and val2<0) ans++; if (val2>0 and val1<0) ans++;

// if(val1>0 and val2<0) // ans++; // else if(val1<0 and val2>0) // ans++; } Here val1 and val2 are the values for two different points inserted in one single equation of line. Basically for checking if they lie on opposite or same side of line.

Can you please tell me if there is any difference between commented conditions and uncommented conditions, because if there is not, my solution was judged wrong because of this. You can also refer to my submissions for confirmation. I can see no value for val1 and val2 for which both if conditions would ever be true simultaneously. Also in my first submission you will find val1>=0 which should still work since val1 or val2 can never be zero according to problem constraints.

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

»
10 years ago, # |
Rev. 3   Vote: I like it +6 Vote: I do not like it

All of your wrong submissions have overflow issues.

a*x+b*y+c may be as large as 106 * 106 = 1012. So it is clear that solution with int's will already fail it.

And when you check that val1*val2<0 — you are multiplying 1012 and 1012, result may be something like 1024 — and it overflows even long long.

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

    val1 and val2 are long long int. and i knew that val1 * val2 would cause overflow, hence i used (val1 > 0 and val2 < 0) as a condition. This was my first submission.

    http://mirror.codeforces.com/contest/499/submission/9251082

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +7 Vote: I do not like it

      Once again, you have overflow issues:)

      I've checked all your submissions)

      In your first submission you did stuff like "long long = int*int+int*int+int". It works following way — first of all you multiply int's, add them (and you already have some trash instead of corect values, because int*int is calculated as int, and it overflows), and only then you do assigment of result to long long.

      You may try to write it like val1=1ll*x*a+1ll*y*b+c, then x*a will be calculated as long long already, and you'll have corect results.

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

        Thanks for pointing that out :). It was a basic mistake on my part. Also, this submission ( link given ) worked well on my system but gave me a wrong answer on submission on first case itself. Can you please tell me why that might have happened?

        http://mirror.codeforces.com/contest/499/submission/9254115

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

          Try to use %lld in scanf for long long values, it should help.

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

            Although that change got my solution accepted, but isnt %Ld and %lld same? If not then why does it work on my system?

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

      you forgot to do casting :) See this submission get AC . http://mirror.codeforces.com/contest/499/submission/9270512