gteu / atcoder Goto Github PK
View Code? Open in Web Editor NEWAtCoder templates and submissions
AtCoder templates and submissions
a = [1,2,3]
print(*a) # リストをスペース区切りで出力
print(*a, sep="\n") # リストを改行区切りで出力
import sys
sys.setrecursionlimit(200001)
q = deque([])
q.append(10) # 追加
q.popleft() # 取り出し(キュー)
q.pop() # 取り出し(スタック)
優先度付きqueueを使う時はheapqを使う
heapq.heapify(a) # リストを優先度付きキューに
heapq.heappush(a, 10) # 追加
heapq.heappop(a) # 取り出し
a = map(lambda x: int(x)*(-1), a)
# あとは同じ
要素数のカウントなら collections.Counter が便利
>>> a = [1,1,2,3,1,1,0]
>>> Counter(a)
Counter({1: 4, 2: 1, 3: 1, 0: 1})
>>> from collections import defaultdict
>>> index = defaultdict(list)
>>> S = "socks"
>>> for i,s in enumerate(S):
... index[s].append(i)
>>> index
defaultdict(<class 'list'>, {'s': [0, 4], 'o': [1], 'c': [2], 'k': [3]})
permutations(iterable, r=None) # 順列(len()を取れば階乗が求まる)
product(iterable, repeat) # 重複順列
combinations(iterable, r) # 組み合わせ
combinations_with_replacement(iterable, r) # 重複組み合わせ
for idxs in product(range(p), repeat=N):
for i, j in enumerate(idxs):
# ...
pow(base, exp[, mod])
文字列連結は "".join(seq)
を使う
最大公約数はmath.gcd。3個以上の値に適用する際は以下のように関数を定義。
def gcd_list(numbers):
return reduce(math.gcd, numbers)
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers):
return reduce(lcm, numbers, 1)
ord()
ascii→文字: chr()
# 数字の2を文字のcに変えたいとき(つまり0-indexed)
chr(2 + ord("a"))
n = 123
ans = []
while(n>=1):
ans.append(n%p)
n //= p
# ansを逆順にしたものが、p進数の数。もし11進数以上の場合は上のchrやordを使って変換。
math.radians()
ラジアン→度: math.degrees()
# 例えば、条件が"以上"か"より大きい"かでbisect_leftからbisect_rightが変わる。
# 5以上の値の数を求めるとき
ans = len(a) - bisect_left(a, 5)
# 5より大きい値の数を求めるとき
ans = len(a) - bisect_right(a, 5)
# 1/a (mod p)
a_inv = pow(a,p-2,p)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.