Skip to content

Commit

Permalink
optimized output and fixed input
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed May 11, 2024
1 parent 8b837ff commit 3793ed5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fastsnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A Python Helper CLI for Competitive Programming
"""

__version__ = "1.4.22"
__version__ = "1.4.23"

__author__ = "Jean Loui Bernard Silva de Jesus"
__github__ = "https://github.com/JeanExtreme002"
Expand Down
18 changes: 14 additions & 4 deletions fastsnake/templates/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import sys

# Optimization to speed up input.
input = sys.stdin.readline

# Python is NOT recommended for recursive solutions.
# If you use PyPy, consider removing the line below.
sys.setrecursionlimit(2 * 10**9)

# Optimizations to speed up input and output.
def optimized_input(remove_newline: bool = True):
string = sys.stdin.readline()
return string.rstrip("\n") if remove_newline else string

def optimized_print(*args, end="\n"):
sys.stdout.write(" ".join(map(str, args)) + end)

# Set by default, as this input customization is generally better.
input = optimized_input

# Time-complexity of Python implementations: https://wiki.python.org/moin/TimeComplexity
# A deque (double-ended queue) is a doubly linked list. Complexity O(1) for append and pop operations.
# Add elements with the method append (left to right). Use it as a stack (pop) or as a queue (popLeft).
Expand All @@ -27,7 +35,7 @@
# from fastsnake.structures.something import *
# from fastsnake.external.your_external_module import *

# Just remove the fastsnake code below if you will not use it.
# [WARNING]: Just remove the fastsnake code below if you will not use it.
# ======================================================================
from fastsnake.entries import *
put = input
Expand All @@ -37,6 +45,8 @@
putm = input_int_matrix # Other: input_{char, float, string}_array
# ======================================================================

print = optimized_print

# >>> HEY, RIGHT HERE!! Write your code below:
# Remember, sometimes the solution is much simpler than you think S2
import math
Expand Down

0 comments on commit 3793ed5

Please sign in to comment.