muff-1n's blog

By muff-1n, history, 4 years ago, In English

Hello all,

I've a question about the judge system, mainly referred to the problem in subject.

I've submitted this linked solution yet, one of the test is failing.

My problem here is that I'm not able to replicate locally the test failure for the 2th test


2
Time: 15 ms, memory: 0 KB
Verdict: WRONG_ANSWER
Input
8
Participant's output
5
Jury's answer
1
Checker comment
wrong answer 1st numbers differ - expected: '1', found: '5'

Yet, in local, for the input 8, I'm getting the right value 1.

Do you know what can cause this discrepancy?

Thank you in advance.

In case the previous source is not visible, the code is included in the screenshot along side with the output.

  • Vote: I like it
  • +1
  • Vote: I do not like it

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

try to run on custom invocation link.It's giving 5 there also . Also changing log to log2 is giving right answer for test 2 .

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

    thanks for the custom test link: it can be useful.

    about the test itself, it is not a matter of log vs log2, rather is about types:

    this doesn't work:

      int exp = log(x)/log(2);
      int abac = x - pow(2,exp);
    
      cout << "debug: " << log(2) << " " << log(x)/log(2) << " " << log2(x) << endl;
    
      cout << 1+abac << endl;
    

    this works:

      double exp = log(x)/log(2);
      int abac = x - pow(2,exp);
    
      cout << "debug: " << log(2) << " " << log(x)/log(2) << " " << log2(x) << endl;
    
      cout << 1+abac << endl;
    
    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      it was precision issue that's why log2 and log gave different answer when i checked .

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

log(8) = 0.903089987 log(2) = 0.3010299957

Which is a double (floating point) number. But you are using int data type. That's why you're getting the wrong answer. Try changing the datatype to double.