Depending on input number N, We have to figure out complexity to select correct methods that will satisfy time and memory limit.
Python calculates about 20,000,000 per sec.
2^10 ~ 1000 : OK
2^20 ~ 1M : OK
2^30 ~ 10 Billion (1,000,000,000) : TLE
Remember Standard library functions’ complexity and make use of it.
Check out complexities for iterable functions in Python
import time
st = time.time()
process()
print(time.time() - st)
Most of free online IDE such as repl.it are generally open to public. This means that your solutions can be caught as cheating in competetion. (Paid account may have private sessions). Therefore, I will use VS Code for solving problems.
In Windows, I/O redirection is not supported. Install WSL2(Windows Subsystem for Linux 2) for I/O redirection support in VS Code. Linux and Mac does not need any optional action.
cntl + p
or cmd + p
and search for launch.json and add args line for I/O redirection."version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": ["<", "in.txt", ">", "out.txt"]
}
]
Now I/O redirection is activated for your VS Code system.