[Python] Competitive template [At Coder]

Currently (2020/05/05) in use ** Templates for competitive pros (for Python) such as AtCoder! ** ** Please use when it is good~ (I'm sorry if I make a mistake!)

Competitive template

I think that the first line is often deleted and submitted, so Always use sys and other libraries (at input) It is divided into two lines! Also, sys.stdin.readline (). Rstrip () is clearly faster than ʻinput ()`! !! !! Reference article [8 small differences in processing speed that Python should know] (https://www.kumilog.net/entry/python-speed-comp#input-%E3%81%A8-sysstdinreadline)

** (Added on 2020/05/17) ** Moved the position of S () over LS () (because it didn't look good)

test.py


import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = [LI() for _ in range(N)]

* Supplement 1 ~ Main uses of libraries ~

** (Added on 2020/05/17) ** Added np.argmax ()

* Supplement 2 ~ Precautions when using template ~

** (Added on 2020/05/11) ** ABC167A When I received the following characters, I got an error and was impatient ...

NG.py


import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
T = S()
print('Yes' if S==T[:-1] else 'No')

T = S() By the way S is just a string (overwritten just before), but you can't useS ()! Error with! If you think about it, it's natural ...

In such a case, let's deal with it as follows ~

OK1.py


import sys
def S(): return sys.stdin.readline().rstrip()
S,T = S(),S()
print('Yes' if S==T[:-1] else 'No')

You can do this! Or rather, I'm glad I wrote this way normally ...

OK2.py


import sys
def S(): return sys.stdin.readline().rstrip()
s = S()
t = S()
print('Yes' if s==t[:-1] else 'No')

Make variables lowercase (other than uppercase S) ~

end!

Recommended Posts

[Python] Competitive template [At Coder]
At Coder (2020/09/08)
[At Coder] ABC085C --Otoshidama's Python answer
python at docker
python argparse template
Fill at Coder
At Coder # 1 at midnight
[Python] Tkinter template
[At Coder] Beginner Contest 175 ABCD python Solution introduction
[Python] ABC133B (upper right triangle problem) [At Coder]
Python template for log analysis at explosive speed
[Python] ABC159D (High School Mathematics nCr) [At Coder]
[At Coder] Output method
Competitive programming diary python 20201213
Competitive programming diary python 20201220
Competitive programming with python
[At Coder] ABC128B --Guidebook
Python data analysis template
Jinja2 | Python template engine
python unit test template
Competitive programming diary python
Python template engine empy
[Python] AGC043A (Problem reading comprehension and DP) [At Coder]
[Python] [BFS] At Coder Beginner Contest 168-D [.. Double Dots]
[At Coder] Acing C-XYZ Triplets
Python template for Codeforces-manual test-
Python Competitive Programming Site Summary
Python Design Pattern --Template method
Python3 standard input for competitive programming
Cropping images at once [python] [Pillow]
Take a look at Django's template.
HomeBrew can't install Python (at Mavericks)
Starry sky wallpaper at night (Python)
[Python] Now a brown coder ~ [AtCoder]
Preprocessing template for data analysis (Python)
web coder tried excel in Python
[Python] I'm a green coder ~ [AtCoder]
[At Coder] What I did to reach the green rank in Python