Bug in template [SOLVED]

Hey there, I really don’t like treating discuss as a free debugging service but in the last contest I had 5 penalties because of my template and despite wasting 1hr on debugging I have not been able to find why is that so, this is the problem link.
RTE_CODE
AC_CODE
both are exactly the same codes but the difference between them is just my template(check the solve function). I stress test-tested the RTE solution against the AC one for 6000 test cases but it seems to be working fine to me. Here’s the generator that I used for stress testing test-case-generator, testing-script.
Help me save my future penalties

The test cases are out of constraints. The following code gives runtime error too.

Constraints Verification
# Python
t = int(input())
if t not in range(1, 11):
    print(1/0)
for test in range(t):
    n, p = map(int, input().split())
    if n not in range(1, 2 * 10**5 + 1):
        print(1/0)
    if p not in range(1, 10**3 + 1):
        print(1/0)
1 Like

Also, after seeing this…I remember that asserts don’t work in Python on Codechef but they work in PyPy. @admin Can you look into this? For instance, this should give RE instead of WA.
Sorry, this is kinda unrelated to this thread but I don’t want to create a new thread for this.

1 Like

But there is an assert statement in the AC code too if you’re talking about p!=0 constraint, also why exactly is the 2nd one thing giving an AC

Well, even this code gives Runtime error.

t = int(input())
if t not in range(1, 11):
    pass
for test in range(t):
    n, p = map(int, input().split())
    if p < 1:
        print(1/0)

And even this code gives RTE.

t = int(input())
if t not in range(1, 11):
    pass
for test in range(t):
    n, p = map(int, input().split())
    if p == 0:
        print(1/0)

NVM, constraints for N and P were fine, it was the input format mismatch in the test cases that resulted in RTE for python codes.

The value of T was not within specified constraints (1 \le T \le 10). The following two codes prove that T was not within the constraints.

WA
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, p;
    cin >> n >> p;
    if(n < 1 || n > 2e5) {
        cout << (1/0) << '\n';
    }
    else if(p < 1 || p > 1e3) {
        cout << (1/0) << '\n';
    }
}

int main() {
    int t = 0;
    cin >> t;
    // if(t < 1 || t > 10) {
    //     cout << (1/0) << '\n';
    // }
    for(; t > 0; t--) {
        solve();
    }
    return 0;
}
RTE
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, p;
    cin >> n >> p;
    if(n < 1 || n > 2e5) {
        cout << (1/0) << '\n';
    }
    else if(p < 1 || p > 1e3) {
        cout << (1/0) << '\n';
    }
}

int main() {
    int t = 0;
    cin >> t;
    if(t < 1 || t > 10) {
        cout << (1/0) << '\n';
    }
    for(; t > 0; t--) {
        solve();
    }
    return 0;
}

It seems the error signal was SIGABRT. One of the many reasons why it occurs is the “excessive memory usage”. Source

Try figuring out which part of your template uses extra memory.

1 Like

I guess raise can be used instead of assert for such cases.

Example:

t = int(input())
if t < 1 or t > 10**5:
    raise AssertionError("Invalid value of T")
2 Likes

there ain’t any bugs in ur template
the test cases were just wrong
problem 1
runtime error ac

problem 4
runtime error ac

i wonder how the candidate masters didn’t find these bugs when they tested the problems

3 Likes

Ah… now this makes sense, thanks for clarification.

Hey @tamo11 , the only difference between the AC code and RTE code for problem 4 is the following if statement.

if (p > 1000) return 0;

But my codes mentioned here show that the constraints for N and P were fine. I strongly feel Something else should have gone wrong.

EDIT: My bad. Yes, test cases were wrong.