ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Please help! Wrong answer (C++)
Posted by Yurii Leskiv 28 Mar 2016 23:11
My program works fine in console, but for some reason I get wrong answer on test 9. Could someone point out where is the problem in my code?

#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
    double num;
    vector<long long> input;
    int limit  = 256 * 1024 / sizeof(long long);
    for (int k = 0; (cin >> num) && k <= limit; k++)
    {
        if (num != (long long)num || num < 0 || num > pow(10.0, 18))
            return 0;
        input.push_back((long long)num);
    }
    for (int i = input.size() - 1; i >= 0; i--)
        cout << fixed << setprecision(4) << sqrt(input[i]) << endl;

    return 0;
}

Edited by author 28.03.2016 23:17

Edited by author 28.03.2016 23:18

Edited by author 28.03.2016 23:18
Re: Please help! Wrong answer (C++)
Posted by ToadMonster 28 Mar 2016 23:37
Limit is wrong. Min number size is 2 bytes - "1 ".

In common, you shouldn't check if input is correct. It's supposed to be always correct.
Reading like:
while (cin >> number) {
    input.push_back(number);
}
should be enough.

If you want to check input (for lulz?) you should fail your program in more visible way - via return not 0, throw something etc. Judge system will return another error, not WA.


Edited by author 28.03.2016 23:43
Re: Please help! Wrong answer (C++)
Posted by ToadMonster 28 Mar 2016 23:40
Another note.

You read number into double, convert it into long long, convert it back to double and finally call sqrt.
Why do you need 2 conversions in the middle?
Shouldn't you better use vector<double> input?
Re: Please help! Wrong answer (C++)
Posted by Yurii Leskiv 29 Mar 2016 01:47
Sorry for stupid question: what is WA?
Re: Please help! Wrong answer (C++)
Posted by retired 29 Mar 2016 02:04
"Wrong Answer"
Re: Please help! Wrong answer (C++)
Posted by ToadMonster 29 Mar 2016 12:43
http://acm.timus.ru/help.aspx?topic=judge&locale=en

Possible solution run results are described in "3. The judge tests your solution" topic.