Does CodeChef Support Tampering with Input/Output

Hello, Everyone
I have recently found a template for Python3/PyPy3 which makes IO operations faster.
Here is the link to the template:- PyRival/template_py3.py at master · cheran-senthil/PyRival · GitHub

I have seen this template used in CodeForces and it works there.

The problem is when I used it in my solution here. The grader became unresponsive and my file was in the submission queue for 5 minutes only to get a response of TLE where the time taken to run the code was specified as -1 sec.

I don’t know what went wrong which brings me to ask the question if it even supported or allowed to do it or is there some changes to be made in the code so that it works

1 Like

This code works perfectly for ATM Problem.

import os
import sys
from io import BytesIO, IOBase


def main():
    widrawl, balance = map(float, input().split())
    if int(widrawl) % 5 != 0 or (widrawl + 0.5) > balance:
        print(balance)
    else:
        balance = balance-widrawl-0.5
        print(balance)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()
1 Like

Thank You Man. I guess i used in the wrong problem. It was a Challenge Problem where script has to interact with the grader.

1 Like

But this code gives me runtime error, I dont know why?

@rishi18 try giving custom input while running on codechef online editor

Thanks brother @kuji

I’m the author of the fastIO stuff on PyRival. FastIO is made to be very similar to the built in IO, so if the built in IO works, then FastIO should work too. One of the main reasons I made fastIO is to speed up the IO for interactive problems.

As for what went wrong. My best guess is that you forgot to flush stdout. FastIO only flushes if you tell it to, or if you exit Python. Not flushing would result in exactly the issues you are experiencing. If you are already flushing, and the code is still getting stuck, then I would be interested to look into it. So far I haven’t found a case where FastIO fails.

6 Likes

@gorre_morre , I might have a case where FastIO is misbehaving. Where can I reach out to you?

Contact me on codeforces or on Discord. You can find me in the AC discord server linked to here: Presenting TLE: the best Codeforces bot for Discord - Codeforces.