Samsam's blog

By Samsam, 9 years ago, In English

Hello, I am solving this problem and

I am getting Wrong answer when submitting my solution even the results are true on my computer

I am getting:

Wrong answer on test 1 for Microsoft visual c++ 2010

Wrong answer on test 9 for GNU c++ 4.9.2

Wrong answer on test 9 for GNU c++11 4.9.2

Even my answer is correct in the three cases

So what could the problem be ?

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

»
9 years ago, # |
  Vote: I like it +1 Vote: I do not like it

try to reset your arrays.

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

I've put larger size(larger than I need) for each array and I got it accepted but I don't know the reason

»
9 years ago, # |
  Vote: I like it +4 Vote: I do not like it

The problem wasn't in compilers, it was in your code :) Look, in the last loop you're using C(i,k). But here i starts from zero while k can be big enough. You just have to use the fact that C(i,k)=0 when k>i: 11176479 — AC.

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

    thank you very mush, but I still don't know why the answers on my computer are correct

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

      Wierd overflow, I think. Let n<m, then n-m<0. So, in C(n,m) you're trying to access inv_fact[] at some strange position. In fact, that must cause an error (out of array bounds), but you were lucky enough and it was just accessing some zero values. Not sure if it's so important to study what exactly happened here... It's better to remember initialize everything correctly :)

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

        your are right , thank you very mush