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

Автор Samsam, 10 лет назад, По-английски

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 ?

Теги bug
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

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

try to reset your arrays.

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

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

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

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.

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

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

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

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