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

Автор soccho66, 13 часов назад, По-английски

Hi,

It is sometimes very hard for someone to find the test case where the code fails. There are some ways to know without debugging the code. one popular way is Stress Testing but stress testing is itself a stressful job to do because you have to write a bunch of lines of code maintaining the constraints. I have found an easy method to know the test case, specifically in codeforces.

Enough trash talk.

The benefit of codeforces is that it gives a checker log, where you can see the wrong test case number, expected value, and your output, So how can you know the wrong test case from here?

You can output a string where you have stored all the input values.

Here is an example to make it more clear...

Suppose, the problem has an array and n the length of the array. And you are getting wrong answer on test case 455. You will write an if condition when the test case is 455 you will append all the input values in a string and submit the code. checker log will show you the string. An easy way to append an integer value to a string is using to_string() library function.

To separate all the integer values you can use underscore or anything you like. It is necessary to use underscore rather than giving space between integers because checker log will only show you the output until there is a space or newline. Here is a sample code

int T;
cin >> T;
for (int tc = 1; tc <= T; tc++)
{
    if(tc == 455){
        int n;cin>>n;
        string s = to_string(n) + "__";
        int a[n];
        for(int i = 0; i < n;i++){
            cin>>a[i];
            s += to_string(a[i]) + "_";
        }
        cout<<s<<endl;
    }
    else solve();
}

Important : Remember to write else statement before solve or write return/break in if block or else most of the time checker log will not show the output properly.

Now, there is a problem. What if you get WA on test #3 but test #2 also have 455th case. You will not pass test #2 by this code.

There is a way, checker log also help us in this case. They show what was your wrong output on 455th test case. So now suppose you have stored your value in ans variable and your WA is 234523 on test #3 in 455th case. Then your if condition will look like this.

if(tc == 455 && ans == 234523)

It is very unlikely that the wrong answer in test #3 455th case would be the same as the correct answer in test #2 455th case.

Even if that is the case that it matches with previous test with same test case number, you can see some surrounding values like if you get WA on test #3 then you can declare a global variable and save the answer of first test case of test #3 and then run it.

Suppose the answer of first test case of test #3 is 234123, and your global variable name is ansGlob then the if statement would look like this

if(tc == 455 && ans == 234523 && ansGlob == 234123)

If this also matches then you have to find some other way to differentiate test #3 from test #2. You get the idea.

Now, you can output on any test #.

What if the test case is too long?

I don't know any good method to output a very long test case but I don't think it will give any benefit even if you know the test case. What can you do is that if all the small cases have been passed then you can be sure that your logic is correct now check for if you have done mod correctly or your array size is enough or not. (there can be other reasons)

Though there is a way but I have never tried it. I have seen that checker log can output a string length of 60. You can submit your code and get the first 60 digits, then again run the code and get the next 60 digits and so on. it is a very lengthy process and I am not sure about whether it will work or not.

Okay now there is another case, checker log tells you that you have got 455th number wrong. Normally if you have one output for every case it will just work as saying wrong answer on test case 455th. But if a single test case has multiple outputs then this is how you can do this,

Initialize a variable globally and sum up the number of outputs every time and when the number exceeds 455 just output the inputs for that test case as mentioned above.

I've tried to cover all the cases I have countered. If there are other cases mention them in the comments and if I know the answer I'll do my best to address them.

If you didn't understand anything in my blog feel free to ask as I am not good at explaining things and if I have made any mistake, please let me know.

I hope you find this blog helpful. Thank you for reading! :)

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится