ColdWinters's blog

By ColdWinters, history, 8 years ago, In English

Hello,

I'm trying to solve the B problem of the Div2 Round #382.

I'm getting the correct answer when i compile on my system with gcc version 5.3.1 but when i submit I get WA on the very first test case. Om my system i get "6.00000000", which is the right answer, but when i submit i get a "0.00000000".Can anybody help me?

Problem statement: http://codeforces.me/contest/735/problem/B Submission: http://codeforces.me/contest/735/submission/22645993

Thanks in Advance :)

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try submitting in c++14 instead of C11.

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

Maybe the results are different since qsort is a randomized algorithm.

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

The problem is that you're using %lf in the printf when you should use %f.

Note that %lf is only used for doubles in scanf.

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

    http://en.cppreference.com/w/c/io/fprintf

    Although it has erroneous behavior in submission, "%lf" is also permitted since C99.

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

      Interesting. I normally don't use C. So, it seems GCC 5.3 is not respecting the change in the standard, right?

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

        I'm trying but can't figure out why it is happening... My GCC works well with that, even with -std=c89. We might need exact compile option/environment to know what the problem is.

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

        Probably MINGW being crazy as usual with format specifiers. It's even worse than this actually, because if you don't submit with C++14, then you must use "%lf" for scanf and "%f" for printf.

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

It's interesting why GCC GNU C11 works strange. Use GCC C++. Bad news for you: your algo is wrong (may be). See my submission: http://codeforces.me/contest/735/submission/22649713 upd: Sorry, your algo is right, only need to use long long for 'a' and 'b' variables :) see http://codeforces.me/contest/735/submission/22649947