diff --git a/algorithm_libraries/python/basic/bit_full_search.py b/algorithm_libraries/python/basic/bit_full_search.py index d6d7e135..31bf0de3 100644 --- a/algorithm_libraries/python/basic/bit_full_search.py +++ b/algorithm_libraries/python/basic/bit_full_search.py @@ -11,9 +11,9 @@ def bit_full_search(max_bit: int) -> Iterator[List[int]]: Yields: Iterator[List[int]]: max_bitの長さの0/1の組み合わせ """ - for i in range(2 ** max_bit): + for i in range(2**max_bit): bit_list = [0 for _ in range(max_bit)] for j in range(max_bit): - if i & (2 ** j) > 0: + if i & (2**j) > 0: bit_list[max_bit - j - 1] = 1 yield bit_list diff --git a/algorithm_libraries/python/basic/sample_generator.py b/algorithm_libraries/python/basic/sample_generator.py index 59a1ef86..b6157f70 100644 --- a/algorithm_libraries/python/basic/sample_generator.py +++ b/algorithm_libraries/python/basic/sample_generator.py @@ -1,11 +1,11 @@ import random MIN0 = 0 -MIN5 = -(10 ** 5) -MIN9 = -(10 ** 9) -MAX5 = 10 ** 5 -MAX9 = 10 ** 9 -MAX18 = 10 ** 18 +MIN5 = -(10**5) +MIN9 = -(10**9) +MAX5 = 10**5 +MAX9 = 10**9 +MAX18 = 10**18 def int_generator(min_value: int = MIN0, max_value: int = MAX5) -> int: @@ -21,9 +21,9 @@ def pair_generator( if __name__ == "__main__": f = open("sample.txt", "w", encoding="UTF-8") datalist = [] - n = int_generator(1, 5 * 10 ** 5) + n = int_generator(1, 5 * 10**5) k = int_generator(1, n) - q = int_generator(1, 5 * 10 ** 5) + q = int_generator(1, 5 * 10**5) datalist.append(f"{n} {k} {q}\n") for _ in [0] * q: x, y = pair_generator(1, n, 0, MAX9) diff --git a/algorithm_libraries/python/data_structure/RMQ.py b/algorithm_libraries/python/data_structure/RMQ.py index 841027b5..f336424c 100644 --- a/algorithm_libraries/python/data_structure/RMQ.py +++ b/algorithm_libraries/python/data_structure/RMQ.py @@ -53,7 +53,7 @@ def query_min(self, p: int, q: int) -> int: return res -e = (2 ** 31) - 1 +e = (2**31) - 1 rmq = RMQ(n, e) for _ in range(q): diff --git a/algorithm_libraries/python/data_structure/predecessor_problem.py b/algorithm_libraries/python/data_structure/predecessor_problem.py index f61d1e26..1dceab0f 100644 --- a/algorithm_libraries/python/data_structure/predecessor_problem.py +++ b/algorithm_libraries/python/data_structure/predecessor_problem.py @@ -5,8 +5,8 @@ class SegTree: def __init__(self, n: int, mode: str = "min") -> None: self.mode = mode unit_elements = { - "min": 10 ** 13, - "max": -(10 ** 13), + "min": 10**13, + "max": -(10**13), } self.e = unit_elements[self.mode] # 単位元 self.tree_size = 2 ** (n - 1).bit_length() # n以上の最小の2のべき乗数 diff --git a/algorithm_libraries/python/data_structure/segtree.py b/algorithm_libraries/python/data_structure/segtree.py index f4ec17df..794a2193 100644 --- a/algorithm_libraries/python/data_structure/segtree.py +++ b/algorithm_libraries/python/data_structure/segtree.py @@ -6,8 +6,8 @@ class SegTree: def __init__(self, n: int, mode: str = "min") -> None: self.mode = mode unit_elements = { - "min": 10 ** 13, - "max": -(10 ** 13), + "min": 10**13, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, @@ -17,7 +17,7 @@ def __init__(self, n: int, mode: str = "min") -> None: self.tree_value = [self.e] * 2 * self.tree_size def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 diff --git a/algorithm_libraries/python/data_structure/segtree_kai.py b/algorithm_libraries/python/data_structure/segtree_kai.py index 483062a9..c589fe7c 100644 --- a/algorithm_libraries/python/data_structure/segtree_kai.py +++ b/algorithm_libraries/python/data_structure/segtree_kai.py @@ -7,20 +7,20 @@ def __init__(self, n: int, mode: str = "min") -> None: self.n = n self.mode = mode unit_elements = { - "min": 2 ** 31 - 1, - "max": -(10 ** 13), + "min": 2**31 - 1, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, } self.e = unit_elements[self.mode] # 単位元 self.lv = (self.n - 1).bit_length() - self.tree_size = 2 ** self.lv # n以上の最小の2のべき乗数 + self.tree_size = 2**self.lv # n以上の最小の2のべき乗数 self.tree_value = [self.e] * (2 * self.tree_size) self.tree_lazy = [None] * (2 * self.tree_size) def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 diff --git a/algorithm_libraries/python/dp/traveling_salesman.py b/algorithm_libraries/python/dp/traveling_salesman.py index b2efb77d..2b6368f2 100644 --- a/algorithm_libraries/python/dp/traveling_salesman.py +++ b/algorithm_libraries/python/dp/traveling_salesman.py @@ -1,5 +1,6 @@ def traveling_salesman_dp(positions): INF = float("inf") + def cost(pos1, pos2): x1, y1, z1 = pos1 x2, y2, z2 = pos2 @@ -13,5 +14,7 @@ def cost(pos1, pos2): for j in range(n): for k in range(n): if i & (1 << k) == 0: - dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + cost(positions[j], positions[k])) - return dp[-1][0] \ No newline at end of file + dp[i | (1 << k)][k] = min( + dp[i | (1 << k)][k], dp[i][j] + cost(positions[j], positions[k]) + ) + return dp[-1][0] diff --git a/algorithm_libraries/python/graph/bfs.py b/algorithm_libraries/python/graph/bfs.py index 768bf635..e47e6f1c 100644 --- a/algorithm_libraries/python/graph/bfs.py +++ b/algorithm_libraries/python/graph/bfs.py @@ -3,7 +3,7 @@ class BreadthFirstSearch: - """ 幅優先探索 """ + """幅優先探索""" def __init__( self, diff --git a/algorithm_libraries/python/graph/dfs.py b/algorithm_libraries/python/graph/dfs.py index baf89e38..7a091c49 100644 --- a/algorithm_libraries/python/graph/dfs.py +++ b/algorithm_libraries/python/graph/dfs.py @@ -1,11 +1,11 @@ import sys from typing import List, Tuple -sys.setrecursionlimit(10 ** 7) +sys.setrecursionlimit(10**7) class DepthFirsSearch: - """ 深さ優先探索 """ + """深さ優先探索""" def __init__( self, diff --git a/algorithm_libraries/python/graph/dinic.py b/algorithm_libraries/python/graph/dinic.py index f53c6d7b..05e237dc 100644 --- a/algorithm_libraries/python/graph/dinic.py +++ b/algorithm_libraries/python/graph/dinic.py @@ -1,5 +1,6 @@ from collections import deque + class Dinic: # V: 頂点数, E: 辺数 # O(V^2E) @@ -49,7 +50,7 @@ def dfs(self, v: int, t: int, f: int) -> int: def flow(self, s: int, t: int) -> int: flow = 0 - INF = 10 ** 9 + 7 + INF = 10**9 + 7 while self.bfs(s, t): (*self.it,) = map(iter, self.G) diff --git a/algorithm_libraries/python/graph/ford_fulkerson.py b/algorithm_libraries/python/graph/ford_fulkerson.py index d0ea9f0e..5f7918e0 100644 --- a/algorithm_libraries/python/graph/ford_fulkerson.py +++ b/algorithm_libraries/python/graph/ford_fulkerson.py @@ -1,4 +1,6 @@ INF = float("inf") + + class FordFulkerson: # Ford-Fulkerson algorithm # E: 辺の数, F: 最大流量 @@ -39,7 +41,7 @@ def flow(self, s, t): f = INF N = self.N while f: - self.used = [0]*N + self.used = [0] * N f = self.dfs(s, t, INF) flow += f - return flow \ No newline at end of file + return flow diff --git a/algorithm_libraries/python/math/catalan_number.py b/algorithm_libraries/python/math/catalan_number.py index dc5794f8..4eff9949 100644 --- a/algorithm_libraries/python/math/catalan_number.py +++ b/algorithm_libraries/python/math/catalan_number.py @@ -1,6 +1,6 @@ class Facts: # O(max_num) - def __init__(self, max_num: int = 10 ** 5, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int = 10**5, p: int = 10**9 + 7) -> None: self.p = p self.max_num = max_num * 2 self.fact = [1] * (self.max_num + 1) diff --git a/algorithm_libraries/python/math/combination.py b/algorithm_libraries/python/math/combination.py index b5a5bcca..9af5aff8 100644 --- a/algorithm_libraries/python/math/combination.py +++ b/algorithm_libraries/python/math/combination.py @@ -1,9 +1,9 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: # O(max_num) - def __init__(self, max_num: int = 10 ** 5, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int = 10**5, p: int = 10**9 + 7) -> None: self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/algorithm_libraries/python/math/counting_primes.py b/algorithm_libraries/python/math/counting_primes.py index 04aba31b..6efdbefd 100644 --- a/algorithm_libraries/python/math/counting_primes.py +++ b/algorithm_libraries/python/math/counting_primes.py @@ -4,8 +4,8 @@ def counting_primes(n: int) -> int: return 0 elif n <= 3: return 2 - v = int(n ** 0.5) - 1 - while v ** 2 <= n: + v = int(n**0.5) - 1 + while v**2 <= n: v += 1 v -= 1 smalls = [(i + 1) // 2 for i in range(v + 1)] diff --git a/algorithm_libraries/python/math/fact_comb_perm.py b/algorithm_libraries/python/math/fact_comb_perm.py index 743cf167..8aa1485a 100644 --- a/algorithm_libraries/python/math/fact_comb_perm.py +++ b/algorithm_libraries/python/math/fact_comb_perm.py @@ -1,9 +1,9 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: # O(max_num) - def __init__(self, max_num: int = 10 ** 5, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int = 10**5, p: int = 10**9 + 7) -> None: self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/algorithm_libraries/python/math/flt.py b/algorithm_libraries/python/math/flt.py index b263c412..3f2b7571 100644 --- a/algorithm_libraries/python/math/flt.py +++ b/algorithm_libraries/python/math/flt.py @@ -4,7 +4,7 @@ class FLT: a^(-1) = a^(m-2) mod p """ - def __init__(self, mod: int = 10 ** 9 + 7) -> None: + def __init__(self, mod: int = 10**9 + 7) -> None: self.mod = mod def rep_sqr(self, base: int, k: int) -> int: @@ -17,5 +17,5 @@ def rep_sqr(self, base: int, k: int) -> int: return ans def inv(self, a: int) -> int: - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) diff --git a/algorithm_libraries/python/math/lcm_list_mod.py b/algorithm_libraries/python/math/lcm_list_mod.py index 297d9d8a..877cdb7e 100644 --- a/algorithm_libraries/python/math/lcm_list_mod.py +++ b/algorithm_libraries/python/math/lcm_list_mod.py @@ -10,7 +10,7 @@ class LCM_mod: 因数の積を逐次余りに置き換えて最小公倍数を導出する. """ - def __init__(self, max_num: int, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int, p: int = 10**9 + 7) -> None: self.max_num = max_num + 1 self.p = p self.prime = [0 for _ in range(self.max_num)] diff --git a/algorithm_libraries/python/math/rep_pow.py b/algorithm_libraries/python/math/rep_pow.py index 630edea0..e68846d4 100644 --- a/algorithm_libraries/python/math/rep_pow.py +++ b/algorithm_libraries/python/math/rep_pow.py @@ -1,4 +1,4 @@ -def rep_pow(a: int, k: int, p: int = 10 ** 9 + 7) -> int: +def rep_pow(a: int, k: int, p: int = 10**9 + 7) -> int: # calculate exponentiation: a^k mod p # O(log(p)) ans = 1 diff --git a/algorithm_libraries/python/math/sieve_of_eratosthenes.py b/algorithm_libraries/python/math/sieve_of_eratosthenes.py index 2697410d..2b19552a 100644 --- a/algorithm_libraries/python/math/sieve_of_eratosthenes.py +++ b/algorithm_libraries/python/math/sieve_of_eratosthenes.py @@ -8,7 +8,7 @@ def sieve_of_eratosthenes( is_prime_list = [True] * (n + 1) is_prime_list[0] = False is_prime_list[1] = False - for i in range(2, int(n ** 0.5) + 1): + for i in range(2, int(n**0.5) + 1): if not is_prime_list[i]: continue for j in range(i * 2, n + 1, i): diff --git a/algorithm_libraries/test/sample_generator/data_structure/union_find.py b/algorithm_libraries/test/sample_generator/data_structure/union_find.py index d67fc8ad..e7fed9d3 100644 --- a/algorithm_libraries/test/sample_generator/data_structure/union_find.py +++ b/algorithm_libraries/test/sample_generator/data_structure/union_find.py @@ -54,8 +54,8 @@ def group_count(self) -> int: sample_size = 10 - n = random.randint(1, 2 * 10 ** 5) - q = random.randint(1, 2 * 10 ** 5) + n = random.randint(1, 2 * 10**5) + q = random.randint(1, 2 * 10**5) out = [f"{n} {q}"] ans = [] for _ in range(q): diff --git a/aoj/library/dpl/1/a.py b/aoj/library/dpl/1/a.py index 77f42cb0..87a0b18c 100644 --- a/aoj/library/dpl/1/a.py +++ b/aoj/library/dpl/1/a.py @@ -1,7 +1,7 @@ n, m = map(int, input().split()) c = list(map(int, input().split())) -INF = 10 ** 9 +INF = 10**9 MAX = n + 1 dp = [INF for _ in range(MAX)] dp[0] = 0 diff --git a/aoj/library/dpl/1/d.py b/aoj/library/dpl/1/d.py index 90b58c2b..425e0a7e 100644 --- a/aoj/library/dpl/1/d.py +++ b/aoj/library/dpl/1/d.py @@ -3,7 +3,7 @@ n = int(input()) a = [int(input()) for _ in range(n)] -INF = 10 ** 9 +INF = 10**9 dp = [INF for _ in range(n)] dp[0] = a[0] diff --git a/aoj/library/dpl/1/f.py b/aoj/library/dpl/1/f.py index d63b1917..1275bb8a 100644 --- a/aoj/library/dpl/1/f.py +++ b/aoj/library/dpl/1/f.py @@ -3,7 +3,7 @@ vw = [(int(x[0]), int(x[1])) for x in vw] v_max = sum([x[0] for x in vw]) -INF = 10 ** 9 + 1 +INF = 10**9 + 1 pdp = [INF for _ in range(v_max + 1)] cdp = [INF for _ in range(v_max + 1)] pdp[0] = 0 diff --git a/aoj/library/dsl/f.py b/aoj/library/dsl/f.py index d34f11f4..62ff763c 100644 --- a/aoj/library/dsl/f.py +++ b/aoj/library/dsl/f.py @@ -14,20 +14,20 @@ def __init__(self, n: int, mode: str = "min") -> None: self.n = n self.mode = mode unit_elements = { - "min": 2 ** 31 - 1, - "max": -(10 ** 13), + "min": 2**31 - 1, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, } self.e = unit_elements[self.mode] # 単位元 self.lv = (self.n - 1).bit_length() - self.tree_size = 2 ** self.lv # n以上の最小の2のべき乗数 + self.tree_size = 2**self.lv # n以上の最小の2のべき乗数 self.tree_value = [self.e] * (2 * self.tree_size) self.tree_lazy = [None] * (2 * self.tree_size) def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 diff --git a/aoj/library/ntl/1/b.py b/aoj/library/ntl/1/b.py index 52eacbe6..eaf2abeb 100644 --- a/aoj/library/ntl/1/b.py +++ b/aoj/library/ntl/1/b.py @@ -1,4 +1,4 @@ -def rep_pow(a, k, p=10 ** 9 + 7): +def rep_pow(a, k, p=10**9 + 7): # calculate exponentiation: a^k mod p ans = 1 while k > 0: diff --git a/atcoder/AGC/AGC043/a.py b/atcoder/AGC/AGC043/a.py index 6a8636b0..0ed2a430 100644 --- a/atcoder/AGC/AGC043/a.py +++ b/atcoder/AGC/AGC043/a.py @@ -2,7 +2,7 @@ h, w = map(int, input().split()) s = [[i for i in list(str(input()))] for i in range(h)] -INF = 10 ** 9 +INF = 10**9 dp = [[INF for _ in range(w)] for _ in range(h)] diff --git a/atcoder/AGC/agc029/b.py b/atcoder/AGC/agc029/b.py index 18f8fe08..ccf93c3a 100644 --- a/atcoder/AGC/agc029/b.py +++ b/atcoder/AGC/agc029/b.py @@ -5,7 +5,7 @@ candidates = [] for i in range(1, 32): - candidates.append(2 ** i) + candidates.append(2**i) candidates.sort(reverse=True) counter = defaultdict(int) diff --git a/atcoder/AGC/agc036/agc036_b.py b/atcoder/AGC/agc036/agc036_b.py index c9dc3897..87c059ff 100644 --- a/atcoder/AGC/agc036/agc036_b.py +++ b/atcoder/AGC/agc036/agc036_b.py @@ -1,7 +1,7 @@ n, k = map(int, input().split()) a = list(map(int, input().split())) -a_idx = [-1] * (2 * 10 ** 5) -ans = [0] * (2 * 10 ** 5) +a_idx = [-1] * (2 * 10**5) +ans = [0] * (2 * 10**5) idx = 0 for i in range(n * k): a_i = a[i % n] diff --git a/atcoder/AGC/agc062/c.py b/atcoder/AGC/agc062/c.py index 56fb2bae..c2328543 100644 --- a/atcoder/AGC/agc062/c.py +++ b/atcoder/AGC/agc062/c.py @@ -5,7 +5,7 @@ def solve1(n, k, a): - max_a = 10 ** 5 + max_a = 10**5 dp = [[False] * (max_a) for _ in range(n + 1)] # dp[i][j] := i番目までの数を使ってjを作れるか dp[0][0] = True diff --git a/atcoder/AGC/agc063/a.py b/atcoder/AGC/agc063/a.py index 4b166568..12716dc8 100644 --- a/atcoder/AGC/agc063/a.py +++ b/atcoder/AGC/agc063/a.py @@ -1,9 +1,10 @@ from collections import deque + n = int(input()) s = list(input()) a_list = [] b_list = [] -INF = 10 ** 10 +INF = 10**10 for i in range(len(s)): s_i = s[i] if s_i == "A": @@ -44,4 +45,4 @@ else: ans.append("Bob") -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/AGC/agc063/b.py b/atcoder/AGC/agc063/b.py index 33a62b60..522ea7d3 100644 --- a/atcoder/AGC/agc063/b.py +++ b/atcoder/AGC/agc063/b.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n = int(input()) a = list(map(int, input().split())) @@ -16,12 +17,12 @@ while len(queue) > 0 and queue[-1] != a_i - 1: queue.pop() if len(queue) > 0: - queue.pop() # a_i - 1を消す + queue.pop() # a_i - 1を消す queue.append(a_i) else: queue.append(1) # a_i = Rとするパターン数をansに加算する - ans += len(queue) # 嘘っぽい + ans += len(queue) # 嘘っぽい # print(ans, queue) # print(counter) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/AGC/agc063/c.py b/atcoder/AGC/agc063/c.py index 8d16aed8..325db7f0 100644 --- a/atcoder/AGC/agc063/c.py +++ b/atcoder/AGC/agc063/c.py @@ -5,4 +5,4 @@ # N < 1000 # a_i -> a_i + x mod yでb_iを作る # 基準を決めて、そこに合わせるようにmod操作をすれば良い -# 最小と最大の \ No newline at end of file +# 最小と最大の diff --git a/atcoder/AGC/agc063/d.py b/atcoder/AGC/agc063/d.py index ce59181d..81df340b 100644 --- a/atcoder/AGC/agc063/d.py +++ b/atcoder/AGC/agc063/d.py @@ -7,44 +7,48 @@ def mod(a, m): res += m return res + def extGCD(a, b, p=0, q=0): if b == 0: p = 1 q = 0 return a, p, q - d, q, p = extGCD(b, a%b) + d, q, p = extGCD(b, a % b) q -= a // b * p return d, p, q + def modinv(a, m): d, x, y = extGCD(a, m) return mod(x, m) # 気持ち的には x % m だが、x が負かもしれないので + def garner(b, m, MOD): m.append(MOD) # 番兵 coeffs = [1 for _ in range(len(m))] constants = [0 for _ in range(len(m))] for k in range(len(b)): t = mod((b[k] - constants[k]) * modinv(coeffs[k], m[k]), m[k]) - for i in range(k+1, len(m)): + for i in range(k + 1, len(m)): constants[i] += t * coeffs[i] constants[i] %= m[i] coeffs[i] *= m[k] coeffs[i] %= m[i] return constants[-1] + n, a, b, c, d = map(int, input().split()) r = [] m = [] max_p = 0 max_q = 0 for k in range(n): - q = (a + k * b) - p = (c + k * d) + q = a + k * b + p = c + k * d max_p = max(max_p, p) max_q = max(max_q, q) r.append(p) m.append(q) x = garner(r, m, MOD) print(max_p, max_q) -print(x) \ No newline at end of file +print(x) diff --git a/atcoder/AGC/agc064/a.py b/atcoder/AGC/agc064/a.py index cfa8ac42..6235a749 100644 --- a/atcoder/AGC/agc064/a.py +++ b/atcoder/AGC/agc064/a.py @@ -1,5 +1,6 @@ import sys from collections import defaultdict, deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -36,5 +37,3 @@ print(*ans, sep=" ") - - diff --git a/atcoder/AGC/agc064/b.py b/atcoder/AGC/agc064/b.py index ace5578c..d8cb4e48 100644 --- a/atcoder/AGC/agc064/b.py +++ b/atcoder/AGC/agc064/b.py @@ -1,12 +1,15 @@ # AGC064B import sys from collections import defaultdict, deque + import pypyjit -pypyjit.set_param('max_unroll_recursion=-1') + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -class UnionFind(): + +class UnionFind: def __init__(self, n): self.n = n + 1 self.parents = [-1] * (n + 1) @@ -51,7 +54,8 @@ def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): - return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) + return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) + n, m = map(int, input().split()) edges = defaultdict(lambda: defaultdict(lambda: [])) @@ -133,4 +137,4 @@ def __str__(self): print("Yes") print(*ans, sep=" ") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/AGC/agc064/d.py b/atcoder/AGC/agc064/d.py index e685a3a9..92f1ce3f 100644 --- a/atcoder/AGC/agc064/d.py +++ b/atcoder/AGC/agc064/d.py @@ -25,7 +25,7 @@ for i in range(1, n + 1): # それまでにj個Bを使っている for j in range(i): - b_count = counter["B"] - j # 使えるBの数 + b_count = counter["B"] - j # 使えるBの数 r_count = n - i - b_count # 使えるRの数 if i == n: print("print", i, j, r_count, b_count) diff --git a/atcoder/AGC/agc065/a.py b/atcoder/AGC/agc065/a.py index a4d3b9d6..112942da 100644 --- a/atcoder/AGC/agc065/a.py +++ b/atcoder/AGC/agc065/a.py @@ -1,7 +1,8 @@ +from bisect import bisect_left, bisect_right from collections import deque from time import time -from bisect import bisect_left, bisect_right -INF = float('inf') + +INF = float("inf") start_at = time() n, k = map(int, input().split()) @@ -9,6 +10,8 @@ a = sorted(a, reverse=True) ans = 0 + + def calc_score(x): score = 0 n = len(x) @@ -17,6 +20,7 @@ def calc_score(x): # print(x[i + 1], x[i], score) return score + cumsum = [0] * (n) for i in range(n - 1): cumsum[i + 1] = cumsum[i] + (a[i + 1] - a[i]) % k @@ -31,4 +35,3 @@ def calc_score(x): ans = max(ans, ansi) print(ans) - diff --git a/atcoder/AHC/open/ahc014/ahc014.py b/atcoder/AHC/open/ahc014/ahc014.py index fe274623..55a9fc89 100644 --- a/atcoder/AHC/open/ahc014/ahc014.py +++ b/atcoder/AHC/open/ahc014/ahc014.py @@ -282,7 +282,7 @@ def sum_q(): q_score += w[i][j] return q_score / s - return round(10 ** 6 * (self.size ** 2 / self.m) * sum_q()) + return round(10**6 * (self.size**2 / self.m) * sum_q()) def add_process(self, sides: List[Any], coordinates: List[Coordinate]) -> None: p = Process(c=coordinates[0], sides=sides, coordinates=coordinates) diff --git a/atcoder/AHC/open/ahc014/simple.py b/atcoder/AHC/open/ahc014/simple.py index 56e5dec3..e606ab12 100644 --- a/atcoder/AHC/open/ahc014/simple.py +++ b/atcoder/AHC/open/ahc014/simple.py @@ -226,7 +226,7 @@ def sum_q(): q_score += w[i][j] return q_score / s - return round(10 ** 6 * (self.size ** 2 / self.m) * sum_q()) + return round(10**6 * (self.size**2 / self.m) * sum_q()) def add_answers(self, coordinates: List[Coordinate]) -> None: self.answers.append(coordinates) diff --git a/atcoder/AHC/open/ahc026/a.py b/atcoder/AHC/open/ahc026/a.py index dd079a3b..156b813d 100644 --- a/atcoder/AHC/open/ahc026/a.py +++ b/atcoder/AHC/open/ahc026/a.py @@ -1,15 +1,16 @@ -import time -import os import itertools +import os +import time from collections import defaultdict, deque from typing import List TIME_LIMIT = 1.90 MAX_PROCESS = 5_000 -INF = 10 ** 12 +INF = 10**12 is_debug_mode = os.getenv("DEBUG_MODE", False) + class Model: def __init__(self, n, m, init_postions): self.n = n @@ -84,7 +85,7 @@ def pickup_top(self): count += 1 return count > 0 - def sort_top(self, diff = 1): + def sort_top(self, diff=1): # 終盤の効率化 # 一番上にあるもの同士がdiff以下の場合乗せる count = 0 @@ -98,7 +99,11 @@ def sort_top(self, diff = 1): for i in tops.keys(): for j in range(1, diff + 1): if i + j in tops.keys(): - if len(self.mountains[tops[i] - 1]) > 1 and self.mountains[tops[i] - 1][-2] < i + j and self.mountains[tops[i] - 1][-2] > i: + if ( + len(self.mountains[tops[i] - 1]) > 1 + and self.mountains[tops[i] - 1][-2] < i + j + and self.mountains[tops[i] - 1][-2] > i + ): continue self.ans.append([i, tops[i + j]]) self.mv(i, tops[i + j]) @@ -107,8 +112,7 @@ def sort_top(self, diff = 1): break return count > 0 - - def zero_fix(self, zero_fix_pattern = 1): + def zero_fix(self, zero_fix_pattern=1): # ゼロ山がある場合、一番下にない最も小さい数字を移動させる zero_mountain = self.find_zero_mountain() flag = True @@ -117,7 +121,7 @@ def zero_fix(self, zero_fix_pattern = 1): zero_mountain = self.find_zero_mountain() flag = False if zero_mountain != -1: - bottoms = set() # 対象外 + bottoms = set() # 対象外 # 一番下にある数字は除外 for m in self.mountains: if len(m) == 0: @@ -157,8 +161,7 @@ def to_mountain(self, mountain_num): to_mountain = [len(self.mountains[mountain_i - 1]), mountain_i] return to_mountain[1] - - def fix_mountains(self, target_num, mountain_num, max_diff = 1000): + def fix_mountains(self, target_num, mountain_num, max_diff=1000): # queueに入ってる数字の登場が最も遅い山に移動させる pre_num = -INF for i in reversed(range(len(self.mountains[mountain_num - 1]))): @@ -198,7 +201,8 @@ def solve_naive(self, top_sort_diff=0, zero_fix_pattern=0, max_diff=1000): # 山の中にある場合 self.fix_mountains(target_num, mountain_num, max_diff=max_diff) if zero_fix_pattern > 0: - self.zero_fix(zero_fix_pattern) # ゼロ山に最も大きい数を移動させる + self.zero_fix(zero_fix_pattern) # ゼロ山に最も大きい数を移動させる + def main(): start_at = time.time() @@ -210,7 +214,26 @@ def main(): config = { "top_sort_diff": [0, 1, 2, 3], "zero_fix_pattern": [0, 1, 2], - "max_diff": [5, 10, 15, 20, 25, 30, 35, 40, 50, 55, 60, 65, 70, 75, 80, 90, 100, 1000], + "max_diff": [ + 5, + 10, + 15, + 20, + 25, + 30, + 35, + 40, + 50, + 55, + 60, + 65, + 70, + 75, + 80, + 90, + 100, + 1000, + ], } p = itertools.product(*config.values()) @@ -231,4 +254,6 @@ def main(): if is_debug_mode: print(model.score()) print(params) -main() \ No newline at end of file + + +main() diff --git a/atcoder/AHC/open/ahc026/after_contest.py b/atcoder/AHC/open/ahc026/after_contest.py index ffdb2f27..ef57451d 100644 --- a/atcoder/AHC/open/ahc026/after_contest.py +++ b/atcoder/AHC/open/ahc026/after_contest.py @@ -1,16 +1,17 @@ -import time +import itertools import os import random -import itertools +import time from collections import defaultdict, deque from typing import List TIME_LIMIT = 1.90 MAX_PROCESS = 5_000 -INF = 10 ** 12 +INF = 10**12 is_debug_mode = os.getenv("DEBUG_MODE", False) + class Model: def __init__(self, n, m, init_postions): self.n = n @@ -107,12 +108,11 @@ def give_mountain(self, mountain_num): to_i = [-1, rand_i] self.mv(from_v, to_i[1]) - def get_mountain(self, mountain_num): current_num = INF for _ in range(1000): self.pickup_top() - process = [-1, -1] # [v, from_i] + process = [-1, -1] # [v, from_i] for i in range(1, self.m + 1): if i == mountain_num: continue @@ -172,6 +172,7 @@ def solve_naive(self): self.fix_mountains() self.solve_last() + def main(): start_at = time.time() n, m = map(int, input().split()) @@ -184,4 +185,6 @@ def main(): if is_debug_mode: print(model.score()) print(params) -main() \ No newline at end of file + + +main() diff --git a/atcoder/AHC/open/ahc026/sample.py b/atcoder/AHC/open/ahc026/sample.py index 3dbce9d4..aa9dea1d 100644 --- a/atcoder/AHC/open/ahc026/sample.py +++ b/atcoder/AHC/open/ahc026/sample.py @@ -5,4 +5,4 @@ for j in range(1, 21): ai.append(j + i * 20) a.append(" ".join(list(map(str, ai)))) -print("\n".join(a)) \ No newline at end of file +print("\n".join(a)) diff --git a/atcoder/ARC/arc006/c.py b/atcoder/ARC/arc006/c.py index 90980f7d..f6a54ec1 100644 --- a/atcoder/ARC/arc006/c.py +++ b/atcoder/ARC/arc006/c.py @@ -1,6 +1,6 @@ n = int(input()) w = [int(input()) for _ in range(n)] -INF = 10 ** 12 +INF = 10**12 # 山の数を1~Nで全探索する ans = INF diff --git a/atcoder/ARC/arc042/b.py b/atcoder/ARC/arc042/b.py index 5cad68bd..ebe9d870 100644 --- a/atcoder/ARC/arc042/b.py +++ b/atcoder/ARC/arc042/b.py @@ -11,7 +11,7 @@ b = X[i - 1] - X[i] c = Y[i - 1] * (X[i] - X[i - 1]) - X[i - 1] * (Y[i] - Y[i - 1]) d = abs(a * x + b * y + c) - e = (a ** 2 + b ** 2) ** 0.5 + e = (a**2 + b**2) ** 0.5 d = d / e ans = min(ans, d) diff --git a/atcoder/ARC/arc049/b.py b/atcoder/ARC/arc049/b.py index ee6960ab..f28b002d 100644 --- a/atcoder/ARC/arc049/b.py +++ b/atcoder/ARC/arc049/b.py @@ -2,8 +2,8 @@ xyc = [list(map(int, input().split())) for _ in range(n)] # x, yでそれぞれ二分探索 -INF = 10 ** 12 -l = -(10 ** 5) -r = 10 ** 5 +INF = 10**12 +l = -(10**5) +r = 10**5 pre_cost = INF cost = INF * 2 diff --git a/atcoder/ARC/arc054/a.py b/atcoder/ARC/arc054/a.py index ce1b730f..1207b8e2 100644 --- a/atcoder/ARC/arc054/a.py +++ b/atcoder/ARC/arc054/a.py @@ -7,7 +7,7 @@ v1 = x + y # 右 v2 = -(x - y) # 左 -ans = 10 ** 9 +ans = 10**9 for d in [d1, d2, d3]: if s < d: ans = min(ans, (d - s) / v1) diff --git a/atcoder/ARC/arc135/c.py b/atcoder/ARC/arc135/c.py index c0bdc815..7e3200a5 100644 --- a/atcoder/ARC/arc135/c.py +++ b/atcoder/ARC/arc135/c.py @@ -16,8 +16,8 @@ for bit_i in range(max_k): if (x >> bit_i) & 1: # xのbit_i桁目にbitが立っていた場合 - ans_i += (2 ** bit_i) * (n - bit_sum[bit_i]) + ans_i += (2**bit_i) * (n - bit_sum[bit_i]) else: - ans_i += (2 ** bit_i) * bit_sum[bit_i] + ans_i += (2**bit_i) * bit_sum[bit_i] ans = max(ans, ans_i) print(ans) diff --git a/atcoder/ARC/arc159/b.py b/atcoder/ARC/arc159/b.py index 186a5644..72ba7420 100644 --- a/atcoder/ARC/arc159/b.py +++ b/atcoder/ARC/arc159/b.py @@ -6,7 +6,7 @@ def gcd(a, b): def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: diff --git a/atcoder/ARC/arc160/b.py b/atcoder/ARC/arc160/b.py index c1c12e79..0492ed89 100644 --- a/atcoder/ARC/arc160/b.py +++ b/atcoder/ARC/arc160/b.py @@ -19,13 +19,13 @@ def solve1(n): sqrt_n = math.floor(math.sqrt(n)) sum1 = 0 # 1 ~ sqrt_nまでのx, y, zの組み合わせ数 - sum1 += sqrt_n ** 3 + sum1 += sqrt_n**3 sum1 %= MOD # sqrt_n + 1 ~ nまでのx, y, zの組み合わせ数 # sum1 -= 1 s = 0 for x in range(1, math.ceil(math.sqrt(n))): - s += (math.floor(n / x) - math.floor(n / (x + 1))) * (x ** 2) + s += (math.floor(n / x) - math.floor(n / (x + 1))) * (x**2) s %= MOD sum1 += s * 3 sum1 %= MOD diff --git a/atcoder/ARC/arc163/c.py b/atcoder/ARC/arc163/c.py index fd698a79..d1c49cb9 100644 --- a/atcoder/ARC/arc163/c.py +++ b/atcoder/ARC/arc163/c.py @@ -4,7 +4,7 @@ input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -MAX = 10 ** 9 +MAX = 10**9 def sep(n): diff --git a/atcoder/ARC/arc166/a.py b/atcoder/ARC/arc166/a.py index d1aaf677..463c88d1 100644 --- a/atcoder/ARC/arc166/a.py +++ b/atcoder/ARC/arc166/a.py @@ -1,6 +1,8 @@ from collections import defaultdict, deque + t = int(input()) + def solve(n, x, y): # x, y はABCからなる文字列 # A...B...の順に変形する @@ -67,9 +69,8 @@ def solve(n, x, y): return "Yes" - ans = [] for _ in range(t): n, x, y = input().split() ans.append(solve(n, x, y)) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/ARC/arc166/b.py b/atcoder/ARC/arc166/b.py index cabfe738..de8cce97 100644 --- a/atcoder/ARC/arc166/b.py +++ b/atcoder/ARC/arc166/b.py @@ -1,13 +1,15 @@ import itertools import sys -import pypyjit -from functools import lru_cache from collections import defaultdict +from functools import lru_cache -pypyjit.set_param('max_unroll_recursion=-1') +import pypyjit + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) + @lru_cache(maxsize=None) def gcd(a: int, b: int) -> int: # 最大公約数 @@ -16,6 +18,7 @@ def gcd(a: int, b: int) -> int: a, b = b, a % b return a + @lru_cache(maxsize=None) def lcm(x: int, y: int) -> int: # 最小公倍数 @@ -58,7 +61,7 @@ def lcm(x: int, y: int) -> int: continue candidate = [] for pattern_i in pattern_orders: - candidate.append(mod_abc[pattern_i][:len(pattern_orders)]) + candidate.append(mod_abc[pattern_i][: len(pattern_orders)]) for candidatei in itertools.product(*candidate): used_i = set() cost = 0 diff --git a/atcoder/ARC/arc167/a.py b/atcoder/ARC/arc167/a.py index a3a13c0f..2f7c3ddc 100644 --- a/atcoder/ARC/arc167/a.py +++ b/atcoder/ARC/arc167/a.py @@ -1,4 +1,5 @@ from collections import deque + n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() @@ -19,4 +20,4 @@ for bi in b: ans += sum(bi) ** 2 # print(b) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/ARC/arc167/b.py b/atcoder/ARC/arc167/b.py index 8843fa84..3df83d6e 100644 --- a/atcoder/ARC/arc167/b.py +++ b/atcoder/ARC/arc167/b.py @@ -1,4 +1,5 @@ from collections import defaultdict + MOD = 998244353 a, b = map(int, input().split()) @@ -7,6 +8,7 @@ exit() # a**bの正の約数の総積はaで何回割り切れるか + def prime_factorize(n): # 素因数分解 # Return list of prime factorized result @@ -26,9 +28,10 @@ def prime_factorize(n): a.append(n) return a + def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if i == n: continue if n % i == 0: @@ -41,13 +44,14 @@ def make_divisors(n): divisors.sort() return divisors + class FLT: """ フェルマーの小定理 a^(-1) = a^(m-2) mod p """ - def __init__(self, mod: int = 10 ** 9 + 7) -> None: + def __init__(self, mod: int = 10**9 + 7) -> None: self.mod = mod def rep_sqr(self, base: int, k: int) -> int: @@ -60,9 +64,10 @@ def rep_sqr(self, base: int, k: int) -> int: return ans def inv(self, a: int) -> int: - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) + a_primes = prime_factorize(a) prime_counter = defaultdict(int) for ai in a_primes: @@ -87,4 +92,4 @@ def inv(self, a: int) -> int: minus *= b * (b + 1) // 2 minus %= counter[target_num] # これだとtarget_numの個数で、target_numがaに2個以上含まれる場合を考慮できていない -print((ans - minus) % MOD) \ No newline at end of file +print((ans - minus) % MOD) diff --git a/atcoder/ARC/arc168/a.py b/atcoder/ARC/arc168/a.py index eeee5d3a..c2a2b1c1 100644 --- a/atcoder/ARC/arc168/a.py +++ b/atcoder/ARC/arc168/a.py @@ -4,10 +4,10 @@ # https://output-zakki.com/inversion_number/ class BIT: def __init__(self, n): - self.size=n - self.tree = [0] * (n+1) - - def add(self, i,x): + self.size = n + self.tree = [0] * (n + 1) + + def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i @@ -19,6 +19,7 @@ def sum(self, i): i -= i & -i return total + def InversionNumberByBIT(A): ans = 0 Bit = BIT(max(len(A) + 1, max(A) + 1)) @@ -27,6 +28,7 @@ def InversionNumberByBIT(A): Bit.add(A[i], 1) return ans + counter = [] # ">"が連続する数を数える count = 0 @@ -54,4 +56,4 @@ def InversionNumberByBIT(A): x[i] += 1 # print(counter) # print(x) -print(InversionNumberByBIT(x)) \ No newline at end of file +print(InversionNumberByBIT(x)) diff --git a/atcoder/ARC/arc168/a_after_contest.py b/atcoder/ARC/arc168/a_after_contest.py index 7618126f..c29571be 100644 --- a/atcoder/ARC/arc168/a_after_contest.py +++ b/atcoder/ARC/arc168/a_after_contest.py @@ -1,12 +1,13 @@ n = int(input()) s = list(input()) + class BIT: def __init__(self, n): - self.size=n - self.tree = [0] * (n+1) + self.size = n + self.tree = [0] * (n + 1) - def add(self, i,x): + def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i @@ -18,6 +19,7 @@ def sum(self, i): i -= i & -i return total + def InversionNumberByBIT(A): ans = 0 Bit = BIT(max(len(A) + 1, max(A) + 1)) @@ -26,11 +28,12 @@ def InversionNumberByBIT(A): Bit.add(A[i], 1) return ans + x = [1] for si in s: if si == "<": - x.append(x[-1] + 10 ** 9) + x.append(x[-1] + 10**9) else: x.append(x[-1] - 1) @@ -43,4 +46,4 @@ def InversionNumberByBIT(A): for i in range(len(x)): x[i] = x_dict[x[i]] -print(InversionNumberByBIT(x)) \ No newline at end of file +print(InversionNumberByBIT(x)) diff --git a/atcoder/ARC/arc168/b.py b/atcoder/ARC/arc168/b.py index 6e17a82f..52c73b65 100644 --- a/atcoder/ARC/arc168/b.py +++ b/atcoder/ARC/arc168/b.py @@ -1,14 +1,16 @@ -from collections import defaultdict from bisect import bisect_left, bisect_right +from collections import defaultdict + n = int(input()) a = list(map(int, input().split())) xor_sum_memo = defaultdict(int) # 大きい順に試す a.sort() -INF = 10 ** 16 +INF = 10**16 for ai in a: - xor_sum_memo[INF] ^= ai + xor_sum_memo[INF] ^= ai + def nim(k, pre_k=INF): # 更新分だけ追加計算 @@ -16,19 +18,20 @@ def nim(k, pre_k=INF): xor_sum = xor_sum_memo[pre_k] idx = bisect_left(a, k + 1) for i in range(idx, len(a)): - + if a[i] < k + 1: continue if a[i] > pre_k: break xor_sum ^= a[i] - xor_sum ^= (a[i] % (k + 1)) + xor_sum ^= a[i] % (k + 1) xor_sum_memo[k] = xor_sum if xor_sum == 0: return -1 else: return k + ans = [] pre_k = INF k_candidates = [] @@ -52,4 +55,4 @@ def nim(k, pre_k=INF): elif max(ans) >= max(a): print(-1) else: - print(max(ans)) \ No newline at end of file + print(max(ans)) diff --git a/atcoder/ARC/arc168/c.py b/atcoder/ARC/arc168/c.py index cebaf123..e36a3fe0 100644 --- a/atcoder/ARC/arc168/c.py +++ b/atcoder/ARC/arc168/c.py @@ -1,4 +1,5 @@ from collections import defaultdict + MOD = 998244353 n, k = map(int, input().split()) @@ -26,21 +27,33 @@ ansi = 0 # AB if counter["A"] - abi > 0 and counter["B"] - abi > 0: - v = memo[abi][bci][cai] * (counter["A"] - abi) * (counter["B"] - abi) + v = ( + memo[abi][bci][cai] + * (counter["A"] - abi) + * (counter["B"] - abi) + ) memo[abi + 1][bci][cai] += v memo[abi + 1][bci][cai] %= MOD ansi += v ansi %= MOD # BC if counter["B"] - bci > 0 and counter["C"] - bci > 0: - v = memo[abi][bci][cai] * (counter["B"] - bci) * (counter["C"] - bci) + v = ( + memo[abi][bci][cai] + * (counter["B"] - bci) + * (counter["C"] - bci) + ) memo[abi][bci + 1][cai] += v memo[abi][bci + 1][cai] %= MOD ansi += v ansi %= MOD # CA if counter["C"] - cai > 0 and counter["A"] - cai > 0: - v = memo[abi][bci][cai] * (counter["C"] - cai) * (counter["A"] - cai) + v = ( + memo[abi][bci][cai] + * (counter["C"] - cai) + * (counter["A"] - cai) + ) memo[abi][bci][cai + 1] += v memo[abi][bci][cai + 1] %= MOD ansi += v @@ -69,4 +82,4 @@ ans -= memo[i][j][l] * (i + j + l - 1) ans %= MOD print(memo) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/ARC/arc168/test.py b/atcoder/ARC/arc168/test.py index 432f27dd..735e8b83 100644 --- a/atcoder/ARC/arc168/test.py +++ b/atcoder/ARC/arc168/test.py @@ -4,4 +4,4 @@ s = "" for i in range(n): s += "<" -print(s) \ No newline at end of file +print(s) diff --git a/atcoder/ARC/arc170/a.py b/atcoder/ARC/arc170/a.py index 60c88121..0c57bc31 100644 --- a/atcoder/ARC/arc170/a.py +++ b/atcoder/ARC/arc170/a.py @@ -1,5 +1,6 @@ from collections import deque -INF = float('inf') + +INF = float("inf") n = int(input()) s = list(input()) t = list(input()) @@ -10,7 +11,7 @@ for i, (si, ti) in enumerate(zip(s, t)): if si != ti: - if si == 'A': + if si == "A": queue_a.append(i) else: queue_b.append(i) @@ -73,4 +74,4 @@ if ans == INF: print(-1) else: - print(ans) \ No newline at end of file + print(ans) diff --git a/atcoder/ARC/arc170/b.py b/atcoder/ARC/arc170/b.py index 737df302..d48b2e49 100644 --- a/atcoder/ARC/arc170/b.py +++ b/atcoder/ARC/arc170/b.py @@ -1,5 +1,5 @@ -from collections import defaultdict, deque import heapq +from collections import defaultdict, deque n = int(input()) a = list(map(int, input().split())) @@ -58,4 +58,4 @@ r, l = queue[0] ans += n - r -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/ARC/arc170/c.py b/atcoder/ARC/arc170/c.py index ae791956..6fa66327 100644 --- a/atcoder/ARC/arc170/c.py +++ b/atcoder/ARC/arc170/c.py @@ -18,9 +18,9 @@ print(ans) for i in range(n): if ans[i] == -1: - ans_num *= (m - count + 1) + ans_num *= m - count + 1 ans_num %= MOD else: count -= 1 -print(ans_num) \ No newline at end of file +print(ans_num) diff --git a/atcoder/Ants/02/ABC002D.py b/atcoder/Ants/02/ABC002D.py index c2ec7006..12d81e74 100644 --- a/atcoder/Ants/02/ABC002D.py +++ b/atcoder/Ants/02/ABC002D.py @@ -7,11 +7,11 @@ input_set.append((x, y)) input_set = set(input_set) ans = 0 -for i in range(2 ** n): +for i in range(2**n): size = 0 l = [] for bit in range(n): - if i & 2 ** bit > 0: + if i & 2**bit > 0: size += 1 l.append(bit + 1) if len(l) < 2: diff --git a/atcoder/Ants/02/ABC104C.py b/atcoder/Ants/02/ABC104C.py index a3b20b65..f2351ba9 100644 --- a/atcoder/Ants/02/ABC104C.py +++ b/atcoder/Ants/02/ABC104C.py @@ -9,13 +9,13 @@ # 完全に解く 1 # 全く解かない 0 -min_cost = 10 ** 10 -for i in range(2 ** d): +min_cost = 10**10 +for i in range(2**d): count = 0 score = 0 use_list = [] for bit in range(d): - if i & 2 ** bit > 0: + if i & 2**bit > 0: use_list.append(bit + 1) count += p[bit] score += (bit + 1) * 100 * p[bit] + c[bit] diff --git a/atcoder/Ants/02/ARC029A.py b/atcoder/Ants/02/ARC029A.py index a21a1255..1a1c76ba 100644 --- a/atcoder/Ants/02/ARC029A.py +++ b/atcoder/Ants/02/ARC029A.py @@ -2,12 +2,12 @@ t = [0] * n for i in range(n): t[i] = int(input()) -ans = 10 ** 10 -for i in range(2 ** n): +ans = 10**10 +for i in range(2**n): a1 = 0 a2 = 0 for bit in range(n): - if i & 2 ** bit > 0: + if i & 2**bit > 0: a1 += t[bit] else: a2 += t[bit] diff --git a/atcoder/Ants/02/ARC061C.py b/atcoder/Ants/02/ARC061C.py index def7fa14..13e4552a 100644 --- a/atcoder/Ants/02/ARC061C.py +++ b/atcoder/Ants/02/ARC061C.py @@ -4,7 +4,7 @@ for i in range(2 ** (len(s) - 1)): l = [] for b in range(len(s)): - bit = 2 ** b + bit = 2**b if i & bit > 0: l.append(b) if len(l) == 0: diff --git a/atcoder/DSL/RMQ.py b/atcoder/DSL/RMQ.py index 8fc93adc..d4511d1e 100644 --- a/atcoder/DSL/RMQ.py +++ b/atcoder/DSL/RMQ.py @@ -52,7 +52,7 @@ def query_min(self, p, q): return res -e = (2 ** 31) - 1 +e = (2**31) - 1 rmq = RMQ(n, e) for i in range(q): diff --git a/atcoder/JOI/joisc2020/a.py b/atcoder/JOI/joisc2020/a.py index 1a1aea5d..a1a6746d 100644 --- a/atcoder/JOI/joisc2020/a.py +++ b/atcoder/JOI/joisc2020/a.py @@ -10,7 +10,7 @@ # あり得る最大と最小のA個数を持っておく # 最後に後ろからたどっていけば行けるはず -INF = 2 ** 30 +INF = 2**30 dp = [[[INF, 0] for _ in range(2)] for _ in range(2 * n)] dp[0][0] = [1, 1] dp[0][1] = [0, 0] diff --git a/atcoder/abc/abc001-100/abc006/b.py b/atcoder/abc/abc001-100/abc006/b.py index 756e8974..69d325ee 100644 --- a/atcoder/abc/abc001-100/abc006/b.py +++ b/atcoder/abc/abc001-100/abc006/b.py @@ -1,6 +1,6 @@ n = int(input()) -a = [0] * (10 ** 6 + 1) +a = [0] * (10**6 + 1) a[3] = 1 -for i in range(4, 10 ** 6 + 1): +for i in range(4, 10**6 + 1): a[i] = (a[i - 1] + a[i - 2] + a[i - 3]) % 10007 print(a[n]) diff --git a/atcoder/abc/abc001-100/abc012/d.py b/atcoder/abc/abc001-100/abc012/d.py index 93c7a4d3..1b269b34 100644 --- a/atcoder/abc/abc001-100/abc012/d.py +++ b/atcoder/abc/abc001-100/abc012/d.py @@ -1,6 +1,6 @@ n, m = map(int, input().split()) -INF = 10 ** 9 +INF = 10**9 edges = [[INF for _ in range(n)] for _ in range(n)] for i in range(m): a, b, t = map(int, input().split()) diff --git a/atcoder/abc/abc001-100/abc014/b.py b/atcoder/abc/abc001-100/abc014/b.py index 31ff0c0a..739699ea 100644 --- a/atcoder/abc/abc001-100/abc014/b.py +++ b/atcoder/abc/abc001-100/abc014/b.py @@ -3,6 +3,6 @@ ans = 0 for i in range(n): - if 2 ** i & x: + if 2**i & x: ans += a[i] print(ans) diff --git a/atcoder/abc/abc001-100/abc014/c.py b/atcoder/abc/abc001-100/abc014/c.py index fcaa837e..e4ff97a3 100644 --- a/atcoder/abc/abc001-100/abc014/c.py +++ b/atcoder/abc/abc001-100/abc014/c.py @@ -2,7 +2,7 @@ input = sys.stdin.readline n = int(input()) -color = [0] * (10 ** 6 + 2) +color = [0] * (10**6 + 2) for i in range(n): a, b = map(int, input().split()) color[a] += 1 diff --git a/atcoder/abc/abc001-100/abc016/c.py b/atcoder/abc/abc001-100/abc016/c.py index 43934c55..75d52ea6 100644 --- a/atcoder/abc/abc001-100/abc016/c.py +++ b/atcoder/abc/abc001-100/abc016/c.py @@ -1,5 +1,5 @@ n, m = map(int, input().split()) -INF = 10 ** 10 +INF = 10**10 ab = [[INF for _ in range(n)] for _ in range(n)] for i in range(n): ab[i][i] = 0 diff --git a/atcoder/abc/abc001-100/abc021/c.py b/atcoder/abc/abc001-100/abc021/c.py index b461ba92..c60f3132 100644 --- a/atcoder/abc/abc001-100/abc021/c.py +++ b/atcoder/abc/abc001-100/abc021/c.py @@ -1,7 +1,7 @@ from heapq import heappop, heappush inf = float("inf") -mod = 10 ** 9 + 7 +mod = 10**9 + 7 def dijkstra(start, ad): diff --git a/atcoder/abc/abc001-100/abc022/b.py b/atcoder/abc/abc001-100/abc022/b.py index 5271ad93..26597f48 100644 --- a/atcoder/abc/abc001-100/abc022/b.py +++ b/atcoder/abc/abc001-100/abc022/b.py @@ -1,5 +1,5 @@ n = int(input()) -d = [0] * (10 ** 5 + 1) +d = [0] * (10**5 + 1) count = 0 for _ in range(n): a = int(input()) diff --git a/atcoder/abc/abc001-100/abc022/c.py b/atcoder/abc/abc001-100/abc022/c.py index 3fb5842e..a2a09f6b 100644 --- a/atcoder/abc/abc001-100/abc022/c.py +++ b/atcoder/abc/abc001-100/abc022/c.py @@ -2,7 +2,7 @@ import scipy.sparse.csgraph as cs N, M = map(int, input().split()) -INF = 10 ** 9 +INF = 10**9 G = np.array([[INF] * N for i in range(N)]) H = [] for _ in range(M): diff --git a/atcoder/abc/abc001-100/abc025/c.py b/atcoder/abc/abc001-100/abc025/c.py index 9516cd07..fb31bb3c 100644 --- a/atcoder/abc/abc001-100/abc025/c.py +++ b/atcoder/abc/abc001-100/abc025/c.py @@ -19,7 +19,7 @@ def solve(t, a): if a and (a in m): return m[a] - r, n = -(10 ** 10), (-1 if t % 2 == 1 else 1) + r, n = -(10**10), (-1 if t % 2 == 1 else 1) for i in range(9): if p[i] == 0: p[i] = n diff --git a/atcoder/abc/abc001-100/abc028/d.py b/atcoder/abc/abc001-100/abc028/d.py index 6a54c70d..72878125 100644 --- a/atcoder/abc/abc001-100/abc028/d.py +++ b/atcoder/abc/abc001-100/abc028/d.py @@ -1,6 +1,6 @@ n, k = map(int, input().split()) -amount = n ** 3 +amount = n**3 center = (k - 1) * (n - k) * 6 center += (k - 1) * 3 + (n - k) * 3 center += 1 diff --git a/atcoder/abc/abc001-100/abc030/c.py b/atcoder/abc/abc001-100/abc030/c.py index 4f980e0e..9322ef46 100644 --- a/atcoder/abc/abc001-100/abc030/c.py +++ b/atcoder/abc/abc001-100/abc030/c.py @@ -7,7 +7,7 @@ t = 0 count = 0 -for i in range(10 ** 5 + 1): +for i in range(10**5 + 1): a_idx = bisect.bisect_left(a, t) if a_idx >= n: break diff --git a/atcoder/abc/abc001-100/abc034/c.py b/atcoder/abc/abc001-100/abc034/c.py index 97479e45..b570bbe4 100644 --- a/atcoder/abc/abc001-100/abc034/c.py +++ b/atcoder/abc/abc001-100/abc034/c.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 w, h = map(int, input().split()) dp = [[1 for _ in range(w)] for _ in range(h)] diff --git a/atcoder/abc/abc001-100/abc034/c2.py b/atcoder/abc/abc001-100/abc034/c2.py index 0decf0fc..53761c3a 100644 --- a/atcoder/abc/abc001-100/abc034/c2.py +++ b/atcoder/abc/abc001-100/abc034/c2.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 w, h = map(int, input().split()) # (h+w-2)! diff --git a/atcoder/abc/abc001-100/abc035/d.py b/atcoder/abc/abc001-100/abc035/d.py index ee136e7c..df47b1f4 100644 --- a/atcoder/abc/abc001-100/abc035/d.py +++ b/atcoder/abc/abc001-100/abc035/d.py @@ -7,7 +7,7 @@ n, m, t = map(int, input().split()) A = list(map(int, input().split())) abc = [list(map(int, input().split())) for _ in range(m)] -edges = defaultdict(lambda: defaultdict(lambda: 10 ** 10)) +edges = defaultdict(lambda: defaultdict(lambda: 10**10)) for i in range(m): a, b, c = abc[i] a -= 1 @@ -51,7 +51,7 @@ def dijkstra(s, n, w, cost, create_path=False, goal=None): d1 = dijkstra(0, n, m, edges) -edges = defaultdict(lambda: defaultdict(lambda: 10 ** 10)) +edges = defaultdict(lambda: defaultdict(lambda: 10**10)) for i in range(m): a, b, c = abc[i] a -= 1 diff --git a/atcoder/abc/abc001-100/abc037/d.py b/atcoder/abc/abc001-100/abc037/d.py index da32b263..4fb45a58 100644 --- a/atcoder/abc/abc001-100/abc037/d.py +++ b/atcoder/abc/abc001-100/abc037/d.py @@ -2,7 +2,7 @@ input = sys.stdin.readline sys.setrecursionlimit(10000000) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 h, w = map(int, input().split()) a = [[int(i) for i in input().rstrip().split()] for i in range(h)] dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]] diff --git a/atcoder/abc/abc001-100/abc040/b.py b/atcoder/abc/abc001-100/abc040/b.py index c4c79eb5..a6775fdf 100644 --- a/atcoder/abc/abc001-100/abc040/b.py +++ b/atcoder/abc/abc001-100/abc040/b.py @@ -1,6 +1,6 @@ n = int(input()) -score = 10 ** 9 +score = 10**9 for i in range(1000): for j in range(1000): diff --git a/atcoder/abc/abc001-100/abc040/c.py b/atcoder/abc/abc001-100/abc040/c.py index a2b67c1a..bb586d2f 100644 --- a/atcoder/abc/abc001-100/abc040/c.py +++ b/atcoder/abc/abc001-100/abc040/c.py @@ -1,6 +1,6 @@ n = int(input()) a = list(map(int, input().split())) -a.insert(0, 10 ** 9) +a.insert(0, 10**9) dp = [0] * (n + 1) dp[2] = abs(a[1] - a[2]) for i in range(3, n + 1): diff --git a/atcoder/abc/abc001-100/abc043/c.py b/atcoder/abc/abc001-100/abc043/c.py index 8de0357b..b7ba2e60 100644 --- a/atcoder/abc/abc001-100/abc043/c.py +++ b/atcoder/abc/abc001-100/abc043/c.py @@ -3,7 +3,7 @@ n = int(input()) a = list(map(int, input().split())) -ans = 10 ** 10 +ans = 10**10 m1 = a[int(n / 2)] m2 = int(sum(a) / n) diff --git a/atcoder/abc/abc001-100/abc047/d.py b/atcoder/abc/abc001-100/abc047/d.py index 63840ee1..1780ae22 100644 --- a/atcoder/abc/abc001-100/abc047/d.py +++ b/atcoder/abc/abc001-100/abc047/d.py @@ -4,7 +4,7 @@ a = list(map(int, input().split())) ans = defaultdict(int) -min_v = [10 ** 9 + 1, 1] +min_v = [10**9 + 1, 1] for v in a: ans[v - min_v[0]] += min_v[1] diff --git a/atcoder/abc/abc001-100/abc050/c.py b/atcoder/abc/abc001-100/abc050/c.py index 52af0864..64f74ce3 100644 --- a/atcoder/abc/abc001-100/abc050/c.py +++ b/atcoder/abc/abc001-100/abc050/c.py @@ -1,6 +1,6 @@ import collections -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) c = collections.Counter(a) diff --git a/atcoder/abc/abc001-100/abc051/d.py b/atcoder/abc/abc001-100/abc051/d.py index 0353df82..bf6dfe1a 100644 --- a/atcoder/abc/abc001-100/abc051/d.py +++ b/atcoder/abc/abc001-100/abc051/d.py @@ -3,7 +3,7 @@ from heapq import heapify, heappop, heappush input = sys.stdin.readline -INF = 10 ** 12 +INF = 10**12 edges = defaultdict(lambda: defaultdict(lambda: INF)) n, m = map(int, input().split()) for i in range(m): diff --git a/atcoder/abc/abc001-100/abc052/c.py b/atcoder/abc/abc001-100/abc052/c.py index 1a5e72e5..962e60ee 100644 --- a/atcoder/abc/abc001-100/abc052/c.py +++ b/atcoder/abc/abc001-100/abc052/c.py @@ -24,7 +24,7 @@ def trial_division(n): n = int(input()) kai = [0 for _ in range(n + 1)] -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 l = [] for i in range(1, n + 1): diff --git a/atcoder/abc/abc001-100/abc057/c.py b/atcoder/abc/abc001-100/abc057/c.py index 68819878..3414d3b7 100644 --- a/atcoder/abc/abc001-100/abc057/c.py +++ b/atcoder/abc/abc001-100/abc057/c.py @@ -7,7 +7,7 @@ def f(a, b): def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: @@ -19,7 +19,7 @@ def make_divisors(n): l = make_divisors(n) -ans = 10 ** 10 +ans = 10**10 for v in l: ans = min(ans, f(v, n // v)) print(ans) diff --git a/atcoder/abc/abc001-100/abc058/c.py b/atcoder/abc/abc001-100/abc058/c.py index 07e302c8..c4a70a7c 100644 --- a/atcoder/abc/abc001-100/abc058/c.py +++ b/atcoder/abc/abc001-100/abc058/c.py @@ -10,7 +10,7 @@ for i in range(1, n): alphabet = alphabet & set(s[i]) -count_min = defaultdict(lambda: 10 ** 9) +count_min = defaultdict(lambda: 10**9) for a in sorted(alphabet): for i in range(n): count_min[a] = min(count_min[a], s[i].count(a)) diff --git a/atcoder/abc/abc001-100/abc059/c.py b/atcoder/abc/abc001-100/abc059/c.py index e0dbd22d..d180ffce 100644 --- a/atcoder/abc/abc001-100/abc059/c.py +++ b/atcoder/abc/abc001-100/abc059/c.py @@ -1,7 +1,7 @@ n = int(input()) a = list(map(int, input().split())) -ans = 10 ** 10 +ans = 10**10 # 1 -1 1 -1... cost1 = 0 diff --git a/atcoder/abc/abc001-100/abc063/d.py b/atcoder/abc/abc001-100/abc063/d.py index 1ca5cc90..8be8189e 100644 --- a/atcoder/abc/abc001-100/abc063/d.py +++ b/atcoder/abc/abc001-100/abc063/d.py @@ -17,7 +17,7 @@ def can_beet(t): l = -1 -r = 10 ** 9 + 1 +r = 10**9 + 1 while r - l > 1: mid = (r + l) // 2 if can_beet(mid): diff --git a/atcoder/abc/abc001-100/abc071/d.py b/atcoder/abc/abc001-100/abc071/d.py index c77c3622..d993f304 100644 --- a/atcoder/abc/abc001-100/abc071/d.py +++ b/atcoder/abc/abc001-100/abc071/d.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n = int(input()) s1 = input() diff --git a/atcoder/abc/abc001-100/abc073/d.py b/atcoder/abc/abc001-100/abc073/d.py index e0d66b39..6f572ea2 100644 --- a/atcoder/abc/abc001-100/abc073/d.py +++ b/atcoder/abc/abc001-100/abc073/d.py @@ -6,7 +6,7 @@ n, m, R = map(int, input().split()) r = list(map(int, input().split())) -INF = 10 ** 10 +INF = 10**10 dist = [[INF for _ in range(n)] for _ in range(n)] for i in range(m): a, b, c = map(int, input().split()) diff --git a/atcoder/abc/abc001-100/abc074/d.py b/atcoder/abc/abc001-100/abc074/d.py index 97bc5088..3337a5b8 100644 --- a/atcoder/abc/abc001-100/abc074/d.py +++ b/atcoder/abc/abc001-100/abc074/d.py @@ -3,7 +3,7 @@ input = sys.stdin.buffer.readline n = int(input()) -INF = 10 ** 12 +INF = 10**12 d = [[INF for _ in range(n)] for _ in range(n)] a = [list(map(int, input().split())) for i in range(n)] for i in range(n): diff --git a/atcoder/abc/abc001-100/abc075/abc075_d.py b/atcoder/abc/abc001-100/abc075/abc075_d.py index c8aecaa4..a122f984 100644 --- a/atcoder/abc/abc001-100/abc075/abc075_d.py +++ b/atcoder/abc/abc001-100/abc075/abc075_d.py @@ -1,7 +1,7 @@ n, k = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(n)] -MAX = 10 ** 9 +MAX = 10**9 MIN = -1 * MAX @@ -27,7 +27,7 @@ def check(x_r, x_l, y_t, y_b): return True, area -INF = 10 ** 20 +INF = 10**20 ans = INF for a in range(n): for b in range(n): diff --git a/atcoder/abc/abc001-100/abc076/abc076_b.py b/atcoder/abc/abc001-100/abc076/abc076_b.py index 93e8f61a..94ec4c4c 100644 --- a/atcoder/abc/abc001-100/abc076/abc076_b.py +++ b/atcoder/abc/abc001-100/abc076/abc076_b.py @@ -1,11 +1,11 @@ n = int(input()) k = int(input()) -min_ans = 10 ** 10 -for i in range(2 ** n): +min_ans = 10**10 +for i in range(2**n): ans = 1 for j in range(n): - if i & 2 ** j: + if i & 2**j: ans += k else: ans *= 2 diff --git a/atcoder/abc/abc001-100/abc077/abc077_b.py b/atcoder/abc/abc001-100/abc077/abc077_b.py index 4f3af45b..b6d3de00 100644 --- a/atcoder/abc/abc001-100/abc077/abc077_b.py +++ b/atcoder/abc/abc001-100/abc077/abc077_b.py @@ -3,8 +3,8 @@ idx = 0 while True: idx += 1 - if idx ** 2 > n: + if idx**2 > n: idx -= 1 break -print(idx ** 2) +print(idx**2) diff --git a/atcoder/abc/abc001-100/abc078/abc078_c.py b/atcoder/abc/abc001-100/abc078/abc078_c.py index 6d246fed..74ed6a0e 100644 --- a/atcoder/abc/abc001-100/abc078/abc078_c.py +++ b/atcoder/abc/abc001-100/abc078/abc078_c.py @@ -1,4 +1,4 @@ n, m = map(int, input().split()) -ans = (m * 1900 + (n - m) * 100) * 2 ** m +ans = (m * 1900 + (n - m) * 100) * 2**m print(ans) diff --git a/atcoder/abc/abc001-100/abc080/c.py b/atcoder/abc/abc001-100/abc080/c.py index bbe0af27..7b504d28 100644 --- a/atcoder/abc/abc001-100/abc080/c.py +++ b/atcoder/abc/abc001-100/abc080/c.py @@ -2,10 +2,10 @@ def bit_full_search(max_bit: int) -> Iterator[List[int]]: - for i in range(2 ** max_bit): + for i in range(2**max_bit): bit_list = [0 for _ in range(max_bit)] for j in range(10): - if i & 2 ** j > 0: + if i & 2**j > 0: bit_list[j] = 1 yield bit_list @@ -21,7 +21,7 @@ def bit_full_search(max_bit: int) -> Iterator[List[int]]: p.append(list(map(int, input().split()))) # bit全探索 -ans = -(10 ** 10) +ans = -(10**10) for l in bit_full_search(10): if sum(l) == 0: diff --git a/atcoder/abc/abc001-100/abc081/d.py b/atcoder/abc/abc001-100/abc081/d.py index 7c034a7f..79f6f25d 100644 --- a/atcoder/abc/abc001-100/abc081/d.py +++ b/atcoder/abc/abc001-100/abc081/d.py @@ -17,7 +17,7 @@ def solve_minus(out): max_a = 0 max_i = 0 -min_a = 10 ** 7 +min_a = 10**7 min_i = 0 for i in range(n): if a[i] > max_a: diff --git a/atcoder/abc/abc001-100/abc084/d.py b/atcoder/abc/abc001-100/abc084/d.py index a60cb09f..d23f345b 100644 --- a/atcoder/abc/abc001-100/abc084/d.py +++ b/atcoder/abc/abc001-100/abc084/d.py @@ -17,13 +17,13 @@ def isPrime(n): return True -isprime = [False] * (10 ** 5 + 1) -for i in range(1, 10 ** 5 + 1): +isprime = [False] * (10**5 + 1) +for i in range(1, 10**5 + 1): if isPrime(i): isprime[i] = True -ans = [0] * (10 ** 5 + 1) +ans = [0] * (10**5 + 1) v = 0 -for i in range(1, 10 ** 5 + 1): +for i in range(1, 10**5 + 1): if i % 2 == 1 and isprime[i] and isprime[(i + 1) // 2]: v += 1 ans[i] = v diff --git a/atcoder/abc/abc001-100/abc091/c.py b/atcoder/abc/abc001-100/abc091/c.py index e237979e..f77b70f5 100644 --- a/atcoder/abc/abc001-100/abc091/c.py +++ b/atcoder/abc/abc001-100/abc091/c.py @@ -50,7 +50,7 @@ def dfs(self, v, t, f): def flow(self, s, t): flow = 0 - INF = 10 ** 9 + 7 + INF = 10**9 + 7 G = self.G while self.bfs(s, t): (*self.it,) = map(iter, self.G) diff --git a/atcoder/abc/abc001-100/abc099/d.py b/atcoder/abc/abc001-100/abc099/d.py index fc7b41b3..99472a2f 100644 --- a/atcoder/abc/abc001-100/abc099/d.py +++ b/atcoder/abc/abc001-100/abc099/d.py @@ -18,7 +18,7 @@ def calc_cost(dic, color): return cost -INF = 10 ** 9 +INF = 10**9 cost = INF for colors in permutations(range(C), 3): tmp_cost = 0 diff --git a/atcoder/abc/abc101-200/ABC144/d.py b/atcoder/abc/abc101-200/ABC144/d.py index 37d15bc8..d12d5c36 100644 --- a/atcoder/abc/abc101-200/ABC144/d.py +++ b/atcoder/abc/abc101-200/ABC144/d.py @@ -5,5 +5,5 @@ if a * a * b / 2 >= x: ans = 90 - degrees(atan((2 * x) / (a * b * b))) else: - ans = degrees(atan((2 * ((a ** 2 * b) - x)) / (a ** 3))) + ans = degrees(atan((2 * ((a**2 * b) - x)) / (a**3))) print(ans) diff --git a/atcoder/abc/abc101-200/ABC146/c.py b/atcoder/abc/abc101-200/ABC146/c.py index 8867ed14..f01f32ae 100644 --- a/atcoder/abc/abc101-200/ABC146/c.py +++ b/atcoder/abc/abc101-200/ABC146/c.py @@ -2,7 +2,7 @@ a, b, x = map(int, input().split()) -cur = 10 ** 9 +cur = 10**9 dis = cur // 2 l = [] while True: @@ -21,4 +21,4 @@ cal = (a * i) + (b * len(str(i))) if cal <= x: ans = max(ans, i) -print(min(ans, 10 ** 9)) +print(min(ans, 10**9)) diff --git a/atcoder/abc/abc101-200/ABC149/e.py b/atcoder/abc/abc101-200/ABC149/e.py index 3e1c78e9..d16f59b5 100644 --- a/atcoder/abc/abc101-200/ABC149/e.py +++ b/atcoder/abc/abc101-200/ABC149/e.py @@ -1,10 +1,11 @@ import bisect + n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() left = 0 -right = 10 ** 12 +right = 10**12 while right - left > 1: mid = (left + right) // 2 cnt = 0 @@ -16,4 +17,4 @@ else: left = mid print(left, right) -# wakaran \ No newline at end of file +# wakaran diff --git a/atcoder/abc/abc101-200/ABC150/abc150_e.py b/atcoder/abc/abc101-200/ABC150/abc150_e.py index a36e536f..7994b0e1 100644 --- a/atcoder/abc/abc101-200/ABC150/abc150_e.py +++ b/atcoder/abc/abc101-200/ABC150/abc150_e.py @@ -9,7 +9,7 @@ def perm(n, r): return factorial(n) // factorial(n - r) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n = int(input()) c = list(map(int, input().split())) diff --git a/atcoder/abc/abc101-200/ABC150/d.py b/atcoder/abc/abc101-200/ABC150/d.py index 9982f1b5..c8f39237 100644 --- a/atcoder/abc/abc101-200/ABC150/d.py +++ b/atcoder/abc/abc101-200/ABC150/d.py @@ -1,4 +1,4 @@ n = int(input()) c = sorted(list(map(int, input().split())), reverse=True) -p = 10 ** 9 + 7 +p = 10**9 + 7 print(sum([(i + 2) * c[i] for i in range(n)]) * pow(4, n - 1, p) % p) diff --git a/atcoder/abc/abc101-200/ABC154/f.py b/atcoder/abc/abc101-200/ABC154/f.py index 2b452187..d4197045 100644 --- a/atcoder/abc/abc101-200/ABC154/f.py +++ b/atcoder/abc/abc101-200/ABC154/f.py @@ -1,13 +1,13 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 r1, c1, r2, c2 = map(int, input().split()) -n = (2 * 10 ** 6) + 2 +n = (2 * 10**6) + 2 from math import factorial class Facts: # 階乗のメモ化 # 組み合わせ数、順列数の計算を高速に行う - def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -52,7 +52,7 @@ def power_func(self, a, b): class FLT: # フェルマーの小定理 # a^(-1) = a^(m-2) mod p - def __init__(self, mod=10 ** 9 + 7): + def __init__(self, mod=10**9 + 7): self.mod = mod def rep_sqr(self, base, k): diff --git a/atcoder/abc/abc101-200/abc112/d.py b/atcoder/abc/abc101-200/abc112/d.py index 74ce712b..88cbcbe3 100644 --- a/atcoder/abc/abc101-200/abc112/d.py +++ b/atcoder/abc/abc101-200/abc112/d.py @@ -3,7 +3,7 @@ def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: diff --git a/atcoder/abc/abc101-200/abc123/b.py b/atcoder/abc/abc101-200/abc123/b.py index 800bc017..987eb268 100644 --- a/atcoder/abc/abc101-200/abc123/b.py +++ b/atcoder/abc/abc101-200/abc123/b.py @@ -4,7 +4,7 @@ t = [] for i in range(5): t.append(int(input())) -ans = 10 ** 9 +ans = 10**9 for values in list(itertools.permutations(t)): tmp = 0 diff --git a/atcoder/abc/abc101-200/abc127/C.py b/atcoder/abc/abc101-200/abc127/C.py index f4abc6dd..00e05782 100644 --- a/atcoder/abc/abc101-200/abc127/C.py +++ b/atcoder/abc/abc101-200/abc127/C.py @@ -1,6 +1,6 @@ n, m = map(int, input().split()) max_l = 0 -min_r = 10 ** 5 +min_r = 10**5 for i in range(m): l, r = map(int, input().split()) max_l = max(max_l, l) diff --git a/atcoder/abc/abc101-200/abc127/E.py b/atcoder/abc/abc101-200/abc127/E.py index d400285f..889d8150 100644 --- a/atcoder/abc/abc101-200/abc127/E.py +++ b/atcoder/abc/abc101-200/abc127/E.py @@ -1,2 +1,2 @@ n, m, k = map(int, input().split()) -mod = 10 ** 9 + 7 +mod = 10**9 + 7 diff --git a/atcoder/abc/abc101-200/abc128/C.py b/atcoder/abc/abc101-200/abc128/C.py index a2c97efe..7237f1f0 100644 --- a/atcoder/abc/abc101-200/abc128/C.py +++ b/atcoder/abc/abc101-200/abc128/C.py @@ -4,7 +4,7 @@ k.append(list(map(int, input().split()))) p = list(map(int, input().split())) count = 0 -for i in range(2 ** n): +for i in range(2**n): flag = True for q_idx, query in enumerate(k): count_p = 0 diff --git a/atcoder/abc/abc101-200/abc129/ABC129B.py b/atcoder/abc/abc101-200/abc129/ABC129B.py index 35ff10cd..1ad9e17e 100644 --- a/atcoder/abc/abc101-200/abc129/ABC129B.py +++ b/atcoder/abc/abc101-200/abc129/ABC129B.py @@ -2,7 +2,7 @@ w = [int(i) for i in input().split()] -min_abs = 10 ** 9 +min_abs = 10**9 for i in range(1, len(w) + 1): s1 = sum(w[:i]) s2 = sum(w[i:]) diff --git a/atcoder/abc/abc101-200/abc129/ABC129C.py b/atcoder/abc/abc101-200/abc129/ABC129C.py index 7d478ba0..0ab12e31 100644 --- a/atcoder/abc/abc101-200/abc129/ABC129C.py +++ b/atcoder/abc/abc101-200/abc129/ABC129C.py @@ -1,4 +1,4 @@ -mod = 10 ** 9 + 7 +mod = 10**9 + 7 n, m = map(int, input().split()) a = [1] * (n + 1) diff --git a/atcoder/abc/abc101-200/abc129/e.py b/atcoder/abc/abc101-200/abc129/e.py index bcdbbdf4..9a952e9c 100644 --- a/atcoder/abc/abc101-200/abc129/e.py +++ b/atcoder/abc/abc101-200/abc129/e.py @@ -2,7 +2,7 @@ # 二進数, 2進数 l = list(map(int, list(input()))) n = len(l) + 1 -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 dp1 = [0 for _ in range(n)] dp2 = [0 for _ in range(n)] dp1[0] = 1 diff --git a/atcoder/abc/abc101-200/abc132/C.py b/atcoder/abc/abc101-200/abc132/C.py index e4ad4d10..4e40f69a 100644 --- a/atcoder/abc/abc101-200/abc132/C.py +++ b/atcoder/abc/abc101-200/abc132/C.py @@ -5,7 +5,7 @@ d.sort() div = n // 2 count = 0 -for i in range(10 ** 5 + 1): +for i in range(10**5 + 1): insert_index = bisect.bisect_right(d, i) if insert_index == div: count += 1 diff --git a/atcoder/abc/abc101-200/abc132/D.py b/atcoder/abc/abc101-200/abc132/D.py index 88adfe0a..458fc8cc 100644 --- a/atcoder/abc/abc101-200/abc132/D.py +++ b/atcoder/abc/abc101-200/abc132/D.py @@ -1,6 +1,6 @@ import math -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n, k = map(int, input().split()) diff --git a/atcoder/abc/abc101-200/abc132/test.py b/atcoder/abc/abc101-200/abc132/test.py index 167387f9..d93240ca 100644 --- a/atcoder/abc/abc101-200/abc132/test.py +++ b/atcoder/abc/abc101-200/abc132/test.py @@ -1,6 +1,6 @@ import math -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 def permutations_count(n, r): diff --git a/atcoder/abc/abc101-200/abc133/abc133_e.py b/atcoder/abc/abc101-200/abc133/abc133_e.py index 0cb1b6b5..be7471e4 100644 --- a/atcoder/abc/abc101-200/abc133/abc133_e.py +++ b/atcoder/abc/abc101-200/abc133/abc133_e.py @@ -2,11 +2,11 @@ sys.setrecursionlimit(1000000) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: - def __init__(self, max_num: int = 10 ** 5, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int = 10**5, p: int = 10**9 + 7) -> None: self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/atcoder/abc/abc101-200/abc134/a.py b/atcoder/abc/abc101-200/abc134/a.py index 5d28d320..95b949ea 100644 --- a/atcoder/abc/abc101-200/abc134/a.py +++ b/atcoder/abc/abc101-200/abc134/a.py @@ -1,3 +1,3 @@ r = int(input()) -print(3 * r ** 2) +print(3 * r**2) diff --git a/atcoder/abc/abc101-200/abc135/d.py b/atcoder/abc/abc101-200/abc135/d.py index 7cabf9ae..3d756a10 100644 --- a/atcoder/abc/abc101-200/abc135/d.py +++ b/atcoder/abc/abc101-200/abc135/d.py @@ -2,7 +2,7 @@ sys.setrecursionlimit(1000000) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 s = str(input()) l = len(s) l_ = ["05", "18", "31", "44", "57", "70", "83", "96"] diff --git a/atcoder/abc/abc101-200/abc135/d_dp.py b/atcoder/abc/abc101-200/abc135/d_dp.py index fc09bb51..2a09b702 100644 --- a/atcoder/abc/abc101-200/abc135/d_dp.py +++ b/atcoder/abc/abc101-200/abc135/d_dp.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 s = str(input()) l = len(s) dp = [[0 for _ in range(2)] for _ in range(l + 1)] diff --git a/atcoder/abc/abc101-200/abc136/e.py b/atcoder/abc/abc101-200/abc136/e.py index 3924fd51..a98b78e4 100644 --- a/atcoder/abc/abc101-200/abc136/e.py +++ b/atcoder/abc/abc101-200/abc136/e.py @@ -3,7 +3,7 @@ def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: diff --git a/atcoder/abc/abc101-200/abc138/f.py b/atcoder/abc/abc101-200/abc138/f.py index 4efe3c49..550ad1f5 100644 --- a/atcoder/abc/abc101-200/abc138/f.py +++ b/atcoder/abc/abc101-200/abc138/f.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 l, r = map(int, input().split()) # bit DP diff --git a/atcoder/abc/abc101-200/abc147/c.py b/atcoder/abc/abc101-200/abc147/c.py index fbac92e6..35e84aed 100644 --- a/atcoder/abc/abc101-200/abc147/c.py +++ b/atcoder/abc/abc101-200/abc147/c.py @@ -11,13 +11,13 @@ # ビット全探索 bit = 0 ans = 0 -for X in range(2 ** n): +for X in range(2**n): # 1010など flag = False count = 0 for num in range(n): f = True - if X & (2 ** num) >= 1: + if X & (2**num) >= 1: for x, y in xy[num]: t = 1 if X & 2 ** (x - 1) >= 1 else 0 if t != y: diff --git a/atcoder/abc/abc101-200/abc147/d.py b/atcoder/abc/abc101-200/abc147/d.py index a24cace2..ed16d178 100644 --- a/atcoder/abc/abc101-200/abc147/d.py +++ b/atcoder/abc/abc101-200/abc147/d.py @@ -5,12 +5,12 @@ bits = [0 for _ in range(60)] for i in range(n): for b in range(60): - if a[i] & 2 ** b > 0: + if a[i] & 2**b > 0: bits[b] += 1 ans = 0 for i, b in enumerate(bits): if b > 0: - ans += (2 ** i) * (b * (n - b)) + ans += (2**i) * (b * (n - b)) ans %= MOD print(ans) diff --git a/atcoder/abc/abc101-200/abc147/e.py b/atcoder/abc/abc101-200/abc147/e.py index 84e50109..5481851e 100644 --- a/atcoder/abc/abc101-200/abc147/e.py +++ b/atcoder/abc/abc101-200/abc147/e.py @@ -68,7 +68,7 @@ dp[h - 1][w - 1][i + v] = True dp[h - 1][w - 1][i - v] = True -ans = 10 ** 9 +ans = 10**9 for i in range(25601): if dp[h - 1][w - 1][i]: ans = min(ans, abs(12800 - i)) diff --git a/atcoder/abc/abc101-200/abc148/e.py b/atcoder/abc/abc101-200/abc148/e.py index dc1ff0b3..caeb6fae 100644 --- a/atcoder/abc/abc101-200/abc148/e.py +++ b/atcoder/abc/abc101-200/abc148/e.py @@ -6,9 +6,9 @@ def f(num): count = 0 i = 1 while True: - if ((5 ** i) * (2)) > num: + if ((5**i) * (2)) > num: break - count += num // ((5 ** i) * (2)) + count += num // ((5**i) * (2)) i += 1 return count diff --git a/atcoder/abc/abc101-200/abc151/e.py b/atcoder/abc/abc101-200/abc151/e.py index 5dcf386b..f53a1d60 100644 --- a/atcoder/abc/abc101-200/abc151/e.py +++ b/atcoder/abc/abc101-200/abc151/e.py @@ -2,7 +2,7 @@ class Facts: - def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -11,7 +11,7 @@ def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): self.fact[i] %= self.p def comb(self, n, k): - """ nCk mod p を求める """ + """nCk mod p を求める""" """ 計算量 O(log(p)) """ """ n! / (n-k)! / k! mod p """ """ フェルマーの小定理 a^(-1) ≡ a^(p-2) """ @@ -28,7 +28,7 @@ def comb(self, n, k): ) % self.p def perm(self, n, k): - """ nPk mod p を求める """ + """nPk mod p を求める""" """ 計算量 O(b - a)? """ """ n! / (n-k)! mod p """ """ n! * (n-k)!^(p-2) mod p """ @@ -41,7 +41,7 @@ def perm(self, n, k): return (a * self.power_func(b, self.p - 2)) % self.p def power_func(self, a, b): - """ a^b mod p を繰り返し二乗法で求める """ + """a^b mod p を繰り返し二乗法で求める""" """ 計算量 O(log(b)) """ if b == 0: return 1 @@ -52,7 +52,7 @@ def power_func(self, a, b): return (a * self.power_func(a, b - 1)) % self.p -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 fact = Facts() n, k = map(int, input().split()) diff --git a/atcoder/abc/abc101-200/abc151/f.py b/atcoder/abc/abc101-200/abc151/f.py index be687017..25a43ed6 100644 --- a/atcoder/abc/abc101-200/abc151/f.py +++ b/atcoder/abc/abc101-200/abc151/f.py @@ -51,14 +51,14 @@ def circumcenter(x1, y1, x2, y2, x3, y3): return x, y, r -ans = 10 ** 15 +ans = 10**15 if n > 2: for a, b, c in itertools.combinations(range(n), 3): cx, cy, cr = circumcenter( xy[a][0], xy[a][1], xy[b][0], xy[b][1], xy[c][0], xy[c][1] ) # check - rr = cr ** 2 + rr = cr**2 flag = True for i in range(n): x, y = xy[i] diff --git a/atcoder/abc/abc101-200/abc152/e.py b/atcoder/abc/abc101-200/abc152/e.py index 6c0bc3f0..ad6eb8b6 100644 --- a/atcoder/abc/abc101-200/abc152/e.py +++ b/atcoder/abc/abc101-200/abc152/e.py @@ -71,7 +71,7 @@ def flt(a, mod): sieve() # python > pypy -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) diff --git a/atcoder/abc/abc101-200/abc152/e_refact.py b/atcoder/abc/abc101-200/abc152/e_refact.py index 55bb96d3..027f607f 100644 --- a/atcoder/abc/abc101-200/abc152/e_refact.py +++ b/atcoder/abc/abc101-200/abc152/e_refact.py @@ -8,7 +8,7 @@ class LCM_mod: 因数の積を逐次余りに置き換えて最小公倍数を導出する. """ - def __init__(self, max_num, p=10 ** 9 + 7): + def __init__(self, max_num, p=10**9 + 7): self.max_num = max_num + 1 self.p = p self.prime = [0 for _ in range(self.max_num)] @@ -61,7 +61,7 @@ def lcm_list_mod(self, arr): class FLT: - def __init__(self, mod=10 ** 9 + 7): + def __init__(self, mod=10**9 + 7): self.mod = mod def rep_sqr(self, base, k): @@ -73,13 +73,13 @@ def rep_sqr(self, base, k): return (self.rep_sqr(base, k - 1) * base) % self.mod def inv(self, a): - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) n = int(input()) a = list(map(int, input().split())) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 lcm_mod = LCM_mod(max(a), MOD) lcm_all = lcm_mod.lcm_list_mod(a) diff --git a/atcoder/abc/abc101-200/abc152/make_test.py b/atcoder/abc/abc101-200/abc152/make_test.py index b5ff5645..3e97c916 100644 --- a/atcoder/abc/abc101-200/abc152/make_test.py +++ b/atcoder/abc/abc101-200/abc152/make_test.py @@ -7,10 +7,10 @@ def is_prime(n): return n != 1 -n = 10 ** 4 +n = 10**4 print(n) a = [] -num = 10 ** 6 +num = 10**6 idx = 0 while len(a) < n: diff --git a/atcoder/abc/abc101-200/abc155/d.py b/atcoder/abc/abc101-200/abc155/d.py index ee45b525..6b169b3e 100644 --- a/atcoder/abc/abc101-200/abc155/d.py +++ b/atcoder/abc/abc101-200/abc155/d.py @@ -38,14 +38,14 @@ def cnt(x): bottom = 0 -top = 2 * (10 ** 18) + 2 +top = 2 * (10**18) + 2 while top - bottom > 1: mid = (top + bottom) // 2 - if cnt(mid - 10 ** 18 - 1) < k: + if cnt(mid - 10**18 - 1) < k: bottom = mid else: top = mid -print(int(top - 10 ** 18 - 1)) +print(int(top - 10**18 - 1)) diff --git a/atcoder/abc/abc101-200/abc155/e.py b/atcoder/abc/abc101-200/abc155/e.py index 42f318e3..3c1d09db 100644 --- a/atcoder/abc/abc101-200/abc155/e.py +++ b/atcoder/abc/abc101-200/abc155/e.py @@ -23,7 +23,7 @@ def solve1(n): def solve2(n): - INF = 10 ** 9 + INF = 10**9 n = n[::-1] n += "0" n_len = len(n) diff --git a/atcoder/abc/abc101-200/abc156/b.py b/atcoder/abc/abc101-200/abc156/b.py index a24eba60..2dd6159e 100644 --- a/atcoder/abc/abc101-200/abc156/b.py +++ b/atcoder/abc/abc101-200/abc156/b.py @@ -2,7 +2,7 @@ i = 0 while True: - s = k ** i + s = k**i if n / s >= 1: i += 1 continue diff --git a/atcoder/abc/abc101-200/abc156/c.py b/atcoder/abc/abc101-200/abc156/c.py index 05d0b531..eac3ea45 100644 --- a/atcoder/abc/abc101-200/abc156/c.py +++ b/atcoder/abc/abc101-200/abc156/c.py @@ -2,7 +2,7 @@ x = list(map(int, input().split())) -ans = 10 ** 12 +ans = 10**12 for i in range(1, 101): cost = 0 for j in range(n): diff --git a/atcoder/abc/abc101-200/abc156/d.py b/atcoder/abc/abc101-200/abc156/d.py index 804f4afc..3b0797ba 100644 --- a/atcoder/abc/abc101-200/abc156/d.py +++ b/atcoder/abc/abc101-200/abc156/d.py @@ -1,14 +1,14 @@ n, a, b = map(int, input().split()) -p = 10 ** 9 + 7 +p = 10**9 + 7 -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 from math import factorial class Facts: # 階乗のメモ化 # 組み合わせ数、順列数の計算を高速に行う - def __init__(self, max_num=(2 * 10 ** 5) + 1, p=10 ** 9 + 7): + def __init__(self, max_num=(2 * 10**5) + 1, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -48,7 +48,7 @@ def power_func(self, a, b): class FLT: # フェルマーの小定理 # a^(-1) = a^(m-2) mod p - def __init__(self, mod=10 ** 9 + 7): + def __init__(self, mod=10**9 + 7): self.mod = mod def rep_sqr(self, base, k): diff --git a/atcoder/abc/abc101-200/abc156/e.py b/atcoder/abc/abc101-200/abc156/e.py index 5f45353b..a82e55a7 100644 --- a/atcoder/abc/abc101-200/abc156/e.py +++ b/atcoder/abc/abc101-200/abc156/e.py @@ -1,5 +1,5 @@ n, k = map(int, input().split()) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 from math import factorial @@ -10,7 +10,7 @@ class Facts: 組み合わせ数、順列数の計算を高速に行う """ - def __init__(self, max_num=2 * 10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=2 * 10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -21,7 +21,7 @@ def __init__(self, max_num=2 * 10 ** 5, p=10 ** 9 + 7): self.ifact[i] = self.power_func(self.fact[i], self.p - 2) def comb(self, n, k): - """ nCk mod p を求める """ + """nCk mod p を求める""" if n < 0 or k < 0 or n < k: return 0 if n == 0 or k == 0: @@ -30,7 +30,7 @@ def comb(self, n, k): return (a * self.ifact[k] * self.ifact[n - k]) % self.p def power_func(self, a, b): - """ a^b mod p を繰り返し二乗法で求める """ + """a^b mod p を繰り返し二乗法で求める""" if b == 0: return 1 if b % 2 == 0: diff --git a/atcoder/abc/abc101-200/abc159/c.py b/atcoder/abc/abc101-200/abc159/c.py index 3d4a0a80..9e9b5ee9 100644 --- a/atcoder/abc/abc101-200/abc159/c.py +++ b/atcoder/abc/abc101-200/abc159/c.py @@ -1,3 +1,3 @@ l = int(input()) a = l / 3 -print(a ** 3) +print(a**3) diff --git a/atcoder/abc/abc101-200/abc159/e.py b/atcoder/abc/abc101-200/abc159/e.py index eb11dc5b..6ff0e1d0 100644 --- a/atcoder/abc/abc101-200/abc159/e.py +++ b/atcoder/abc/abc101-200/abc159/e.py @@ -22,12 +22,12 @@ def solve(l): for v in vs: if s[v][i]: if choco[idx] + 1 > k: - return 10 ** 9 + return 10**9 choco[idx] += 1 return ans + len(l) - 1 -ans = 10 ** 9 +ans = 10**9 for i in range(2 ** (h - 1)): div = [] tmp = [] diff --git a/atcoder/abc/abc101-200/abc160/f.py b/atcoder/abc/abc101-200/abc160/f.py index 422b47fe..b2aa7b8f 100644 --- a/atcoder/abc/abc101-200/abc160/f.py +++ b/atcoder/abc/abc101-200/abc160/f.py @@ -2,15 +2,15 @@ import sys input = sys.stdin.readline -sys.setrecursionlimit(10 ** 6) +sys.setrecursionlimit(10**6) from collections import defaultdict, deque from math import factorial -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: - def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/atcoder/abc/abc101-200/abc161/f.py b/atcoder/abc/abc101-200/abc161/f.py index 4b65b07a..f7e8f344 100644 --- a/atcoder/abc/abc101-200/abc161/f.py +++ b/atcoder/abc/abc101-200/abc161/f.py @@ -5,7 +5,7 @@ def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: diff --git a/atcoder/abc/abc101-200/abc162/e.py b/atcoder/abc/abc101-200/abc162/e.py index 8b62f81b..317708dd 100644 --- a/atcoder/abc/abc101-200/abc162/e.py +++ b/atcoder/abc/abc101-200/abc162/e.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 def rep_sqr(base, k): diff --git a/atcoder/abc/abc101-200/abc162/f.py b/atcoder/abc/abc101-200/abc162/f.py index bc1f2952..176b341d 100644 --- a/atcoder/abc/abc101-200/abc162/f.py +++ b/atcoder/abc/abc101-200/abc162/f.py @@ -1,7 +1,7 @@ # dpでいけそう n = int(input()) a = list(map(int, input().split())) -INF = 10 ** 16 +INF = 10**16 ans = -INF diff --git a/atcoder/abc/abc101-200/abc163/d.py b/atcoder/abc/abc101-200/abc163/d.py index 73dd8069..74418f23 100644 --- a/atcoder/abc/abc101-200/abc163/d.py +++ b/atcoder/abc/abc101-200/abc163/d.py @@ -1,6 +1,6 @@ n, k = map(int, input().split()) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 s = [0 for _ in range(n + 2)] v = 0 diff --git a/atcoder/abc/abc101-200/abc163/e.py b/atcoder/abc/abc101-200/abc163/e.py index 0015d270..493be2a7 100644 --- a/atcoder/abc/abc101-200/abc163/e.py +++ b/atcoder/abc/abc101-200/abc163/e.py @@ -57,7 +57,7 @@ def dfs(self, v, t, f): def flow(self, s, t): flow = 0 - INF = 10 ** 9 + 7 + INF = 10**9 + 7 G = self.G while self.bfs(s, t): (*self.it,) = map(iter, self.G) diff --git a/atcoder/abc/abc101-200/abc163/f.py b/atcoder/abc/abc101-200/abc163/f.py index 422b47fe..b2aa7b8f 100644 --- a/atcoder/abc/abc101-200/abc163/f.py +++ b/atcoder/abc/abc101-200/abc163/f.py @@ -2,15 +2,15 @@ import sys input = sys.stdin.readline -sys.setrecursionlimit(10 ** 6) +sys.setrecursionlimit(10**6) from collections import defaultdict, deque from math import factorial -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: - def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/atcoder/abc/abc101-200/abc164/e.py b/atcoder/abc/abc101-200/abc164/e.py index a1b28807..7eadedc0 100644 --- a/atcoder/abc/abc101-200/abc164/e.py +++ b/atcoder/abc/abc101-200/abc164/e.py @@ -4,7 +4,7 @@ input = sys.stdin.readline -INF = 10 ** 19 +INF = 10**19 n, m, s = map(int, input().split()) edges = defaultdict(lambda: defaultdict(lambda: [INF, INF])) cd = [] @@ -34,7 +34,7 @@ def dijakstra(): goals = set({0}) que = [(0, 0, s)] heapify(que) - while 10 ** 6 > len(que) > 0: + while 10**6 > len(que) > 0: if len(goals) >= n: break cost, num, silver = heappop(que) diff --git a/atcoder/abc/abc101-200/abc166/d.py b/atcoder/abc/abc101-200/abc166/d.py index e9bcc42c..aca358f7 100644 --- a/atcoder/abc/abc101-200/abc166/d.py +++ b/atcoder/abc/abc101-200/abc166/d.py @@ -1,7 +1,7 @@ x = int(input()) d = [] for i in range(-1000, 1000): - d.append([i ** 5, i]) + d.append([i**5, i]) for j in range(len(d)): for i in range(len(d)): diff --git a/atcoder/abc/abc101-200/abc167/c.py b/atcoder/abc/abc101-200/abc167/c.py index 7570f12c..5a043846 100644 --- a/atcoder/abc/abc101-200/abc167/c.py +++ b/atcoder/abc/abc101-200/abc167/c.py @@ -1,6 +1,6 @@ n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for i in range(n)] -INF = 10 ** 12 +INF = 10**12 def calc_cost(l): @@ -20,7 +20,7 @@ def calc_cost(l): ans = INF -for i in range(2 ** n): +for i in range(2**n): l = [] for j in range(n): if i >> j & 1: diff --git a/atcoder/abc/abc101-200/abc167/c_product.py b/atcoder/abc/abc101-200/abc167/c_product.py index 89d95e6a..6afe0679 100644 --- a/atcoder/abc/abc101-200/abc167/c_product.py +++ b/atcoder/abc/abc101-200/abc167/c_product.py @@ -2,7 +2,7 @@ n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for i in range(n)] -INF = 10 ** 12 +INF = 10**12 ans = INF l = [0, 1] diff --git a/atcoder/abc/abc101-200/abc167/d.py b/atcoder/abc/abc101-200/abc167/d.py index 90ef5bef..ab5d395f 100644 --- a/atcoder/abc/abc101-200/abc167/d.py +++ b/atcoder/abc/abc101-200/abc167/d.py @@ -7,7 +7,7 @@ # ループがあるか見つけ、ループのサイズを見つける # ループしている場合、残りのkをループで割ったあまりに置き換える -INF = 10 ** 12 +INF = 10**12 cnt = [-1 for _ in range(n)] cur = 0 size = INF diff --git a/atcoder/abc/abc101-200/abc167/e.py b/atcoder/abc/abc101-200/abc167/e.py index 1211d08a..46afb34f 100644 --- a/atcoder/abc/abc101-200/abc167/e.py +++ b/atcoder/abc/abc101-200/abc167/e.py @@ -10,7 +10,7 @@ class Facts: # O(max_num) - def __init__(self, max_num=2 * 10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=2 * 10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) diff --git a/atcoder/abc/abc101-200/abc168/c.py b/atcoder/abc/abc101-200/abc168/c.py index c5e88743..e3b2bd1e 100644 --- a/atcoder/abc/abc101-200/abc168/c.py +++ b/atcoder/abc/abc101-200/abc168/c.py @@ -4,7 +4,7 @@ def yogen(b, c, shi): - return sqrt(b ** 2 + c ** 2 - 2 * b * c * cos(shi)) + return sqrt(b**2 + c**2 - 2 * b * c * cos(shi)) shi1 = radians(m / 60 * 360) diff --git a/atcoder/abc/abc101-200/abc168/e.py b/atcoder/abc/abc101-200/abc168/e.py index 7583dcce..39e28f90 100644 --- a/atcoder/abc/abc101-200/abc168/e.py +++ b/atcoder/abc/abc101-200/abc168/e.py @@ -3,8 +3,8 @@ from math import gcd input = sys.stdin.readline -MOD = 10 ** 9 + 7 -MAX = 2 * (10 ** 5) + 1 +MOD = 10**9 + 7 +MAX = 2 * (10**5) + 1 sqr = [1 for _ in range(MAX)] for i in range(1, MAX): sqr[i] = sqr[i - 1] * 2 @@ -12,7 +12,7 @@ class FLT: - def __init__(self, mod=10 ** 9 + 7): + def __init__(self, mod=10**9 + 7): self.mod = mod def rep_sqr(self, base, k): @@ -25,7 +25,7 @@ def rep_sqr(self, base, k): return ans def inv(self, a): - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) diff --git a/atcoder/abc/abc101-200/abc169/b.py b/atcoder/abc/abc101-200/abc169/b.py index b8bbb46b..0d56b847 100644 --- a/atcoder/abc/abc101-200/abc169/b.py +++ b/atcoder/abc/abc101-200/abc169/b.py @@ -4,7 +4,7 @@ ans = 1 for v in a: ans *= v - if ans > 10 ** 18: + if ans > 10**18: print(-1) exit() print(ans) diff --git a/atcoder/abc/abc101-200/abc172/a.py b/atcoder/abc/abc101-200/abc172/a.py index 03bf211d..38d8fa1e 100644 --- a/atcoder/abc/abc101-200/abc172/a.py +++ b/atcoder/abc/abc101-200/abc172/a.py @@ -1,2 +1,2 @@ a = int(input()) -print(a + a ** 2 + a ** 3) +print(a + a**2 + a**3) diff --git a/atcoder/abc/abc101-200/abc172/e.py b/atcoder/abc/abc101-200/abc172/e.py index d9db0d8c..0b6e32d2 100644 --- a/atcoder/abc/abc101-200/abc172/e.py +++ b/atcoder/abc/abc101-200/abc172/e.py @@ -1,9 +1,9 @@ n, m = map(int, input().split()) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 class Facts: - def __init__(self, max_num=10 ** 5, p=10 ** 9 + 7): + def __init__(self, max_num=10**5, p=10**9 + 7): self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -44,7 +44,7 @@ def mod_pow(self, a, b): return ans -facts = Facts(max_num=5 * 10 ** 5) +facts = Facts(max_num=5 * 10**5) ans = 0 for k in range(n + 1): diff --git a/atcoder/abc/abc101-200/abc173/e.py b/atcoder/abc/abc101-200/abc173/e.py index d9129ffd..ba6fccc2 100644 --- a/atcoder/abc/abc101-200/abc173/e.py +++ b/atcoder/abc/abc101-200/abc173/e.py @@ -2,7 +2,7 @@ n, k = map(int, input().split()) a = list(map(int, input().split())) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 a.sort() cnt_neg = 0 diff --git a/atcoder/abc/abc101-200/abc174/b.py b/atcoder/abc/abc101-200/abc174/b.py index a847e51e..d83a864a 100644 --- a/atcoder/abc/abc101-200/abc174/b.py +++ b/atcoder/abc/abc101-200/abc174/b.py @@ -5,7 +5,7 @@ def dist(x, y): - return sqrt(x ** 2 + y ** 2) + return sqrt(x**2 + y**2) ans = 0 diff --git a/atcoder/abc/abc101-200/abc175/d.py b/atcoder/abc/abc101-200/abc175/d.py index 597ff643..9b007c54 100644 --- a/atcoder/abc/abc101-200/abc175/d.py +++ b/atcoder/abc/abc101-200/abc175/d.py @@ -7,7 +7,7 @@ # 2の30乗まで調べれば十分 until = 0 for i in range(31): - if 2 ** i <= k: + if 2**i <= k: until = i memo = [[[0, 0] for _ in range(n)] for _ in range(until + 1)] ans = [[i, 0] for i in range(n)] @@ -23,7 +23,7 @@ memo[i + 1][p_i][1] = memo[i][idx][1] + memo[i][p_i][1] for i in reversed(range(until)): - if 2 ** i <= k: + if 2**i <= k: next_ans = [[i, 0] for i in range(n)] for idx in range(len(ans)): p_i = ans[idx][0] @@ -33,6 +33,6 @@ next_ans[idx][0] = next_pi next_ans[idx][1] = next_score ans = next_ans - k -= 2 ** i + k -= 2**i print(memo) print(ans) diff --git a/atcoder/abc/abc101-200/abc178/b.py b/atcoder/abc/abc101-200/abc178/b.py index dd640724..e4b8e3f9 100644 --- a/atcoder/abc/abc101-200/abc178/b.py +++ b/atcoder/abc/abc101-200/abc178/b.py @@ -14,7 +14,7 @@ if c <= 0 and 0 <= d: Y += [0] -ans = -(10 ** 18) +ans = -(10**18) for x in X: for y in Y: ans = max(ans, x * y) diff --git a/atcoder/abc/abc101-200/abc178/c.py b/atcoder/abc/abc101-200/abc178/c.py index e4726302..dcf1c032 100644 --- a/atcoder/abc/abc101-200/abc178/c.py +++ b/atcoder/abc/abc101-200/abc178/c.py @@ -1,5 +1,5 @@ n = int(input()) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 if n == 1: print(0) else: diff --git a/atcoder/abc/abc101-200/abc178/d.py b/atcoder/abc/abc101-200/abc178/d.py index e2688dac..2eafa8c1 100644 --- a/atcoder/abc/abc101-200/abc178/d.py +++ b/atcoder/abc/abc101-200/abc178/d.py @@ -1,5 +1,5 @@ s = int(input()) -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 dp = [0] * 10000 dp[0] = 1 dp[1] = 0 diff --git a/atcoder/abc/abc101-200/abc180/e.py b/atcoder/abc/abc101-200/abc180/e.py index 52599046..9d90c4ba 100644 --- a/atcoder/abc/abc101-200/abc180/e.py +++ b/atcoder/abc/abc101-200/abc180/e.py @@ -8,6 +8,7 @@ def traveling_salesman_dp(positions): INF = float("inf") + def cost(pos1, pos2): x1, y1, z1 = pos1 x2, y2, z2 = pos2 @@ -21,7 +22,10 @@ def cost(pos1, pos2): for j in range(n): for k in range(n): if i & (1 << k) == 0: - dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + cost(positions[j], positions[k])) + dp[i | (1 << k)][k] = min( + dp[i | (1 << k)][k], dp[i][j] + cost(positions[j], positions[k]) + ) return dp[-1][0] -print(traveling_salesman_dp(xyz)) \ No newline at end of file + +print(traveling_salesman_dp(xyz)) diff --git a/atcoder/abc/abc101-200/abc187/d.py b/atcoder/abc/abc101-200/abc187/d.py index aecc9e2e..5081b0f2 100644 --- a/atcoder/abc/abc101-200/abc187/d.py +++ b/atcoder/abc/abc101-200/abc187/d.py @@ -22,4 +22,4 @@ ans += 1 if b_sum > a_sum: break -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc202/d.py b/atcoder/abc/abc201-300/abc202/d.py index a04f23fa..c9cff3e6 100644 --- a/atcoder/abc/abc201-300/abc202/d.py +++ b/atcoder/abc/abc201-300/abc202/d.py @@ -1,2 +1 @@ a, b, k = map(int, input().split()) - diff --git a/atcoder/abc/abc201-300/abc217/f.py b/atcoder/abc/abc201-300/abc217/f.py index 51ef58fa..6c0455c3 100644 --- a/atcoder/abc/abc201-300/abc217/f.py +++ b/atcoder/abc/abc201-300/abc217/f.py @@ -5,4 +5,3 @@ for _ in range(m): a, b = map(int, input().split()) ab.append((a, b)) - diff --git a/atcoder/abc/abc201-300/abc244/a.py b/atcoder/abc/abc201-300/abc244/a.py index 0496adaf..b739c085 100644 --- a/atcoder/abc/abc201-300/abc244/a.py +++ b/atcoder/abc/abc201-300/abc244/a.py @@ -1,4 +1,4 @@ n = int(input()) s = input() -print(s[-1]) \ No newline at end of file +print(s[-1]) diff --git a/atcoder/abc/abc201-300/abc244/b.py b/atcoder/abc/abc201-300/abc244/b.py index c6018d6b..4ac09a7e 100644 --- a/atcoder/abc/abc201-300/abc244/b.py +++ b/atcoder/abc/abc201-300/abc244/b.py @@ -12,5 +12,4 @@ ans[1] += y else: status += 1 -print(*ans, sep=" ") - \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc201-300/abc246/b.py b/atcoder/abc/abc201-300/abc246/b.py index 950deddc..d76cd893 100644 --- a/atcoder/abc/abc201-300/abc246/b.py +++ b/atcoder/abc/abc201-300/abc246/b.py @@ -3,7 +3,7 @@ a, b = map(int, input().split()) if a != 0 and b != 0: - y = sqrt(b ** 2 / (a ** 2 + b ** 2)) + y = sqrt(b**2 / (a**2 + b**2)) x = a * y / b print(f"{x:.10} {y:.10}") elif a == 0: diff --git a/atcoder/abc/abc201-300/abc246/d.py b/atcoder/abc/abc201-300/abc246/d.py index 22e62bb9..c7d3f0dc 100644 --- a/atcoder/abc/abc201-300/abc246/d.py +++ b/atcoder/abc/abc201-300/abc246/d.py @@ -2,12 +2,12 @@ def func(a, b): - return a ** 3 + a ** 2 * b + a * b ** 2 + b ** 3 + return a**3 + a**2 * b + a * b**2 + b**3 -ans = 10 ** 18 -j = 10 ** 6 -for i in range(10 ** 6 + 1): +ans = 10**18 +j = 10**6 +for i in range(10**6 + 1): while func(i, j) >= n and j >= 0: ans = min(func(i, j), ans) j -= 1 diff --git a/atcoder/abc/abc201-300/abc247/a.py b/atcoder/abc/abc201-300/abc247/a.py index 3096980c..2a99f359 100644 --- a/atcoder/abc/abc201-300/abc247/a.py +++ b/atcoder/abc/abc201-300/abc247/a.py @@ -1,3 +1,3 @@ s = list(map(int, list(input()))) s = [0] + s -print(*s[:-1], sep='') \ No newline at end of file +print(*s[:-1], sep="") diff --git a/atcoder/abc/abc201-300/abc247/b.py b/atcoder/abc/abc201-300/abc247/b.py index fbe6ee93..597243a5 100644 --- a/atcoder/abc/abc201-300/abc247/b.py +++ b/atcoder/abc/abc201-300/abc247/b.py @@ -1,4 +1,5 @@ from collections import defaultdict + n = int(input()) counter = defaultdict(int) @@ -20,6 +21,6 @@ ans = False break if ans: - print('Yes') + print("Yes") else: - print('No') + print("No") diff --git a/atcoder/abc/abc201-300/abc247/c.py b/atcoder/abc/abc201-300/abc247/c.py index 955ec53d..97c8a66a 100644 --- a/atcoder/abc/abc201-300/abc247/c.py +++ b/atcoder/abc/abc201-300/abc247/c.py @@ -1,17 +1,21 @@ import sys -import pypyjit from functools import lru_cache -pypyjit.set_param('max_unroll_recursion=-1') + +import pypyjit + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) n = int(input()) + @lru_cache(maxsize=None) def func_s(i): if i == 1: return [1] else: - return func_s(i-1) + [i] + func_s(i-1) + return func_s(i - 1) + [i] + func_s(i - 1) + -print(*func_s(n), sep=" ") \ No newline at end of file +print(*func_s(n), sep=" ") diff --git a/atcoder/abc/abc201-300/abc247/d.py b/atcoder/abc/abc201-300/abc247/d.py index a0212747..1e937885 100644 --- a/atcoder/abc/abc201-300/abc247/d.py +++ b/atcoder/abc/abc201-300/abc247/d.py @@ -35,5 +35,4 @@ q.appendleft([pos, x]) break ans.append(ansi) -print(*ans, sep='\n') - \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc249/c.py b/atcoder/abc/abc201-300/abc249/c.py index ef6b0dec..7cd32687 100644 --- a/atcoder/abc/abc201-300/abc249/c.py +++ b/atcoder/abc/abc201-300/abc249/c.py @@ -2,10 +2,10 @@ def bit_full_search(max_bit: int) -> Iterator[List[int]]: - for i in range(2 ** max_bit): + for i in range(2**max_bit): bit_list = [0 for _ in range(max_bit)] for j in range(max_bit): - if i & (2 ** j) > 0: + if i & (2**j) > 0: bit_list[max_bit - j - 1] = 1 yield bit_list diff --git a/atcoder/abc/abc201-300/abc260/a.py b/atcoder/abc/abc201-300/abc260/a.py index e3d94417..35c8f679 100644 --- a/atcoder/abc/abc201-300/abc260/a.py +++ b/atcoder/abc/abc201-300/abc260/a.py @@ -9,4 +9,4 @@ if v == 1: print(k) exit() -print(-1) \ No newline at end of file +print(-1) diff --git a/atcoder/abc/abc201-300/abc260/c.py b/atcoder/abc/abc201-300/abc260/c.py index c01e8697..09100682 100644 --- a/atcoder/abc/abc201-300/abc260/c.py +++ b/atcoder/abc/abc201-300/abc260/c.py @@ -1,6 +1,8 @@ from collections import defaultdict + n, x, y = map(int, input().split()) + def process(color, level): if level <= 1: if color == "red": @@ -8,6 +10,7 @@ def process(color, level): else: return 1 + stones = defaultdict(lambda: defaultdict(lambda: 0)) stones["red"][n] = 1 level = n @@ -21,4 +24,4 @@ def process(color, level): stones["blue"][level - 1] += stones["blue"][level] * y stones["blue"][level] = 0 level -= 1 -print(stones["blue"][1]) \ No newline at end of file +print(stones["blue"][1]) diff --git a/atcoder/abc/abc201-300/abc261/a.py b/atcoder/abc/abc201-300/abc261/a.py index 57b80220..992cd062 100644 --- a/atcoder/abc/abc201-300/abc261/a.py +++ b/atcoder/abc/abc201-300/abc261/a.py @@ -1,4 +1,4 @@ l1, r1, l2, r2 = map(int, input().split()) s = set(range(l1, r1 + 1)) & set(range(l2, r2 + 1)) -print(max(0, len(s) - 1)) \ No newline at end of file +print(max(0, len(s) - 1)) diff --git a/atcoder/abc/abc201-300/abc261/b.py b/atcoder/abc/abc201-300/abc261/b.py index 4c7903a7..d45553a8 100644 --- a/atcoder/abc/abc201-300/abc261/b.py +++ b/atcoder/abc/abc201-300/abc261/b.py @@ -19,4 +19,4 @@ if ans: print("correct") else: - print("incorrect") \ No newline at end of file + print("incorrect") diff --git a/atcoder/abc/abc201-300/abc261/c.py b/atcoder/abc/abc201-300/abc261/c.py index e8c98c3f..d0635f58 100644 --- a/atcoder/abc/abc201-300/abc261/c.py +++ b/atcoder/abc/abc201-300/abc261/c.py @@ -12,4 +12,4 @@ ans.append(s + f"({counter[s]})") counter[s] += 1 -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc261/d.py b/atcoder/abc/abc201-300/abc261/d.py index 5e778475..074258c4 100644 --- a/atcoder/abc/abc201-300/abc261/d.py +++ b/atcoder/abc/abc201-300/abc261/d.py @@ -19,4 +19,4 @@ for j in range(n + 1): # 裏 dp[i][0] = max(dp[i][0], dp[i - 1][j]) -print(max(dp[n])) \ No newline at end of file +print(max(dp[n])) diff --git a/atcoder/abc/abc201-300/abc261/e.py b/atcoder/abc/abc201-300/abc261/e.py index 70a1f89b..dc218c0b 100644 --- a/atcoder/abc/abc201-300/abc261/e.py +++ b/atcoder/abc/abc201-300/abc261/e.py @@ -1,6 +1,8 @@ import sys + import pypyjit -pypyjit.set_param('max_unroll_recursion=-1') + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -35,4 +37,4 @@ next_x += transformed_bit << j x = next_x ans.append(x) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc262/a.py b/atcoder/abc/abc201-300/abc262/a.py index 49ced30a..69694886 100644 --- a/atcoder/abc/abc201-300/abc262/a.py +++ b/atcoder/abc/abc201-300/abc262/a.py @@ -3,4 +3,4 @@ for i in range(y, 4000): if i % 4 == 2: print(i) - exit() \ No newline at end of file + exit() diff --git a/atcoder/abc/abc201-300/abc262/b.py b/atcoder/abc/abc201-300/abc262/b.py index 543b3786..02a7718f 100644 --- a/atcoder/abc/abc201-300/abc262/b.py +++ b/atcoder/abc/abc201-300/abc262/b.py @@ -14,4 +14,3 @@ if edges[a][b] and edges[b][c] and edges[a][c]: ans += 1 print(ans) - diff --git a/atcoder/abc/abc201-300/abc262/c.py b/atcoder/abc/abc201-300/abc262/c.py index 7fe73862..24b2617a 100644 --- a/atcoder/abc/abc201-300/abc262/c.py +++ b/atcoder/abc/abc201-300/abc262/c.py @@ -12,4 +12,4 @@ if count > 0: ans += count * (count - 1) // 2 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc263/b.py b/atcoder/abc/abc201-300/abc263/b.py index 3781aae4..1a0dfd96 100644 --- a/atcoder/abc/abc201-300/abc263/b.py +++ b/atcoder/abc/abc201-300/abc263/b.py @@ -1,5 +1,6 @@ -from collections import defaultdict import sys +from collections import defaultdict + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -8,13 +9,15 @@ parents = defaultdict(lambda: -1) -for i, pi in enumerate(p, start = 2): +for i, pi in enumerate(p, start=2): parents[i] = pi -def solve(i, depth = 0): + +def solve(i, depth=0): if parents[i] == -1: return depth else: return solve(parents[i]) + 1 + print(solve(n)) diff --git a/atcoder/abc/abc201-300/abc263/c.py b/atcoder/abc/abc201-300/abc263/c.py index 037f7786..57ec7207 100644 --- a/atcoder/abc/abc201-300/abc263/c.py +++ b/atcoder/abc/abc201-300/abc263/c.py @@ -12,4 +12,4 @@ break if flag: ans.append(" ".join(list(map(str, p)))) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc264/a.py b/atcoder/abc/abc201-300/abc264/a.py index ad5593ac..0f415a32 100644 --- a/atcoder/abc/abc201-300/abc264/a.py +++ b/atcoder/abc/abc201-300/abc264/a.py @@ -1,4 +1,4 @@ s = "atcoder" l, r = map(int, input().split()) -print(s[l-1:r]) \ No newline at end of file +print(s[l - 1 : r]) diff --git a/atcoder/abc/abc201-300/abc264/b.py b/atcoder/abc/abc201-300/abc264/b.py index c1671f8b..d28b809c 100644 --- a/atcoder/abc/abc201-300/abc264/b.py +++ b/atcoder/abc/abc201-300/abc264/b.py @@ -3,4 +3,4 @@ if min(min(r, (16 - r)), min(c, (16 - c))) % 2 == 1: print("black") else: - print("white") \ No newline at end of file + print("white") diff --git a/atcoder/abc/abc201-300/abc264/c.py b/atcoder/abc/abc201-300/abc264/c.py index cbe74185..6be0c755 100644 --- a/atcoder/abc/abc201-300/abc264/c.py +++ b/atcoder/abc/abc201-300/abc264/c.py @@ -1,4 +1,5 @@ import itertools + h1, w1 = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(h1)] diff --git a/atcoder/abc/abc201-300/abc265/a.py b/atcoder/abc/abc201-300/abc265/a.py index e24128f6..948baf2f 100644 --- a/atcoder/abc/abc201-300/abc265/a.py +++ b/atcoder/abc/abc201-300/abc265/a.py @@ -1,3 +1,3 @@ x, y, n = map(int, input().split()) -print(min((n % 3) * x + (n // 3) * y, n * x)) \ No newline at end of file +print(min((n % 3) * x + (n // 3) * y, n * x)) diff --git a/atcoder/abc/abc201-300/abc265/b.py b/atcoder/abc/abc201-300/abc265/b.py index 0d67f287..aaa4b571 100644 --- a/atcoder/abc/abc201-300/abc265/b.py +++ b/atcoder/abc/abc201-300/abc265/b.py @@ -1,4 +1,5 @@ from collections import defaultdict + n, m, t = map(int, input().split()) a = list(map(int, input().split())) xy = [] diff --git a/atcoder/abc/abc201-300/abc265/c.py b/atcoder/abc/abc201-300/abc265/c.py index 8dc5d46e..1e75796c 100644 --- a/atcoder/abc/abc201-300/abc265/c.py +++ b/atcoder/abc/abc201-300/abc265/c.py @@ -1,14 +1,17 @@ from collections import defaultdict, deque + h, w = map(int, input().split()) g = [list(input()) for _ in range(h)] visited = [[False] * w for _ in range(h)] + def out(x, y): if x < 0 or x >= w or y < 0 or y >= h: return True else: return False + ans = (-1, -1) queue = deque([(0, 0)]) while queue: @@ -25,13 +28,13 @@ def out(x, y): next_x, next_y = x - 1, y else: next_x, next_y = x + 1, y - + if out(next_x, next_y): ans = (x + 1, y + 1) break queue.append((next_x, next_y)) - + if ans == (-1, -1): print(-1) else: - print(ans[1], ans[0]) \ No newline at end of file + print(ans[1], ans[0]) diff --git a/atcoder/abc/abc201-300/abc266/g.py b/atcoder/abc/abc201-300/abc266/g.py index 26ff8a3c..b583d6d4 100644 --- a/atcoder/abc/abc201-300/abc266/g.py +++ b/atcoder/abc/abc201-300/abc266/g.py @@ -59,7 +59,7 @@ def mod_pow(self, a: int, b: int) -> int: r -= k g -= k -facts = Facts(3 * 10 ** 6, MOD) +facts = Facts(3 * 10**6, MOD) ans = 1 ans *= facts.comb(g + b + k, g) diff --git a/atcoder/abc/abc201-300/abc267/a.py b/atcoder/abc/abc201-300/abc267/a.py index 7f2cc882..497d7b8d 100644 --- a/atcoder/abc/abc201-300/abc267/a.py +++ b/atcoder/abc/abc201-300/abc267/a.py @@ -5,4 +5,4 @@ for i in range(5): if s == days[i]: print(5 - i) - exit() \ No newline at end of file + exit() diff --git a/atcoder/abc/abc201-300/abc267/b.py b/atcoder/abc/abc201-300/abc267/b.py index 8211f790..dffc88de 100644 --- a/atcoder/abc/abc201-300/abc267/b.py +++ b/atcoder/abc/abc201-300/abc267/b.py @@ -34,4 +34,3 @@ print("Yes") exit() print("No") - diff --git a/atcoder/abc/abc201-300/abc267/c.py b/atcoder/abc/abc201-300/abc267/c.py index a35671ef..2b6cd9d3 100644 --- a/atcoder/abc/abc201-300/abc267/c.py +++ b/atcoder/abc/abc201-300/abc267/c.py @@ -7,6 +7,8 @@ def cumsum(a): for v in a: r.append(r[-1] + v) return r + + cumsum_a = cumsum(a) ans = -float("inf") @@ -21,4 +23,4 @@ def cumsum(a): sub = cumsum_a[i + m - 1] - cumsum_a[i - 1] v = v - sub + (a[i + m - 1] * m) ans = max(ans, v) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc268/b.py b/atcoder/abc/abc201-300/abc268/b.py index dad149f1..eb250a6c 100644 --- a/atcoder/abc/abc201-300/abc268/b.py +++ b/atcoder/abc/abc201-300/abc268/b.py @@ -14,4 +14,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc201-300/abc268/c.py b/atcoder/abc/abc201-300/abc268/c.py index 8d0f0ba6..3adf1b77 100644 --- a/atcoder/abc/abc201-300/abc268/c.py +++ b/atcoder/abc/abc201-300/abc268/c.py @@ -1,4 +1,5 @@ from collections import defaultdict + n = int(input()) p = list(map(int, input().split())) @@ -8,7 +9,7 @@ spins = [] for j in range(3): - spins.append((n + (pi - i - 1 + j)) % n) + spins.append((n + (pi - i - 1 + j)) % n) for s in spins: counter[s] += 1 diff --git a/atcoder/abc/abc201-300/abc269/c.py b/atcoder/abc/abc201-300/abc269/c.py index 369898ad..8ba96143 100644 --- a/atcoder/abc/abc201-300/abc269/c.py +++ b/atcoder/abc/abc201-300/abc269/c.py @@ -13,7 +13,7 @@ for v in itertools.combinations(l, i): ans_num = 0 for num in v: - ans_num += 2 ** num + ans_num += 2**num ans.append(ans_num) ans.sort() for v in ans: diff --git a/atcoder/abc/abc201-300/abc273/a.py b/atcoder/abc/abc201-300/abc273/a.py index dfe473b2..f69a2304 100644 --- a/atcoder/abc/abc201-300/abc273/a.py +++ b/atcoder/abc/abc201-300/abc273/a.py @@ -3,4 +3,6 @@ def f(x): return 1 else: return x * f(x - 1) -print(f(int(input()))) \ No newline at end of file + + +print(f(int(input()))) diff --git a/atcoder/abc/abc201-300/abc273/b.py b/atcoder/abc/abc201-300/abc273/b.py index 61d72f91..0959b0f4 100644 --- a/atcoder/abc/abc201-300/abc273/b.py +++ b/atcoder/abc/abc201-300/abc273/b.py @@ -1,4 +1,5 @@ from collections import deque + x, k = map(int, input().split()) ans = [0 for _ in range(16)] @@ -20,5 +21,5 @@ while len(ans) > 1 and ans[0] == 0: ans.popleft() -ans = ''.join(map(str, ans)) -print(ans) \ No newline at end of file +ans = "".join(map(str, ans)) +print(ans) diff --git a/atcoder/abc/abc201-300/abc273/c.py b/atcoder/abc/abc201-300/abc273/c.py index c898f4a8..7f206878 100644 --- a/atcoder/abc/abc201-300/abc273/c.py +++ b/atcoder/abc/abc201-300/abc273/c.py @@ -9,10 +9,10 @@ ans = [] for ai in a: - num = (len(sorted_a) - bisect_right(sorted_a, ai)) + num = len(sorted_a) - bisect_right(sorted_a, ai) counter[num] += 1 for i in range(n): ans.append(counter[i]) -print(*ans, sep='\n') \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc274/a.py b/atcoder/abc/abc201-300/abc274/a.py index 2ce1c1ca..ac802335 100644 --- a/atcoder/abc/abc201-300/abc274/a.py +++ b/atcoder/abc/abc201-300/abc274/a.py @@ -1,5 +1,5 @@ a, b = map(int, input().split()) ans = str(round(b / a, 3)) if len(ans) < 5: - ans += '0' * (5 - len(ans)) -print(ans) \ No newline at end of file + ans += "0" * (5 - len(ans)) +print(ans) diff --git a/atcoder/abc/abc201-300/abc274/b.py b/atcoder/abc/abc201-300/abc274/b.py index 2582aa23..298c05db 100644 --- a/atcoder/abc/abc201-300/abc274/b.py +++ b/atcoder/abc/abc201-300/abc274/b.py @@ -6,4 +6,4 @@ for j in range(w): if c[i][j] == "#": ans[j] += 1 -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc201-300/abc274/c.py b/atcoder/abc/abc201-300/abc274/c.py index 8660337a..1a91e48b 100644 --- a/atcoder/abc/abc201-300/abc274/c.py +++ b/atcoder/abc/abc201-300/abc274/c.py @@ -1,9 +1,7 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) n = int(input()) a = list(map(int, input().split())) - -def dfs(ai): - \ No newline at end of file diff --git a/atcoder/abc/abc201-300/abc275/a.py b/atcoder/abc/abc201-300/abc275/a.py index e26cca78..4606e46f 100644 --- a/atcoder/abc/abc201-300/abc275/a.py +++ b/atcoder/abc/abc201-300/abc275/a.py @@ -6,4 +6,4 @@ for i in range(n): if h[i] == max_h: ans = i + 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc275/b.py b/atcoder/abc/abc201-300/abc275/b.py index 7d5de471..760ed801 100644 --- a/atcoder/abc/abc201-300/abc275/b.py +++ b/atcoder/abc/abc201-300/abc275/b.py @@ -5,4 +5,4 @@ def_value = (a[3] * a[4] * a[5]) % MOD ans = (abc_value - def_value) % MOD -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc275/c.py b/atcoder/abc/abc201-300/abc275/c.py index 732be1a7..3b6bc12d 100644 --- a/atcoder/abc/abc201-300/abc275/c.py +++ b/atcoder/abc/abc201-300/abc275/c.py @@ -1,19 +1,21 @@ import itertools import math + s = [] for _ in range(9): si = list(input()) s.append(si) ans = 0 + def dist(xy1, xy2): return math.sqrt((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2) + def check(xy): xy1 = xy[0] xy2 = xy[1] xy3 = xy[2] - xy4 = if xy1 == xy2 or xy1 == xy3 or xy2 == xy3: return False dist1 = dist(xy1, xy2) @@ -23,12 +25,13 @@ def check(xy): return False return True + ans = 0 for p in itertools.product(range(9), repeat=6): xy = [] for i in range(3): - xy.append([p[i], p[i+3]]) + xy.append([p[i], p[i + 3]]) ans += check(xy) print(ans) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc275/d.py b/atcoder/abc/abc201-300/abc275/d.py index 08994eac..e237fa98 100644 --- a/atcoder/abc/abc201-300/abc275/d.py +++ b/atcoder/abc/abc201-300/abc275/d.py @@ -1,12 +1,15 @@ import sys from functools import lru_cache + import pypyjit -pypyjit.set_param('max_unroll_recursion=-1') + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) n = int(input()) + @lru_cache(maxsize=None) def f(k): if k == 0: @@ -14,4 +17,5 @@ def f(k): else: return f(k // 2) + f(k // 3) -print(f(n)) \ No newline at end of file + +print(f(n)) diff --git a/atcoder/abc/abc201-300/abc276/a.py b/atcoder/abc/abc201-300/abc276/a.py index ed7a2f0b..45e54ce7 100644 --- a/atcoder/abc/abc201-300/abc276/a.py +++ b/atcoder/abc/abc201-300/abc276/a.py @@ -5,4 +5,4 @@ si = s[i] if si == "a": ans = i + 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc276/b.py b/atcoder/abc/abc201-300/abc276/b.py index c337971e..77ed061c 100644 --- a/atcoder/abc/abc201-300/abc276/b.py +++ b/atcoder/abc/abc201-300/abc276/b.py @@ -1,4 +1,5 @@ from collections import defaultdict + n, m = map(int, input().split()) ab = [] path = defaultdict(lambda: []) diff --git a/atcoder/abc/abc201-300/abc276/c.py b/atcoder/abc/abc201-300/abc276/c.py index 10f8a5e6..a6ade7f3 100644 --- a/atcoder/abc/abc201-300/abc276/c.py +++ b/atcoder/abc/abc201-300/abc276/c.py @@ -30,4 +30,4 @@ ans.append(max_num) flag = False ans = reversed(ans) -print(*ans, sep=' ') \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc201-300/abc276/d.py b/atcoder/abc/abc201-300/abc276/d.py index 121d8577..aa9d42e2 100644 --- a/atcoder/abc/abc201-300/abc276/d.py +++ b/atcoder/abc/abc201-300/abc276/d.py @@ -3,6 +3,7 @@ n = int(input()) a = list(map(int, input().split())) + def gcd(a: int, b: int) -> int: # 最大公約数 # (12, 18) -> 6 @@ -10,6 +11,7 @@ def gcd(a: int, b: int) -> int: a, b = b, a % b return a + def prime_factorize(n: int): # 素因数分解 # Return list of prime factorized result @@ -29,6 +31,7 @@ def prime_factorize(n: int): counter[n] += 1 return counter + gcd_value = a[0] for ai in a[1:]: gcd_value = gcd(gcd_value, ai) diff --git a/atcoder/abc/abc201-300/abc277/a.py b/atcoder/abc/abc201-300/abc277/a.py index 0745024d..cc925212 100644 --- a/atcoder/abc/abc201-300/abc277/a.py +++ b/atcoder/abc/abc201-300/abc277/a.py @@ -4,4 +4,4 @@ for i in range(n): if p[i] == x: print(i + 1) - exit() \ No newline at end of file + exit() diff --git a/atcoder/abc/abc201-300/abc277/b.py b/atcoder/abc/abc201-300/abc277/b.py index 9d46d1e8..fbb0ebb4 100644 --- a/atcoder/abc/abc201-300/abc277/b.py +++ b/atcoder/abc/abc201-300/abc277/b.py @@ -11,7 +11,7 @@ flag = False break s_set.add(si) - + if not si[0] in ["H", "D", "C", "S"]: flag = False break @@ -21,4 +21,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc201-300/abc277/c.py b/atcoder/abc/abc201-300/abc277/c.py index e8921a15..b8e2f392 100644 --- a/atcoder/abc/abc201-300/abc277/c.py +++ b/atcoder/abc/abc201-300/abc277/c.py @@ -1,4 +1,5 @@ -from collections import deque, defaultdict +from collections import defaultdict, deque + n = int(input()) ab = [] path = defaultdict(lambda: []) diff --git a/atcoder/abc/abc201-300/abc278/a.py b/atcoder/abc/abc201-300/abc278/a.py index 64664f51..38edd18f 100644 --- a/atcoder/abc/abc201-300/abc278/a.py +++ b/atcoder/abc/abc201-300/abc278/a.py @@ -1,4 +1,5 @@ from collections import deque + n, k = map(int, input().split()) a = list(map(int, input().split())) a = deque(a) diff --git a/atcoder/abc/abc201-300/abc278/b.py b/atcoder/abc/abc201-300/abc278/b.py index 0d9bc2ce..518e4c10 100644 --- a/atcoder/abc/abc201-300/abc278/b.py +++ b/atcoder/abc/abc201-300/abc278/b.py @@ -6,6 +6,7 @@ def valid(a, b, c, d): else: return False + h, m = map(int, input().split()) for i in range(60 * 24): if m == 60: diff --git a/atcoder/abc/abc201-300/abc278/c.py b/atcoder/abc/abc201-300/abc278/c.py index d1880ad6..14598cb2 100644 --- a/atcoder/abc/abc201-300/abc278/c.py +++ b/atcoder/abc/abc201-300/abc278/c.py @@ -1,4 +1,5 @@ from collections import defaultdict + n, q = map(int, input().split()) tab = [] for i in range(q): @@ -19,5 +20,3 @@ else: ans.append("No") print(*ans, sep="\n") - - \ No newline at end of file diff --git a/atcoder/abc/abc201-300/abc278/d.py b/atcoder/abc/abc201-300/abc278/d.py index 4a19a4e8..8e475d9f 100644 --- a/atcoder/abc/abc201-300/abc278/d.py +++ b/atcoder/abc/abc201-300/abc278/d.py @@ -1,4 +1,5 @@ from collections import defaultdict + n = int(input()) a = list(map(int, input().split())) diff --git a/atcoder/abc/abc201-300/abc279/a.py b/atcoder/abc/abc201-300/abc279/a.py index 48cca56f..613fb985 100644 --- a/atcoder/abc/abc201-300/abc279/a.py +++ b/atcoder/abc/abc201-300/abc279/a.py @@ -3,8 +3,8 @@ ans = 0 for si in s: - if si == 'v': + if si == "v": ans += 1 else: ans += 2 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc279/b.py b/atcoder/abc/abc201-300/abc279/b.py index 6b68acad..1587466b 100644 --- a/atcoder/abc/abc201-300/abc279/b.py +++ b/atcoder/abc/abc201-300/abc279/b.py @@ -6,7 +6,7 @@ exit() else: for i in range(len(s) - len(t) + 1): - if s[i:i+len(t)] == t: + if s[i : i + len(t)] == t: print("Yes") exit() -print("No") \ No newline at end of file +print("No") diff --git a/atcoder/abc/abc201-300/abc279/c.py b/atcoder/abc/abc201-300/abc279/c.py index 4177403d..0525ed24 100644 --- a/atcoder/abc/abc201-300/abc279/c.py +++ b/atcoder/abc/abc201-300/abc279/c.py @@ -26,4 +26,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc201-300/abc279/d.py b/atcoder/abc/abc201-300/abc279/d.py index 91d9b43d..79573bad 100644 --- a/atcoder/abc/abc201-300/abc279/d.py +++ b/atcoder/abc/abc201-300/abc279/d.py @@ -3,9 +3,11 @@ a, b = map(int, input().split()) + def f(x): return Decimal((a / math.sqrt(1 + x)) + (b * x)) + # 3分探索する l = 0 r = 10**40 @@ -21,4 +23,4 @@ def f(x): l += 1 else: l = m1 -print(min(f(l), f(r))) \ No newline at end of file +print(min(f(l), f(r))) diff --git a/atcoder/abc/abc201-300/abc279/e.py b/atcoder/abc/abc201-300/abc279/e.py index 0f4b694a..c55fc3b9 100644 --- a/atcoder/abc/abc201-300/abc279/e.py +++ b/atcoder/abc/abc201-300/abc279/e.py @@ -15,4 +15,4 @@ if b[j] == 1: ans.append(j + 1) break -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc280/a.py b/atcoder/abc/abc201-300/abc280/a.py index 13a43b83..effde063 100644 --- a/atcoder/abc/abc201-300/abc280/a.py +++ b/atcoder/abc/abc201-300/abc280/a.py @@ -3,6 +3,6 @@ h, w = map(int, input().split()) for _ in range(h): for si in list(input()): - if si == '#': + if si == "#": ans += 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc280/b.py b/atcoder/abc/abc201-300/abc280/b.py index a7304752..0bfc9d26 100644 --- a/atcoder/abc/abc201-300/abc280/b.py +++ b/atcoder/abc/abc201-300/abc280/b.py @@ -9,4 +9,4 @@ else: ans.append(s[si]) ans = ans[1:] -print(*ans, sep=' ') +print(*ans, sep=" ") diff --git a/atcoder/abc/abc201-300/abc280/c.py b/atcoder/abc/abc201-300/abc280/c.py index d2ee9732..8e2656e7 100644 --- a/atcoder/abc/abc201-300/abc280/c.py +++ b/atcoder/abc/abc201-300/abc280/c.py @@ -3,6 +3,6 @@ t = list(input()) for i in range(1, len(t) + 1): - if s[i-1] != t[i-1]: + if s[i - 1] != t[i - 1]: print(i) - exit() \ No newline at end of file + exit() diff --git a/atcoder/abc/abc201-300/abc280/d.py b/atcoder/abc/abc201-300/abc280/d.py index ade55223..7dc7921a 100644 --- a/atcoder/abc/abc201-300/abc280/d.py +++ b/atcoder/abc/abc201-300/abc280/d.py @@ -1,6 +1,6 @@ import math -from typing import List from collections import defaultdict +from typing import List def prime_factorize(n: int) -> List[int]: @@ -22,6 +22,7 @@ def prime_factorize(n: int) -> List[int]: a.append(n) return sorted(a) + k = int(input()) k_factors = defaultdict(lambda: 0) @@ -42,4 +43,4 @@ def prime_factorize(n: int) -> List[int]: break i += 1 ans = max(ans, factor * i) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc281/a.py b/atcoder/abc/abc201-300/abc281/a.py index de23a78a..9ca99a17 100644 --- a/atcoder/abc/abc201-300/abc281/a.py +++ b/atcoder/abc/abc201-300/abc281/a.py @@ -1,4 +1,4 @@ n = int(input()) ans = [i for i in range(n + 1)] ans.sort(reverse=True) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc201-300/abc281/b.py b/atcoder/abc/abc201-300/abc281/b.py index 1dc87955..135fd922 100644 --- a/atcoder/abc/abc201-300/abc281/b.py +++ b/atcoder/abc/abc201-300/abc281/b.py @@ -12,4 +12,4 @@ except: print("No") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc201-300/abc281/c.py b/atcoder/abc/abc201-300/abc281/c.py index 8b6f7159..229b089b 100644 --- a/atcoder/abc/abc201-300/abc281/c.py +++ b/atcoder/abc/abc201-300/abc281/c.py @@ -7,4 +7,4 @@ t -= a_i if t <= 0: print(f"{i} {a_i + t}") - break \ No newline at end of file + break diff --git a/atcoder/abc/abc201-300/abc281/d.py b/atcoder/abc/abc201-300/abc281/d.py index b90afe99..e019ae17 100644 --- a/atcoder/abc/abc201-300/abc281/d.py +++ b/atcoder/abc/abc201-300/abc281/d.py @@ -14,7 +14,7 @@ for ii in range(d): dp[i][j][ii] = max( dp[i - 1][j][ii], # i番目を選択しない - dp[i - 1][j - 1][(ii - ai) % d] + ai # i番目を選択する + dp[i - 1][j - 1][(ii - ai) % d] + ai, # i番目を選択する ) ans = dp[-1][-1][0] diff --git a/atcoder/abc/abc201-300/abc282/a.py b/atcoder/abc/abc201-300/abc282/a.py index ba01e2af..c31e99b6 100644 --- a/atcoder/abc/abc201-300/abc282/a.py +++ b/atcoder/abc/abc201-300/abc282/a.py @@ -3,4 +3,4 @@ ans = "" for i in range(k): ans += chr(ord("A") + i) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc201-300/abc282/c.py b/atcoder/abc/abc201-300/abc282/c.py index b3f9d769..d9a7fe1a 100644 --- a/atcoder/abc/abc201-300/abc282/c.py +++ b/atcoder/abc/abc201-300/abc282/c.py @@ -5,7 +5,7 @@ ans = [] for i in range(n): # ""で囲まれていない,を.にする - if s[i] == "\"": + if s[i] == '"': flag = not flag if s[i] == "," and flag: diff --git a/atcoder/abc/abc201-300/abc282/d.py b/atcoder/abc/abc201-300/abc282/d.py index f5f2a3a9..3ea67c9e 100644 --- a/atcoder/abc/abc201-300/abc282/d.py +++ b/atcoder/abc/abc201-300/abc282/d.py @@ -3,4 +3,3 @@ for _ in range(m): u, v = map(int, input().split()) uv.append((u - 1, v - 1)) - diff --git a/atcoder/abc/abc201-300/abc283/a.py b/atcoder/abc/abc201-300/abc283/a.py index a0924417..89c440e9 100644 --- a/atcoder/abc/abc201-300/abc283/a.py +++ b/atcoder/abc/abc201-300/abc283/a.py @@ -1,2 +1,2 @@ a, b = map(int, input().split()) -print(a ** b) +print(a**b) diff --git a/atcoder/abc/abc201-300/abc284/d.py b/atcoder/abc/abc201-300/abc284/d.py index 38f605ce..21b7ba36 100644 --- a/atcoder/abc/abc201-300/abc284/d.py +++ b/atcoder/abc/abc201-300/abc284/d.py @@ -6,9 +6,9 @@ def solve(): for i in range(2, ceil(n ** (1 / 3)) + 1): div = n // i - if n % i ** 2 == 0: + if n % i**2 == 0: p = i - q = n // i ** 2 + q = n // i**2 break elif n % i == 0 and int(sqrt(div)) ** 2 == div: p = int(sqrt(div)) diff --git a/atcoder/abc/abc201-300/abc284/e.py b/atcoder/abc/abc201-300/abc284/e.py index b5c42f34..064631fe 100644 --- a/atcoder/abc/abc201-300/abc284/e.py +++ b/atcoder/abc/abc201-300/abc284/e.py @@ -3,7 +3,7 @@ input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -MAX = 10 ** 6 +MAX = 10**6 n, m = map(int, input().split()) edges = defaultdict(list) diff --git a/atcoder/abc/abc201-300/abc285/c.py b/atcoder/abc/abc201-300/abc285/c.py index fccbc9e7..ec693cb3 100644 --- a/atcoder/abc/abc201-300/abc285/c.py +++ b/atcoder/abc/abc201-300/abc285/c.py @@ -6,5 +6,5 @@ ans = 0 s.reverse() for i in range(len(s)): - ans += (ord(s[i]) - ord("A") + 1) * (26 ** i) + ans += (ord(s[i]) - ord("A") + 1) * (26**i) print(ans) diff --git a/atcoder/abc/abc201-300/abc293/e.py b/atcoder/abc/abc201-300/abc293/e.py index a715d489..9a523bb2 100644 --- a/atcoder/abc/abc201-300/abc293/e.py +++ b/atcoder/abc/abc201-300/abc293/e.py @@ -1,7 +1,7 @@ a, x, m = map(int, input().split()) -def rep_pow(a: int, k: int, p: int = 10 ** 9 + 7) -> int: +def rep_pow(a: int, k: int, p: int = 10**9 + 7) -> int: # calculate exponentiation: a^k mod p # O(log(p)) ans = 1 diff --git a/atcoder/abc/abc201-300/abc298/d.py b/atcoder/abc/abc201-300/abc298/d.py index bed4f31d..d1a2da2a 100644 --- a/atcoder/abc/abc201-300/abc298/d.py +++ b/atcoder/abc/abc201-300/abc298/d.py @@ -80,7 +80,7 @@ def __rpow__(self, other): s = deque([1]) ans = [] -ten_multi = [0 for _ in range((6 * (10 ** 5)) + 1)] +ten_multi = [0 for _ in range((6 * (10**5)) + 1)] ten = 1 for i in range(len(ten_multi)): ten_multi[i] = ten diff --git a/atcoder/abc/abc201-300/abc298/e.py b/atcoder/abc/abc201-300/abc298/e.py index 33100192..26675c5d 100644 --- a/atcoder/abc/abc201-300/abc298/e.py +++ b/atcoder/abc/abc201-300/abc298/e.py @@ -16,7 +16,7 @@ def rep_sqr(self, base: int, k: int) -> int: return ans def inv(self, a: int) -> int: - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) diff --git a/atcoder/abc/abc201-300/abc300/d.py b/atcoder/abc/abc201-300/abc300/d.py index fed295d1..deccb2cd 100644 --- a/atcoder/abc/abc201-300/abc300/d.py +++ b/atcoder/abc/abc201-300/abc300/d.py @@ -9,7 +9,7 @@ def sieve_of_eratosthenes( is_prime_list = [True] * (n + 1) is_prime_list[0] = False is_prime_list[1] = False - for i in range(2, int(n ** 0.5) + 1): + for i in range(2, int(n**0.5) + 1): if not is_prime_list[i]: continue for j in range(i * 2, n + 1, i): @@ -50,7 +50,7 @@ def sieve_of_eratosthenes( continue if b >= c: break - if v ** 2 * b > n: + if v**2 * b > n: break # print(a, b, c, a ** 2 * b * c ** 2) ans += 1 diff --git a/atcoder/abc/abc201-300/abc300/g.py b/atcoder/abc/abc201-300/abc300/g.py index a5c50386..b4451076 100644 --- a/atcoder/abc/abc201-300/abc300/g.py +++ b/atcoder/abc/abc201-300/abc300/g.py @@ -11,7 +11,7 @@ def sieve_of_eratosthenes( is_prime_list = [True] * (n + 1) is_prime_list[0] = False is_prime_list[1] = False - for i in range(2, int(n ** 0.5) + 1): + for i in range(2, int(n**0.5) + 1): if not is_prime_list[i]: continue for j in range(i * 2, n + 1, i): diff --git a/atcoder/abc/abc301-400/abc304/b.py b/atcoder/abc/abc301-400/abc304/b.py index fb45e9d6..2ea1a018 100644 --- a/atcoder/abc/abc301-400/abc304/b.py +++ b/atcoder/abc/abc301-400/abc304/b.py @@ -1,16 +1,16 @@ n = int(input()) -if n <= 10 ** 3 - 1: +if n <= 10**3 - 1: print(n) -elif n <= 10 ** 4 - 1: +elif n <= 10**4 - 1: print(n // 10 * 10) -elif n <= 10 ** 5 - 1: +elif n <= 10**5 - 1: print(n // 100 * 100) -elif n <= 10 ** 6 - 1: +elif n <= 10**6 - 1: print(n // 1000 * 1000) -elif n <= 10 ** 7 - 1: +elif n <= 10**7 - 1: print(n // 10000 * 10000) -elif n <= 10 ** 8 - 1: +elif n <= 10**8 - 1: print(n // 100000 * 100000) -elif n <= 10 ** 9 - 1: +elif n <= 10**9 - 1: print(n // 1000000 * 1000000) diff --git a/atcoder/abc/abc301-400/abc304/f.py b/atcoder/abc/abc301-400/abc304/f.py index 92d01c1a..755fc08f 100644 --- a/atcoder/abc/abc301-400/abc304/f.py +++ b/atcoder/abc/abc301-400/abc304/f.py @@ -7,7 +7,7 @@ def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if i == n: continue if n % i == 0: diff --git a/atcoder/abc/abc301-400/abc304/g.py b/atcoder/abc/abc301-400/abc304/g.py index ed32f3fd..2d20fe17 100644 --- a/atcoder/abc/abc301-400/abc304/g.py +++ b/atcoder/abc/abc301-400/abc304/g.py @@ -10,7 +10,7 @@ def is_ok(m): l = 0 -r = 10 ** 12 +r = 10**12 while r - l > 1: m = (l + r) // 2 if is_ok(m): diff --git a/atcoder/abc/abc301-400/abc305/d.py b/atcoder/abc/abc301-400/abc305/d.py index 8a306aa0..c924954b 100644 --- a/atcoder/abc/abc301-400/abc305/d.py +++ b/atcoder/abc/abc301-400/abc305/d.py @@ -27,8 +27,8 @@ class SegTree: def __init__(self, n: int, mode: str = "min") -> None: self.mode = mode unit_elements = { - "min": 10 ** 13, - "max": -(10 ** 13), + "min": 10**13, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, @@ -38,7 +38,7 @@ def __init__(self, n: int, mode: str = "min") -> None: self.tree_value = [self.e] * 2 * self.tree_size def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 diff --git a/atcoder/abc/abc301-400/abc305/e.py b/atcoder/abc/abc301-400/abc305/e.py index 61f3018b..7a304894 100644 --- a/atcoder/abc/abc301-400/abc305/e.py +++ b/atcoder/abc/abc301-400/abc305/e.py @@ -4,7 +4,7 @@ input = lambda: sys.stdin.readline().rstrip() -MAX_N = 3 * 10 ** 5 +MAX_N = 3 * 10**5 n, m, k = map(int, input().split()) ab = [list(map(int, input().split())) for _ in [0] * m] diff --git a/atcoder/abc/abc301-400/abc306/b.py b/atcoder/abc/abc301-400/abc306/b.py index b608f1a4..9b6d4fd5 100644 --- a/atcoder/abc/abc301-400/abc306/b.py +++ b/atcoder/abc/abc301-400/abc306/b.py @@ -2,5 +2,5 @@ ans = 0 for i, a_i in enumerate(a): - ans += 2 ** i * a_i + ans += 2**i * a_i print(ans) diff --git a/atcoder/abc/abc301-400/abc306/f.py b/atcoder/abc/abc301-400/abc306/f.py index 0cf9fbe3..84699a7b 100644 --- a/atcoder/abc/abc301-400/abc306/f.py +++ b/atcoder/abc/abc301-400/abc306/f.py @@ -27,8 +27,8 @@ class SegTree: def __init__(self, n: int, mode: str = "min") -> None: self.mode = mode unit_elements = { - "min": 10 ** 13, - "max": -(10 ** 13), + "min": 10**13, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, @@ -38,7 +38,7 @@ def __init__(self, n: int, mode: str = "min") -> None: self.tree_value = [self.e] * 2 * self.tree_size def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 diff --git a/atcoder/abc/abc301-400/abc308/c.py b/atcoder/abc/abc301-400/abc308/c.py index bf82835f..aea13fe5 100644 --- a/atcoder/abc/abc301-400/abc308/c.py +++ b/atcoder/abc/abc301-400/abc308/c.py @@ -7,7 +7,7 @@ def solve1(ab): ans = [] for i, (a, b) in enumerate(ab, start=1): - p = (10 ** 20 * a) // (a + b) + p = (10**20 * a) // (a + b) ans.append([p, i]) ans.sort(key=lambda x: (-x[0], x[1])) ans = [i for _, i in ans] diff --git a/atcoder/abc/abc301-400/abc312/a.py b/atcoder/abc/abc301-400/abc312/a.py index 4add8697..f177d5fc 100644 --- a/atcoder/abc/abc301-400/abc312/a.py +++ b/atcoder/abc/abc301-400/abc312/a.py @@ -4,4 +4,4 @@ if s in l: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc312/b.py b/atcoder/abc/abc301-400/abc312/b.py index 0608bb8f..76d31ad2 100644 --- a/atcoder/abc/abc301-400/abc312/b.py +++ b/atcoder/abc/abc301-400/abc312/b.py @@ -13,8 +13,8 @@ if ii == 3 or jj == 3: if s[i + ii][j + jj] == ".": left_up_white += 1 - elif 0 <= i+ii < n and 0 <= j+jj < m: - if s[i+ii][j+jj] == "#": + elif 0 <= i + ii < n and 0 <= j + jj < m: + if s[i + ii][j + jj] == "#": left_up += 1 right_down_white = 0 right_down = 0 @@ -27,6 +27,11 @@ if s[i + 5 + ii][j + 5 + jj] == "#": right_down += 1 # print(left_up_white, left_up, right_down_white, right_down) - if left_up_white == 7 and left_up == 9 and right_down_white == 7 and right_down == 9: + if ( + left_up_white == 7 + and left_up == 9 + and right_down_white == 7 + and right_down == 9 + ): ans.append(f"{i + 1} {j + 1}") -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc312/c.py b/atcoder/abc/abc301-400/abc312/c.py index a2216733..3fbf4464 100644 --- a/atcoder/abc/abc301-400/abc312/c.py +++ b/atcoder/abc/abc301-400/abc312/c.py @@ -1,5 +1,6 @@ -import sys import bisect +import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -25,4 +26,4 @@ if a_count >= (m - b_count): ans = x break -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc312/d.py b/atcoder/abc/abc301-400/abc312/d.py index 1a0fe7bd..035cf0fe 100644 --- a/atcoder/abc/abc301-400/abc312/d.py +++ b/atcoder/abc/abc301-400/abc312/d.py @@ -1,4 +1,5 @@ from collections import defaultdict + MOD = 998244353 s = list(input()) @@ -33,4 +34,4 @@ if j > 0: dp[i][j - 1] += dp[i - 1][j] dp[i][j - 1] %= MOD -print(dp[len(s)][0]) \ No newline at end of file +print(dp[len(s)][0]) diff --git a/atcoder/abc/abc301-400/abc312/e.py b/atcoder/abc/abc301-400/abc312/e.py index bb3f060e..418840af 100644 --- a/atcoder/abc/abc301-400/abc312/e.py +++ b/atcoder/abc/abc301-400/abc312/e.py @@ -1,4 +1,5 @@ from collections import defaultdict + MAX_SIZE = 100 n = int(input()) @@ -7,13 +8,18 @@ l_i = list(map(lambda x: int(x) + 1, input().split())) l.append(l_i) + def iterations(x1, x2, y1, y2, z1, z2): for x in range(x1, x2): for y in range(y1, y2): for z in range(z1, z2): yield x, y, z -grid = [[[-1 for _ in range(MAX_SIZE + 2)] for _ in range(MAX_SIZE + 2)] for _ in range(MAX_SIZE + 2)] + +grid = [ + [[-1 for _ in range(MAX_SIZE + 2)] for _ in range(MAX_SIZE + 2)] + for _ in range(MAX_SIZE + 2) +] for i, (x1, y1, z1, x2, y2, z2) in enumerate(l, start=1): # 6面グリッドを埋めていく # x軸方向の面 @@ -24,7 +30,14 @@ def iterations(x1, x2, y1, y2, z1, z2): for x, y, z in iterations(1, MAX_SIZE + 1, 1, MAX_SIZE + 1, 1, MAX_SIZE + 1): num1 = grid[x][y][z] # 6方向探索 - for dx, dy, dz in [[0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -1, 0], [1, 0, 0], [-1, 0, 0]]: + for dx, dy, dz in [ + [0, 0, 1], + [0, 0, -1], + [0, 1, 0], + [0, -1, 0], + [1, 0, 0], + [-1, 0, 0], + ]: num2 = grid[x + dx][y + dy][z + dz] if num1 == -1 or num2 == -1 or num1 == num2: continue @@ -35,4 +48,4 @@ def iterations(x1, x2, y1, y2, z1, z2): for i in range(1, n + 1): ans_out.append(len(ans[i])) -print(*ans_out, sep="\n") \ No newline at end of file +print(*ans_out, sep="\n") diff --git a/atcoder/abc/abc301-400/abc312/f.py b/atcoder/abc/abc301-400/abc312/f.py index 64fa9d7b..14ee7b37 100644 --- a/atcoder/abc/abc301-400/abc312/f.py +++ b/atcoder/abc/abc301-400/abc312/f.py @@ -1,9 +1,10 @@ -import sys import heapq +import sys from collections import defaultdict, deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -INF = 10 ** 20 +INF = 10**20 n, m = map(int, input().split()) tx = [] @@ -20,9 +21,9 @@ else: openers.append(x) -can_without_opener.sort(reverse=True) # 満足度が高いものから -can_with_opener.sort(reverse=True) # 満足度が高いものから -openers.sort(reverse=True) # 多く開けられるものから +can_without_opener.sort(reverse=True) # 満足度が高いものから +can_with_opener.sort(reverse=True) # 満足度が高いものから +openers.sort(reverse=True) # 多く開けられるものから can_with_opener = deque(can_with_opener) # 缶抜きの数を累積和で管理する @@ -31,6 +32,8 @@ def cumsum(a): for v in a: r.append(r[-1] + v) return r + + openers_cumsum = cumsum(openers) sum_value = 0 diff --git a/atcoder/abc/abc301-400/abc312/g.py b/atcoder/abc/abc301-400/abc312/g.py index 6065d14b..4600b039 100644 --- a/atcoder/abc/abc301-400/abc312/g.py +++ b/atcoder/abc/abc301-400/abc312/g.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -11,5 +12,3 @@ # 2頂点を選んだ時に通ることができない頂点の数を求める # 木DPっぽい # ある頂点を根とした時に、その頂点を通ることができない頂点の数を求める - - diff --git a/atcoder/abc/abc301-400/abc313/a.py b/atcoder/abc/abc301-400/abc313/a.py index 777426e7..ca73ddf1 100644 --- a/atcoder/abc/abc301-400/abc313/a.py +++ b/atcoder/abc/abc301-400/abc313/a.py @@ -9,4 +9,4 @@ elif max(a[1:]) == me: print(1) else: - print(0) \ No newline at end of file + print(0) diff --git a/atcoder/abc/abc301-400/abc313/b.py b/atcoder/abc/abc301-400/abc313/b.py index 8575348b..879fcd20 100644 --- a/atcoder/abc/abc301-400/abc313/b.py +++ b/atcoder/abc/abc301-400/abc313/b.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n, m = map(int, input().split()) ab = defaultdict(lambda: []) for _ in range(m): @@ -29,4 +30,4 @@ if count == n: ans = i + 1 break -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc313/c.py b/atcoder/abc/abc301-400/abc313/c.py index 9a38a49c..99b3fbe6 100644 --- a/atcoder/abc/abc301-400/abc313/c.py +++ b/atcoder/abc/abc301-400/abc313/c.py @@ -1,4 +1,5 @@ from collections import deque + n = int(input()) a = list(map(int, input().split())) a.sort() diff --git a/atcoder/abc/abc301-400/abc313/d.py b/atcoder/abc/abc301-400/abc313/d.py index 7f0f2733..ebf147e4 100644 --- a/atcoder/abc/abc301-400/abc313/d.py +++ b/atcoder/abc/abc301-400/abc313/d.py @@ -1,4 +1,5 @@ from collections import defaultdict + n, k = map(int, input().split()) memo = defaultdict(lambda: -1) each_group = defaultdict(lambda: -1) @@ -8,6 +9,7 @@ def answer(a): out = "! " + " ".join(list(map(str, a))) print(out) + def question(a): a_str = " ".join(sorted(list(map(str, a)))) if memo[a_str] != -1: @@ -18,6 +20,7 @@ def question(a): memo[a_str] = res return res + # グループ分けを行なう # 1をgroup1とする groups = [[1], []] @@ -45,12 +48,12 @@ def question(a): xj = question([j for j in range(1, k + 1)]) if xi == xj: # iとjは同じ値 - groups[each_group[k+1]].append(i) - each_group[i] = each_group[k+1] + groups[each_group[k + 1]].append(i) + each_group[i] = each_group[k + 1] else: # iとjは異なる値 - groups[each_group[k+1] ^ 1].append(i) - each_group[i] = each_group[k+1] ^ 1 + groups[each_group[k + 1] ^ 1].append(i) + each_group[i] = each_group[k + 1] ^ 1 # 全部でN回の質問 a0 = [0 for _ in range(n)] a1 = [0 for _ in range(n)] @@ -80,4 +83,4 @@ def question(a): if count_a0 == n: answer(a0) else: - answer(a1) \ No newline at end of file + answer(a1) diff --git a/atcoder/abc/abc301-400/abc313/e.py b/atcoder/abc/abc301-400/abc313/e.py index 30448ec8..7e3bc83a 100644 --- a/atcoder/abc/abc301-400/abc313/e.py +++ b/atcoder/abc/abc301-400/abc313/e.py @@ -25,4 +25,4 @@ t += 1 t %= MOD # print(t) - print(t - 1) \ No newline at end of file + print(t - 1) diff --git a/atcoder/abc/abc301-400/abc314/a.py b/atcoder/abc/abc301-400/abc314/a.py index 9ba0087b..b15d73bc 100644 --- a/atcoder/abc/abc301-400/abc314/a.py +++ b/atcoder/abc/abc301-400/abc314/a.py @@ -1,3 +1,3 @@ s = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679" n = int(input()) -print(s[:n+2]) \ No newline at end of file +print(s[: n + 2]) diff --git a/atcoder/abc/abc301-400/abc314/b.py b/atcoder/abc/abc301-400/abc314/b.py index ddb4bc29..156d7851 100644 --- a/atcoder/abc/abc301-400/abc314/b.py +++ b/atcoder/abc/abc301-400/abc314/b.py @@ -18,4 +18,4 @@ ans[1].append(i + 1) out = sorted(ans[1]) print(len(out)) -print(*out, sep=" ") \ No newline at end of file +print(*out, sep=" ") diff --git a/atcoder/abc/abc301-400/abc314/c.py b/atcoder/abc/abc301-400/abc314/c.py index 112210e7..5206a906 100644 --- a/atcoder/abc/abc301-400/abc314/c.py +++ b/atcoder/abc/abc301-400/abc314/c.py @@ -1,4 +1,5 @@ -from collections import deque, defaultdict +from collections import defaultdict, deque + n, m = map(int, input().split()) s = list(input()) c = list(map(int, input().split())) @@ -16,4 +17,4 @@ for ci in c: ans.append(que[ci].popleft()) -print("".join(ans)) \ No newline at end of file +print("".join(ans)) diff --git a/atcoder/abc/abc301-400/abc314/d.py b/atcoder/abc/abc301-400/abc314/d.py index 2be6e2c8..2dc5681e 100644 --- a/atcoder/abc/abc301-400/abc314/d.py +++ b/atcoder/abc/abc301-400/abc314/d.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -7,7 +8,7 @@ s = list(input()) q = int(input()) txc = [] -status = 0 # 1: komoji, 2: oomoji +status = 0 # 1: komoji, 2: oomoji exclude_set = set() for _ in range(q): t, x, c = input().split() @@ -32,4 +33,4 @@ if i not in exclude_set: s[i] = si.upper() -print("".join(s)) \ No newline at end of file +print("".join(s)) diff --git a/atcoder/abc/abc301-400/abc314/e.py b/atcoder/abc/abc301-400/abc314/e.py index d9b78f0a..ac8ac3a4 100644 --- a/atcoder/abc/abc301-400/abc314/e.py +++ b/atcoder/abc/abc301-400/abc314/e.py @@ -1,5 +1,6 @@ import sys from collections import defaultdict + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -40,4 +41,4 @@ continue for cost, p in dp[i].items(): ans += p * cost -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc314/f.py b/atcoder/abc/abc301-400/abc314/f.py index 3f89adcd..26a7cca2 100644 --- a/atcoder/abc/abc301-400/abc314/f.py +++ b/atcoder/abc/abc301-400/abc314/f.py @@ -1,8 +1,10 @@ import sys from collections import defaultdict, deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) + class ModInt: def __init__(self, x, p=998244353): self.mod = p @@ -73,7 +75,8 @@ def __rpow__(self, other): else ModInt(pow(other, self.x, self.mod)) ) -class UnionFind(): + +class UnionFind: def __init__(self, n): self.n = n + 1 self.parents = [-1] * (n + 1) @@ -118,7 +121,8 @@ def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): - return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) + return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) + n = int(input()) pq = [] @@ -135,6 +139,7 @@ def __str__(self): points = defaultdict(lambda: ModInt(0)) parents = defaultdict(lambda: -1) + def find_parents(node): first_node = node path_node_list = [first_node] @@ -145,6 +150,7 @@ def find_parents(node): parents[child_node] = node return node + for edge_i, (p, q) in enumerate(pq, start=0): # pが先攻, qが後攻 edge_num = n + edge_i @@ -180,4 +186,4 @@ def find_parents(node): ans.append(ans_i) # print(edge_name) # print(edges) -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc301-400/abc314/g.py b/atcoder/abc/abc301-400/abc314/g.py index f0c33e60..81b81edc 100644 --- a/atcoder/abc/abc301-400/abc314/g.py +++ b/atcoder/abc/abc301-400/abc314/g.py @@ -4,4 +4,3 @@ for _ in range(n): a, b = map(int, input().split()) ab.append([a, b]) - diff --git a/atcoder/abc/abc301-400/abc315/a.py b/atcoder/abc/abc301-400/abc315/a.py index dbc5cef2..7c0a40ff 100644 --- a/atcoder/abc/abc301-400/abc315/a.py +++ b/atcoder/abc/abc301-400/abc315/a.py @@ -6,4 +6,4 @@ if si in ex: continue ans.append(si) -print("".join(ans)) \ No newline at end of file +print("".join(ans)) diff --git a/atcoder/abc/abc301-400/abc315/b.py b/atcoder/abc/abc301-400/abc315/b.py index fb9c535d..fd8f32f0 100644 --- a/atcoder/abc/abc301-400/abc315/b.py +++ b/atcoder/abc/abc301-400/abc315/b.py @@ -7,4 +7,4 @@ for day in range(1, d[month - 1] + 1): list.append([month, day]) -print(f"{list[len(list) // 2][0]} {list[len(list) // 2][1]}") \ No newline at end of file +print(f"{list[len(list) // 2][0]} {list[len(list) // 2][1]}") diff --git a/atcoder/abc/abc301-400/abc315/c_saki.py b/atcoder/abc/abc301-400/abc315/c_saki.py index 9699d946..33d98639 100644 --- a/atcoder/abc/abc301-400/abc315/c_saki.py +++ b/atcoder/abc/abc301-400/abc315/c_saki.py @@ -6,13 +6,13 @@ ans = 0 for i in range(N): - for j in range(i+1,N): + for j in range(i + 1, N): if S[i][0] != S[j][0]: if ans < S[i][1] + S[j][1]: ans = S[i][1] + S[j][1] break else: - if ans < S[i][1] + S[j][1]//2: - ans = S[i][1] + S[j][1]//2 + if ans < S[i][1] + S[j][1] // 2: + ans = S[i][1] + S[j][1] // 2 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc315/d.py b/atcoder/abc/abc301-400/abc315/d.py index 225cb516..eca475f8 100644 --- a/atcoder/abc/abc301-400/abc315/d.py +++ b/atcoder/abc/abc301-400/abc315/d.py @@ -1,4 +1,5 @@ from collections import defaultdict + h, w = map(int, input().split()) c = [list(input()) for _ in range(h)] @@ -52,4 +53,4 @@ for idx in counter[s].keys(): for v in counter[s][idx].values(): ans += v -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc315/e.py b/atcoder/abc/abc301-400/abc315/e.py index 4664ac52..afe6dd15 100644 --- a/atcoder/abc/abc301-400/abc315/e.py +++ b/atcoder/abc/abc301-400/abc315/e.py @@ -1,7 +1,9 @@ import sys from collections import defaultdict + import pypyjit -pypyjit.set_param('max_unroll_recursion=-1') + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -21,6 +23,8 @@ ans = [] set_ans = set() visited = defaultdict(lambda: False) + + def dfs(i): if visited[i]: return @@ -34,5 +38,6 @@ def dfs(i): ans.append(i) set_ans.add(i) + dfs(1) print(*ans[:-1], sep=" ") diff --git a/atcoder/abc/abc301-400/abc315/f.py b/atcoder/abc/abc301-400/abc315/f.py index 438cabca..df0c280a 100644 --- a/atcoder/abc/abc301-400/abc315/f.py +++ b/atcoder/abc/abc301-400/abc315/f.py @@ -1,17 +1,21 @@ -import sys import math +import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) def dist(i, j): - return math.sqrt((xy[i - 1][0] - xy[j - 1][0]) ** 2 + (xy[i - 1][1] - xy[j - 1][1]) ** 2) + return math.sqrt( + (xy[i - 1][0] - xy[j - 1][0]) ** 2 + (xy[i - 1][1] - xy[j - 1][1]) ** 2 + ) + def penalty(i): if i == 0: return 0 else: - return 2**(i - 1) + return 2 ** (i - 1) n = int(input()) @@ -40,17 +44,24 @@ def penalty(i): # 頂点1からスタート dp[1][0] = 0 -for start in range(1, n + 1): # 次に訪れるべき頂点 - for penalty_count in range(max_value): # それまで無視した頂点数 - for skip_count in range(1, max_value): # 連続で無視する頂点数 +for start in range(1, n + 1): # 次に訪れるべき頂点 + for penalty_count in range(max_value): # それまで無視した頂点数 + for skip_count in range(1, max_value): # 連続で無視する頂点数 if start + skip_count > n: break if penalty_count + skip_count > max_value: break - base = dp[start][penalty_count] + dist(start, start + skip_count) + penalty(penalty_count + skip_count - 1) - penalty(penalty_count) - dp[start + skip_count][penalty_count + skip_count - 1] = min(dp[start + skip_count][penalty_count + skip_count - 1], base) + base = ( + dp[start][penalty_count] + + dist(start, start + skip_count) + + penalty(penalty_count + skip_count - 1) + - penalty(penalty_count) + ) + dp[start + skip_count][penalty_count + skip_count - 1] = min( + dp[start + skip_count][penalty_count + skip_count - 1], base + ) ans = INF # print(dp) for v in dp[n]: ans = min(ans, v) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc316/c.py b/atcoder/abc/abc301-400/abc316/c.py index 26045802..328584cb 100644 --- a/atcoder/abc/abc301-400/abc316/c.py +++ b/atcoder/abc/abc301-400/abc316/c.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n, m = map(int, input().split()) abc = [] @@ -32,4 +33,4 @@ if next in visited: continue q.appendleft([next, dist + next_dist, path_num + 1]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc316/d.py b/atcoder/abc/abc301-400/abc316/d.py index 8f726fd6..eb42c335 100644 --- a/atcoder/abc/abc301-400/abc316/d.py +++ b/atcoder/abc/abc301-400/abc316/d.py @@ -1,6 +1,7 @@ import math from collections import defaultdict -INF = float('inf') + +INF = float("inf") n = int(input()) candidates = [] diff --git a/atcoder/abc/abc301-400/abc316/e.py b/atcoder/abc/abc301-400/abc316/e.py index 45711f47..83b99eef 100644 --- a/atcoder/abc/abc301-400/abc316/e.py +++ b/atcoder/abc/abc301-400/abc316/e.py @@ -1,6 +1,7 @@ import sys -from collections import deque, defaultdict -INF = float('inf') +from collections import defaultdict, deque + +INF = float("inf") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -79,4 +80,4 @@ que.append([dist + 1, [ni, nj]]) visited[ni][nj] = True # print(a) -print(-1) \ No newline at end of file +print(-1) diff --git a/atcoder/abc/abc301-400/abc316/g.py b/atcoder/abc/abc301-400/abc316/g.py index 74eebed1..ced1ffe5 100644 --- a/atcoder/abc/abc301-400/abc316/g.py +++ b/atcoder/abc/abc301-400/abc316/g.py @@ -1,6 +1,7 @@ import sys -from collections import deque, defaultdict -INF = float('inf') +from collections import defaultdict, deque + +INF = float("inf") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -9,4 +10,4 @@ for i in range(h): ai = list(input()) - a.append(ai) \ No newline at end of file + a.append(ai) diff --git a/atcoder/abc/abc301-400/abc318/a.py b/atcoder/abc/abc301-400/abc318/a.py index c28d0eab..2f87b636 100644 --- a/atcoder/abc/abc301-400/abc318/a.py +++ b/atcoder/abc/abc301-400/abc318/a.py @@ -5,4 +5,4 @@ for i in range(1, n + 1): if (i - m) % p == 0: ans += 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc318/b.py b/atcoder/abc/abc301-400/abc318/b.py index 03e6c3cd..2c916fb7 100644 --- a/atcoder/abc/abc301-400/abc318/b.py +++ b/atcoder/abc/abc301-400/abc318/b.py @@ -18,4 +18,4 @@ for j in range(101): if grid[i][j] == 1: ans += 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc318/c.py b/atcoder/abc/abc301-400/abc318/c.py index 8e4f57ca..5ddc6583 100644 --- a/atcoder/abc/abc301-400/abc318/c.py +++ b/atcoder/abc/abc301-400/abc318/c.py @@ -1,8 +1,9 @@ from collections import deque + n, d, p = map(int, input().split()) f = list(map(int, input().split())) f_origin = f[:] -INF = float('inf') +INF = float("inf") f.sort(reverse=True) f = deque(f) diff --git a/atcoder/abc/abc301-400/abc318/d.py b/atcoder/abc/abc301-400/abc318/d.py index b9359ed9..65be8d0d 100644 --- a/atcoder/abc/abc301-400/abc318/d.py +++ b/atcoder/abc/abc301-400/abc318/d.py @@ -1,9 +1,10 @@ -import sys -import math import itertools +import math +import sys from collections import defaultdict + input = lambda: sys.stdin.readline().rstrip() -INF = float('inf') +INF = float("inf") n = int(input()) costs = defaultdict(lambda: defaultdict(lambda: 0)) @@ -25,6 +26,8 @@ if bit & (1 << i) == 0: zero_bits.append(i) for bit_i, bit_j in itertools.combinations(zero_bits, 2): - dp[bit | (1 << bit_i) | (1 << bit_j)] = max(dp[bit | (1 << bit_i) | (1 << bit_j)], dp[bit] + costs[bit_i][bit_j]) + dp[bit | (1 << bit_i) | (1 << bit_j)] = max( + dp[bit | (1 << bit_i) | (1 << bit_j)], dp[bit] + costs[bit_i][bit_j] + ) ans = max(ans, dp[bit | (1 << bit_i) | (1 << bit_j)]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc318/e.py b/atcoder/abc/abc301-400/abc318/e.py index da2eb8fd..e7292fc7 100644 --- a/atcoder/abc/abc301-400/abc318/e.py +++ b/atcoder/abc/abc301-400/abc318/e.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n = int(input()) a = list(map(int, input().split())) @@ -7,7 +8,7 @@ print(a) for i in range(len(a)): - counter[a[i]][1] += (i - counter[a[i]][0]) + counter[a[i]][1] += i - counter[a[i]][0] counter[a[i]][0] += 1 ans = 0 diff --git a/atcoder/abc/abc301-400/abc319/b.py b/atcoder/abc/abc301-400/abc319/b.py index 18c763b5..6121546c 100644 --- a/atcoder/abc/abc301-400/abc319/b.py +++ b/atcoder/abc/abc301-400/abc319/b.py @@ -1,8 +1,9 @@ n = int(input()) + def make_divisors(n): divisors = [] - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if i == n: continue if n % i == 0: @@ -13,6 +14,7 @@ def make_divisors(n): divisors.append(n // i) return sorted(divisors) + # 約数列挙 divs = list(make_divisors(n)) + [n] diff --git a/atcoder/abc/abc301-400/abc319/c.py b/atcoder/abc/abc301-400/abc319/c.py index 59f6a890..aa0864b8 100644 --- a/atcoder/abc/abc301-400/abc319/c.py +++ b/atcoder/abc/abc301-400/abc319/c.py @@ -1,19 +1,24 @@ import decimal from collections import defaultdict from itertools import permutations + c = [list(map(int, input().split())) for _ in range(3)] -c_list = [c[0][0], c[0][1], c[0][2], c[1][0], c[1][1], c[1][2], c[2][0], c[2][1], c[2][2]] +c_list = [ + c[0][0], + c[0][1], + c[0][2], + c[1][0], + c[1][1], + c[1][2], + c[2][0], + c[2][1], + c[2][2], +] # 順列全探索 count_all = 0 count_ok = 0 -naname_group = { - 0: [0], - 2: [1], - 4: [0, 1], - 6: [1], - 8: [0] -} +naname_group = {0: [0], 2: [1], 4: [0, 1], 6: [1], 8: [0]} for perm in permutations(list(range(9))): # print(perm) tate = defaultdict(lambda: set()) @@ -45,4 +50,4 @@ if flag: count_ok += 1 # print(count_all, count_ok) -print(decimal.Decimal(count_ok) / decimal.Decimal(count_all)) \ No newline at end of file +print(decimal.Decimal(count_ok) / decimal.Decimal(count_all)) diff --git a/atcoder/abc/abc301-400/abc319/d.py b/atcoder/abc/abc301-400/abc319/d.py index e583c021..8270d507 100644 --- a/atcoder/abc/abc301-400/abc319/d.py +++ b/atcoder/abc/abc301-400/abc319/d.py @@ -25,4 +25,4 @@ else: # m行以下で表示できない場合、window_sizeが小さすぎるのでwindow_sizeを大きくしていく left = window_size -print(right) \ No newline at end of file +print(right) diff --git a/atcoder/abc/abc301-400/abc319/e.py b/atcoder/abc/abc301-400/abc319/e.py index f008db4d..0abce26a 100644 --- a/atcoder/abc/abc301-400/abc319/e.py +++ b/atcoder/abc/abc301-400/abc319/e.py @@ -15,6 +15,7 @@ CONST_VALUE = 3 * 5 * 7 * 8 ans = [] + @lru_cache(maxsize=None) def calc_bus(time): start_time = time @@ -26,6 +27,7 @@ def calc_bus(time): time += t return time - start_time + for qi in q_list: start_time = qi + x end_time = start_time + calc_bus(start_time % CONST_VALUE) diff --git a/atcoder/abc/abc301-400/abc320/a.py b/atcoder/abc/abc301-400/abc320/a.py index 132f4bbf..2d900436 100644 --- a/atcoder/abc/abc301-400/abc320/a.py +++ b/atcoder/abc/abc301-400/abc320/a.py @@ -1,2 +1,2 @@ a, b = map(int, input().split()) -print(a**b+b**a) \ No newline at end of file +print(a**b + b**a) diff --git a/atcoder/abc/abc301-400/abc320/b.py b/atcoder/abc/abc301-400/abc320/b.py index 5d7f1d1b..af0b7f05 100644 --- a/atcoder/abc/abc301-400/abc320/b.py +++ b/atcoder/abc/abc301-400/abc320/b.py @@ -1,8 +1,8 @@ s = list(input()) ans = 0 for i in range(len(s)): - for j in range(i+1, len(s)+1): - si = s[i:j] - if "".join(si) == "".join(list(reversed(si))): - ans = max(ans, len(si)) -print(ans) \ No newline at end of file + for j in range(i + 1, len(s) + 1): + si = s[i:j] + if "".join(si) == "".join(list(reversed(si))): + ans = max(ans, len(si)) +print(ans) diff --git a/atcoder/abc/abc301-400/abc320/c.py b/atcoder/abc/abc301-400/abc320/c.py index 8f27f8e6..5f7ed653 100644 --- a/atcoder/abc/abc301-400/abc320/c.py +++ b/atcoder/abc/abc301-400/abc320/c.py @@ -9,7 +9,14 @@ ans = INF for target_number in range(10): - for first, second, third in [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]: + for first, second, third in [ + [0, 1, 2], + [0, 2, 1], + [1, 0, 2], + [1, 2, 0], + [2, 0, 1], + [2, 1, 0], + ]: num = 0 for t in range(3 * m): if num == 0 and s[first][t] == target_number: @@ -24,4 +31,4 @@ if ans == INF: print(-1) else: - print(ans) \ No newline at end of file + print(ans) diff --git a/atcoder/abc/abc301-400/abc320/d.py b/atcoder/abc/abc301-400/abc320/d.py index 4ec25498..d5072c4c 100644 --- a/atcoder/abc/abc301-400/abc320/d.py +++ b/atcoder/abc/abc301-400/abc320/d.py @@ -1,6 +1,7 @@ from collections import defaultdict, deque -class UnionFind(): + +class UnionFind: def __init__(self, n): self.n = n + 1 self.parents = [-1] * (n + 1) @@ -45,7 +46,8 @@ def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): - return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) + return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) + n, m = map(int, input().split()) uf = UnionFind(n) @@ -75,4 +77,4 @@ def __str__(self): queue.append([next_num, x + next_x, y + next_y]) visited[next_num] = True -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc320/e.py b/atcoder/abc/abc301-400/abc320/e.py index 227ddad3..ef93b7b2 100644 --- a/atcoder/abc/abc301-400/abc320/e.py +++ b/atcoder/abc/abc301-400/abc320/e.py @@ -1,4 +1,5 @@ import heapq + n, m = map(int, input().split()) events = [] diff --git a/atcoder/abc/abc301-400/abc320/f.py b/atcoder/abc/abc301-400/abc320/f.py index 36777497..b67c3c91 100644 --- a/atcoder/abc/abc301-400/abc320/f.py +++ b/atcoder/abc/abc301-400/abc320/f.py @@ -6,4 +6,4 @@ p, f = map(int, input().split()) # DP -# 往路を考えるのだるいので、 \ No newline at end of file +# 往路を考えるのだるいので、 diff --git a/atcoder/abc/abc301-400/abc321/a.py b/atcoder/abc/abc301-400/abc321/a.py index b66b6531..e8988085 100644 --- a/atcoder/abc/abc301-400/abc321/a.py +++ b/atcoder/abc/abc301-400/abc321/a.py @@ -5,11 +5,11 @@ flag = True else: for i in range(len(n) - 1): - if n[i] <= n[i+1]: + if n[i] <= n[i + 1]: flag = False break if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc321/b.py b/atcoder/abc/abc301-400/abc321/b.py index d83495ee..63e27a78 100644 --- a/atcoder/abc/abc301-400/abc321/b.py +++ b/atcoder/abc/abc301-400/abc321/b.py @@ -8,4 +8,4 @@ if sum(sorted_a[1:-1]) >= x: ans = i break -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc321/c.py b/atcoder/abc/abc301-400/abc321/c.py index 68ca9189..5bd434c7 100644 --- a/atcoder/abc/abc301-400/abc321/c.py +++ b/atcoder/abc/abc301-400/abc321/c.py @@ -1,5 +1,6 @@ # 9876543210 が最大 from collections import deque + k = int(input()) que = deque([]) @@ -15,5 +16,5 @@ for i in range(last_num): que.append(nums + [i]) ans = sorted(list(ans))[1:] -print(ans[k-1]) -print(len(ans)) \ No newline at end of file +print(ans[k - 1]) +print(len(ans)) diff --git a/atcoder/abc/abc301-400/abc321/d.py b/atcoder/abc/abc301-400/abc321/d.py index 136f5b8e..d3962b23 100644 --- a/atcoder/abc/abc301-400/abc321/d.py +++ b/atcoder/abc/abc301-400/abc321/d.py @@ -11,6 +11,7 @@ def cumsum(a): r.append(r[-1] + v) return r + # 二部探索をする a = sorted(a) b = sorted(b) diff --git a/atcoder/abc/abc301-400/abc321/e.py b/atcoder/abc/abc301-400/abc321/e.py index 24bd3544..dd082d9f 100644 --- a/atcoder/abc/abc301-400/abc321/e.py +++ b/atcoder/abc/abc301-400/abc321/e.py @@ -1,6 +1,7 @@ -import sys import math +import sys from collections import deque + input = lambda: sys.stdin.readline().rstrip() t = int(input()) @@ -16,9 +17,9 @@ continue ansi = 0 # xの子孫を数える - base = x * (2 ** k) + base = x * (2**k) if base <= n: - ansi += min(n, (base + (2 ** k) - 1)) - base + 1 + ansi += min(n, (base + (2**k) - 1)) - base + 1 que = deque([]) if x // 2 > 0: que = deque([[x, x // 2, k - 1]]) @@ -41,4 +42,4 @@ if parent // 2 > 0: que.append([parent, parent // 2, k - 1]) ans.append(ansi) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc322/a.py b/atcoder/abc/abc301-400/abc322/a.py index 283bfda6..c58ae953 100644 --- a/atcoder/abc/abc301-400/abc322/a.py +++ b/atcoder/abc/abc301-400/abc322/a.py @@ -2,7 +2,7 @@ s = input() for i in range(n - 2): - if s[i:i+3] == "ABC": + if s[i : i + 3] == "ABC": print(i + 1) exit() -print(-1) \ No newline at end of file +print(-1) diff --git a/atcoder/abc/abc301-400/abc322/b.py b/atcoder/abc/abc301-400/abc322/b.py index 9104e4a4..660a5258 100644 --- a/atcoder/abc/abc301-400/abc322/b.py +++ b/atcoder/abc/abc301-400/abc322/b.py @@ -5,9 +5,9 @@ prefix = False suffix = False -if t[:len(s)] == s: +if t[: len(s)] == s: prefix = True -if t[-len(s):] == s: +if t[-len(s) :] == s: suffix = True if prefix and suffix: print(0) @@ -16,4 +16,4 @@ elif suffix: print(2) else: - print(3) \ No newline at end of file + print(3) diff --git a/atcoder/abc/abc301-400/abc322/c.py b/atcoder/abc/abc301-400/abc322/c.py index a52ac269..184cc05c 100644 --- a/atcoder/abc/abc301-400/abc322/c.py +++ b/atcoder/abc/abc301-400/abc322/c.py @@ -1,4 +1,5 @@ from bisect import bisect_left, bisect_right + n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() diff --git a/atcoder/abc/abc301-400/abc322/d.py b/atcoder/abc/abc301-400/abc322/d.py index 060b476c..afd7e9d1 100644 --- a/atcoder/abc/abc301-400/abc322/d.py +++ b/atcoder/abc/abc301-400/abc322/d.py @@ -1,7 +1,8 @@ # 全探索するしかなさそう -import numpy as np from functools import lru_cache +import numpy as np + ps = [] for i in range(3): p = [] @@ -22,18 +23,22 @@ p = np.delete(p, idxs, 1) ps.append(p) + @lru_cache(maxsize=None) def rotate_x(num): return np.rot90(ps[0], num) + @lru_cache(maxsize=None) def rotate_y(num): return np.rot90(ps[1], num) + @lru_cache(maxsize=None) def rotate_z(num): return np.rot90(ps[2], num) + @lru_cache(maxsize=None) def out_of_range(x, y): return x < 0 or x > 3 or y < 0 or y > 3 @@ -108,4 +113,3 @@ def out_of_range(x, y): print("Yes") exit() print("No") - diff --git a/atcoder/abc/abc301-400/abc322/e.py b/atcoder/abc/abc301-400/abc322/e.py index 3ca75979..ef854288 100644 --- a/atcoder/abc/abc301-400/abc322/e.py +++ b/atcoder/abc/abc301-400/abc322/e.py @@ -1,9 +1,10 @@ from collections import defaultdict from copy import deepcopy + MAX_NUM = 5 n, k, p = map(int, input().split()) -INF = 10 ** 18 +INF = 10**18 cas = [] for _ in range(n): c, *a = list(map(int, input().split())) @@ -13,19 +14,20 @@ for i in range(n + 1): dp[i]["_".join(list(map(str, [0] * k)))] = 0 + def value_of_num(num, k, p) -> list: # 数字numのk進数における各桁の値をList[int]で返す ret = [0 for _ in range(p)] for i in range(p): - ret[i] = num // (p ** i) % p + ret[i] = num // (p**i) % p return ret[::-1] + def fix_index(idx, max_value=p): return min(idx, max_value) - + + for i, (c, a) in enumerate(cas): # (p + 1)進数でk桁まで全探索 - for num in range((p + 1)**k): - lists = value_of_num(num, k, p + 1): - - dp[i + 1][] \ No newline at end of file + for num in range((p + 1) ** k): + lists = value_of_num(num, k, p + 1) diff --git a/atcoder/abc/abc301-400/abc322/e_bad.py b/atcoder/abc/abc301-400/abc322/e_bad.py index ed465165..64993316 100644 --- a/atcoder/abc/abc301-400/abc322/e_bad.py +++ b/atcoder/abc/abc301-400/abc322/e_bad.py @@ -1,8 +1,9 @@ import copy + MAX_NUM = 6 n, k, p = map(int, input().split()) -INF = 10 ** 18 +INF = 10**18 cas = [] for _ in range(n): ca = list(map(int, input().split())) @@ -20,13 +21,30 @@ dp = [[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] dp[0][0] = 0 elif k == 3: - dp = [[[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] + dp = [ + [[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM) + ] dp[0][0][0] = 0 elif k == 4: - dp = [[[[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] + dp = [ + [ + [[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] + for _ in range(MAX_NUM) + ] + for _ in range(MAX_NUM) + ] dp[0][0][0][0] = 0 else: - dp = [[[[[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] + dp = [ + [ + [ + [[INF for _ in range(MAX_NUM)] for _ in range(MAX_NUM)] + for _ in range(MAX_NUM) + ] + for _ in range(MAX_NUM) + ] + for _ in range(MAX_NUM) + ] dp[0][0][0][0][0] = 0 for c, a in cas: @@ -48,7 +66,9 @@ idx1 = min(i + a[0], 5) idx2 = min(j + a[1], 5) idx3 = min(ii + a[2], 5) - tmp_dp[idx1][idx2][idx3] = min(tmp_dp[idx1][idx2][idx3], dp[i][j][ii] + c) + tmp_dp[idx1][idx2][idx3] = min( + tmp_dp[idx1][idx2][idx3], dp[i][j][ii] + c + ) elif k == 4: for i in range(6): for j in range(6): @@ -58,7 +78,9 @@ idx2 = min(j + a[1], 5) idx3 = min(ii + a[2], 5) idx4 = min(jj + a[3], 5) - tmp_dp[idx1][idx2][idx3][idx4] = min(tmp_dp[idx1][idx2][idx3][idx4], dp[i][j][ii][jj] + c) + tmp_dp[idx1][idx2][idx3][idx4] = min( + tmp_dp[idx1][idx2][idx3][idx4], dp[i][j][ii][jj] + c + ) else: for i in range(6): for j in range(6): @@ -70,7 +92,10 @@ idx3 = min(ii + a[2], 5) idx4 = min(jj + a[3], 5) idx5 = min(kk + a[4], 5) - tmp_dp[idx1][idx2][idx3][idx4][idx5] = min(tmp_dp[idx1][idx2][idx3][idx4][idx5], dp[i][j][ii][jj][kk] + c) + tmp_dp[idx1][idx2][idx3][idx4][idx5] = min( + tmp_dp[idx1][idx2][idx3][idx4][idx5], + dp[i][j][ii][jj][kk] + c, + ) dp = tmp_dp ans = -1 @@ -119,4 +144,4 @@ ans = dp[i][j][ii][jj][kk] else: ans = min(ans, dp[i][j][ii][jj][kk]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc322/f.py b/atcoder/abc/abc301-400/abc322/f.py index 16eaf134..d2da51f5 100644 --- a/atcoder/abc/abc301-400/abc322/f.py +++ b/atcoder/abc/abc301-400/abc322/f.py @@ -11,12 +11,13 @@ # c: 2 -> l~rの間の連続する1の最大の長さを求める # セグ木 + class SegTree: def __init__(self, n: int, mode: str = "max") -> None: self.mode = mode unit_elements = { - "min": 10 ** 13, - "max": -(10 ** 13), + "min": 10**13, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, @@ -26,7 +27,7 @@ def __init__(self, n: int, mode: str = "max") -> None: self.tree_value = [self.e] * 2 * self.tree_size def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 @@ -105,6 +106,7 @@ def query(self, l: int, r: int) -> int: res = self._op(self._op(res, self.tree_value[l]), self.tree_value[r]) return res + ans = [] for c, l, r in queries: if c == 1: @@ -125,5 +127,3 @@ def query(self, l: int, r: int) -> int: ret = max(ret, cnt) ans.append(ret) print(*ans, sep="\n") - - diff --git a/atcoder/abc/abc301-400/abc323/a.py b/atcoder/abc/abc301-400/abc323/a.py index 260d677c..1043bdd6 100644 --- a/atcoder/abc/abc301-400/abc323/a.py +++ b/atcoder/abc/abc301-400/abc323/a.py @@ -10,4 +10,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc323/b.py b/atcoder/abc/abc301-400/abc323/b.py index d99e32de..2e700867 100644 --- a/atcoder/abc/abc301-400/abc323/b.py +++ b/atcoder/abc/abc301-400/abc323/b.py @@ -1,4 +1,5 @@ from collections import defaultdict + n = int(input()) counter = defaultdict(int) for i in range(n): @@ -10,4 +11,4 @@ counter[i + 1] += 0 ans = sorted([[v, k] for k, v in counter.items()], key=lambda x: [-x[0], x[1]]) -print(*[y for x, y in ans], sep=" ") \ No newline at end of file +print(*[y for x, y in ans], sep=" ") diff --git a/atcoder/abc/abc301-400/abc323/c.py b/atcoder/abc/abc301-400/abc323/c.py index 55ffa679..26c75e99 100644 --- a/atcoder/abc/abc301-400/abc323/c.py +++ b/atcoder/abc/abc301-400/abc323/c.py @@ -1,6 +1,6 @@ from collections import defaultdict -INF = 10 ** 18 +INF = 10**18 MAX_VALUE = 250002 n, m = map(int, input().split()) diff --git a/atcoder/abc/abc301-400/abc323/d.py b/atcoder/abc/abc301-400/abc323/d.py index 624e3edd..6b6be8e7 100644 --- a/atcoder/abc/abc301-400/abc323/d.py +++ b/atcoder/abc/abc301-400/abc323/d.py @@ -1,6 +1,7 @@ import sys from collections import defaultdict -from heapq import heappop, heappush, heapify +from heapq import heapify, heappop, heappush + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) diff --git a/atcoder/abc/abc301-400/abc323/e.py b/atcoder/abc/abc301-400/abc323/e.py index 521676c6..54d434f4 100644 --- a/atcoder/abc/abc301-400/abc323/e.py +++ b/atcoder/abc/abc301-400/abc323/e.py @@ -3,6 +3,7 @@ n, x = map(int, input().split()) t = list(map(int, input().split())) + class FLT: """ フェルマーの小定理 @@ -22,9 +23,10 @@ def rep_sqr(self, base: int, k: int) -> int: return ans def inv(self, a: int) -> int: - """ 逆元を取る """ + """逆元を取る""" return self.rep_sqr(a, self.mod - 2) + flt = FLT(MOD) inv_n = flt.inv(n) ans = 0 @@ -47,4 +49,3 @@ def inv(self, a: int) -> int: ans %= MOD # print(dp) print(ans) - diff --git a/atcoder/abc/abc301-400/abc323/f.py b/atcoder/abc/abc301-400/abc323/f.py index c8805ad1..a9aa9c8b 100644 --- a/atcoder/abc/abc301-400/abc323/f.py +++ b/atcoder/abc/abc301-400/abc323/f.py @@ -1,11 +1,13 @@ -INF = 10 ** 18 +INF = 10**18 xa, ya, xb, yb, xc, yc = map(int, input().split()) # 荷物から目的地の方向を求める # 横方向から押すパターンと縦方向から押すパターンを考える + def manhattan_distance(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) + to_push = [yc - yb, xc - xb] # [上に押す距離, 右に押す距離] # print(to_push) @@ -103,4 +105,3 @@ def manhattan_distance(x1, y1, x2, y2): # print(to_push) # print(cost1, cost2) print(min([cost1, cost2])) - diff --git a/atcoder/abc/abc301-400/abc324/a.py b/atcoder/abc/abc301-400/abc324/a.py index c212c50c..80d00b32 100644 --- a/atcoder/abc/abc301-400/abc324/a.py +++ b/atcoder/abc/abc301-400/abc324/a.py @@ -12,4 +12,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc324/b.py b/atcoder/abc/abc301-400/abc324/b.py index 9a345b03..29b49c80 100644 --- a/atcoder/abc/abc301-400/abc324/b.py +++ b/atcoder/abc/abc301-400/abc324/b.py @@ -2,11 +2,11 @@ for x in range(70): for y in range(40): - if 3 ** y > n: + if 3**y > n: break if 2**x * 3**y == n: print("Yes") exit() - if 2 **x > n: + if 2**x > n: break -print("No") \ No newline at end of file +print("No") diff --git a/atcoder/abc/abc301-400/abc324/c.py b/atcoder/abc/abc301-400/abc324/c.py index 66f3e0b6..4ceb79c3 100644 --- a/atcoder/abc/abc301-400/abc324/c.py +++ b/atcoder/abc/abc301-400/abc324/c.py @@ -1,8 +1,10 @@ from collections import deque + n, t = input().split() n = int(n) s = [input() for _ in range(n)] + def create_correct_set(t): correct_set = set() # 1 @@ -11,18 +13,18 @@ def create_correct_set(t): # 2 for pos in range(n + 1): for alph in range(26): - correct_set.add(t[:pos] + chr(ord('a') + alph) + t[pos:]) + correct_set.add(t[:pos] + chr(ord("a") + alph) + t[pos:]) # 3 for pos in range(n): # O(n**2) - correct_set.add(t[:pos] + t[pos + 1:]) + correct_set.add(t[:pos] + t[pos + 1 :]) # 4 for pos in range(n): for alph in range(26): # O(n**2) - correct_set.add(t[:pos] + chr(ord('a') + alph) + t[pos + 1:]) + correct_set.add(t[:pos] + chr(ord("a") + alph) + t[pos + 1 :]) return correct_set @@ -34,6 +36,7 @@ def solve1(n, t, s): ans.append(i + 1) return ans + def leavenshtain_distance(s1, s2): cnt = 0 for si1, si2 in zip(s1, s2): @@ -41,6 +44,7 @@ def leavenshtain_distance(s1, s2): cnt += 1 return cnt + def solve2(n, t, s): # 都度確認する # まずあり得る長さはt+-1 @@ -109,7 +113,8 @@ def solve2(n, t, s): continue return ans + # ans = solve1(n, t, s) ans = solve2(n, t, s) print(len(ans)) -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc301-400/abc324/d.py b/atcoder/abc/abc301-400/abc324/d.py index 185be76a..9a4a4847 100644 --- a/atcoder/abc/abc301-400/abc324/d.py +++ b/atcoder/abc/abc301-400/abc324/d.py @@ -1,7 +1,9 @@ from collections import defaultdict + n = int(input()) s = int(input()) + def norm_for_s(s): zeropad_si = str(s).zfill(n) ll = list(zeropad_si) @@ -10,10 +12,11 @@ def norm_for_s(s): counter[int(l)] += 1 return counter + normed_s = norm_for_s(s) ans = 0 -for i in range(10 ** 7 + 1): +for i in range(10**7 + 1): if i * i > 10 ** (n + 1): break si = str(i * i).zfill(n) diff --git a/atcoder/abc/abc301-400/abc324/e.py b/atcoder/abc/abc301-400/abc324/e.py index f974f0b6..37f807e2 100644 --- a/atcoder/abc/abc301-400/abc324/e.py +++ b/atcoder/abc/abc301-400/abc324/e.py @@ -45,6 +45,6 @@ # 分割位置を全探索 ans = 0 for i in range(len(t) + 1): - ans += (counter[i] * rev_counter[len(t) - i]) + ans += counter[i] * rev_counter[len(t) - i] -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc324/f.py b/atcoder/abc/abc301-400/abc324/f.py index 9d6a38d3..af139dde 100644 --- a/atcoder/abc/abc301-400/abc324/f.py +++ b/atcoder/abc/abc301-400/abc324/f.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -8,5 +9,3 @@ for _ in range(m): u, v, b, c = map(int, input().split()) uvbc.append((u, v, b, c)) - - diff --git a/atcoder/abc/abc301-400/abc325/a.py b/atcoder/abc/abc301-400/abc325/a.py index 02c57af3..002d502a 100644 --- a/atcoder/abc/abc301-400/abc325/a.py +++ b/atcoder/abc/abc301-400/abc325/a.py @@ -1,2 +1,2 @@ s, t = input().split() -print(f"{s} san") \ No newline at end of file +print(f"{s} san") diff --git a/atcoder/abc/abc301-400/abc325/b.py b/atcoder/abc/abc301-400/abc325/b.py index e669669e..36ef91db 100644 --- a/atcoder/abc/abc301-400/abc325/b.py +++ b/atcoder/abc/abc301-400/abc325/b.py @@ -1,9 +1,11 @@ n = int(input()) wx = [] + def ok(time): return 9 <= time and time <= 17 + for _ in range(n): w, x = map(int, input().split()) wx.append((w, x)) @@ -15,4 +17,4 @@ def ok(time): if ok((x + t) % 24): count += w ans = max(ans, count) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc325/c.py b/atcoder/abc/abc301-400/abc325/c.py index 4087e5a4..2d4b0174 100644 --- a/atcoder/abc/abc301-400/abc325/c.py +++ b/atcoder/abc/abc301-400/abc325/c.py @@ -1,5 +1,6 @@ import sys from collections import deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) DXY = [(1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, 1), (1, -1), (-1, -1)] diff --git a/atcoder/abc/abc301-400/abc325/d.py b/atcoder/abc/abc301-400/abc325/d.py index b1b6b507..4df0df4c 100644 --- a/atcoder/abc/abc301-400/abc325/d.py +++ b/atcoder/abc/abc301-400/abc325/d.py @@ -1,5 +1,6 @@ import heapq from collections import deque + n = int(input()) td = [] @@ -40,4 +41,4 @@ else: break -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc325/e.py b/atcoder/abc/abc301-400/abc325/e.py index 56f0f98f..170ad2d0 100644 --- a/atcoder/abc/abc301-400/abc325/e.py +++ b/atcoder/abc/abc301-400/abc325/e.py @@ -1,6 +1,7 @@ import heapq from collections import defaultdict -INF = float('inf') + +INF = float("inf") n, a, b, c = map(int, input().split()) d = [] @@ -33,7 +34,7 @@ costs[w] = min(costs[w], cost + d[v][w] * a) heapq.heappush(que, [cost + d[v][w] * a, w]) -que = [[0, n-1]] +que = [[0, n - 1]] visited = defaultdict(lambda: False) costs = [INF for _ in range(n)] while que: @@ -55,4 +56,4 @@ for i in range(n): ans = min(ans, from_one[i] + from_n[i]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc326/a.py b/atcoder/abc/abc301-400/abc326/a.py index 2ef7b570..89edf39d 100644 --- a/atcoder/abc/abc301-400/abc326/a.py +++ b/atcoder/abc/abc301-400/abc326/a.py @@ -3,4 +3,4 @@ if (a > 0 and a <= 3) or (a < 0 and a >= -2): print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc326/b.py b/atcoder/abc/abc301-400/abc326/b.py index f35507c3..f72942a1 100644 --- a/atcoder/abc/abc301-400/abc326/b.py +++ b/atcoder/abc/abc301-400/abc326/b.py @@ -6,4 +6,4 @@ if len(num_str) == 3: if int(num_str[0]) * int(num_str[1]) == int(num_str[2]): ans = min(ans, num) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc326/c.py b/atcoder/abc/abc301-400/abc326/c.py index 1ffe6b61..b083a34b 100644 --- a/atcoder/abc/abc301-400/abc326/c.py +++ b/atcoder/abc/abc301-400/abc326/c.py @@ -1,4 +1,5 @@ import bisect + n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() @@ -8,4 +9,4 @@ ai = a[i] j = bisect.bisect_left(a, ai + m) ans = max(ans, j - i) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc326/d.py b/atcoder/abc/abc301-400/abc326/d.py index bdff47d6..63456287 100644 --- a/atcoder/abc/abc301-400/abc326/d.py +++ b/atcoder/abc/abc301-400/abc326/d.py @@ -5,6 +5,7 @@ R = list(input()) C = list(input()) + def first(a, b, c): min_value = min(a, b, c) if min_value == a: @@ -14,6 +15,7 @@ def first(a, b, c): else: return "C" + def check_abc(a, b, c): # 衝突してないか for i in range(n): @@ -40,6 +42,7 @@ def check_abc(a, b, c): return False return True + def show_abc(a, b, c): out = [["." for _ in range(n)] for _ in range(n)] for i in range(n): @@ -48,10 +51,11 @@ def show_abc(a, b, c): out[i][c[i]] = "C" return "Yes\n" + "\n".join(["".join(row) for row in out]) + # 賢く全探索 abc_list = list(range(n)) for a, b, c in itertools.product(itertools.permutations(abc_list), repeat=3): if check_abc(a, b, c): print(show_abc(a, b, c)) exit() -print("No") \ No newline at end of file +print("No") diff --git a/atcoder/abc/abc301-400/abc326/e.py b/atcoder/abc/abc301-400/abc326/e.py index 5d965c70..f15596ce 100644 --- a/atcoder/abc/abc301-400/abc326/e.py +++ b/atcoder/abc/abc301-400/abc326/e.py @@ -1,10 +1,11 @@ import sys + input = lambda: sys.stdin.readline().rstrip() MOD = 998244353 n = int(input()) a = list(map(int, input().split())) -inv_n = pow(n, MOD - 2, MOD) # 1/nをあらかじめ計算しておく +inv_n = pow(n, MOD - 2, MOD) # 1/nをあらかじめ計算しておく memo = [0 for _ in range(n + 1)] stuck = 0 @@ -21,4 +22,4 @@ for i in reversed(range(1, n + 1)): ans += memo[i] * inv_n ans %= MOD -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc326/f.py b/atcoder/abc/abc301-400/abc326/f.py index f35fbb59..51d4aa74 100644 --- a/atcoder/abc/abc301-400/abc326/f.py +++ b/atcoder/abc/abc301-400/abc326/f.py @@ -1,4 +1,5 @@ from collections import deque + n, x, y = map(int, input().split()) a = list(map(int, input().split())) @@ -12,14 +13,15 @@ print("R") exit() + def solve_half(ax, target_x): # 半分全列挙して可能かどうかを判定する # 不可能な場合は空行列 # 可能な場合は正負のリストを返す(0: 負, 1: 正) - halfs = [ax[:len(ax) // 2], ax[len(ax) // 2:]] + halfs = [ax[: len(ax) // 2], ax[len(ax) // 2 :]] values = [dict(), dict()] for i, half in enumerate(halfs): - que = deque([[0, 0, 0]]) # [value, path] + que = deque([[0, 0, 0]]) # [value, path] while que: value, depth, path = que.popleft() if depth == len(half): @@ -59,6 +61,7 @@ def solve_half(ax, target_x): return path return [] + # 4分割して半分全列挙 def solve(a): ay = a[::2] @@ -71,7 +74,7 @@ def solve(a): return ans = [] - direction = 0 # 0: x正, 1: x負, 2: y正, 3: y負 + direction = 0 # 0: x正, 1: x負, 2: y正, 3: y負 while path_y or path_x: if path_y: d = path_y.popleft() @@ -105,9 +108,7 @@ def solve(a): print("".join(ans)) return + solve(a) # 奇数回目の操作でy方向に動く # 偶数回目の操作でx方向に動く - - - diff --git a/atcoder/abc/abc301-400/abc326/g.py b/atcoder/abc/abc301-400/abc326/g.py index ef0e1b8f..e77a2b81 100644 --- a/atcoder/abc/abc301-400/abc326/g.py +++ b/atcoder/abc/abc301-400/abc326/g.py @@ -1,2 +1,2 @@ n = int(input()) -a = list(map(int, input().split())) \ No newline at end of file +a = list(map(int, input().split())) diff --git a/atcoder/abc/abc301-400/abc327/a.py b/atcoder/abc/abc301-400/abc327/a.py index 5660b9cf..e68184b3 100644 --- a/atcoder/abc/abc301-400/abc327/a.py +++ b/atcoder/abc/abc301-400/abc327/a.py @@ -5,4 +5,4 @@ if set([s[i - 1], s[i]]) == set(["a", "b"]): print("Yes") exit() -print("No") \ No newline at end of file +print("No") diff --git a/atcoder/abc/abc301-400/abc327/b.py b/atcoder/abc/abc301-400/abc327/b.py index 08d58dae..9a71a1b4 100644 --- a/atcoder/abc/abc301-400/abc327/b.py +++ b/atcoder/abc/abc301-400/abc327/b.py @@ -1,9 +1,9 @@ b = int(input()) for i in range(1, 10**6 + 1): - if i ** i > b: + if i**i > b: break - if i ** i == b: + if i**i == b: print(i) exit() -print(-1) \ No newline at end of file +print(-1) diff --git a/atcoder/abc/abc301-400/abc327/c.py b/atcoder/abc/abc301-400/abc327/c.py index 6b6ee0c3..a5954e3b 100644 --- a/atcoder/abc/abc301-400/abc327/c.py +++ b/atcoder/abc/abc301-400/abc327/c.py @@ -30,4 +30,4 @@ if flag: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc327/d.py b/atcoder/abc/abc301-400/abc327/d.py index 70a5e6fa..62f3bb07 100644 --- a/atcoder/abc/abc301-400/abc327/d.py +++ b/atcoder/abc/abc301-400/abc327/d.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) @@ -41,4 +42,4 @@ elif node_num[j] != next_num: print("No") exit() -print("Yes") \ No newline at end of file +print("Yes") diff --git a/atcoder/abc/abc301-400/abc327/e.py b/atcoder/abc/abc301-400/abc327/e.py index a6b67e10..54070a8f 100644 --- a/atcoder/abc/abc301-400/abc327/e.py +++ b/atcoder/abc/abc301-400/abc327/e.py @@ -41,4 +41,4 @@ for i in range(len(dp)): for j in range(len(dp[i])): ans = max(ans, dp[i][j]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc327/f.py b/atcoder/abc/abc301-400/abc327/f.py index 65918424..5857cb0d 100644 --- a/atcoder/abc/abc301-400/abc327/f.py +++ b/atcoder/abc/abc301-400/abc327/f.py @@ -6,4 +6,3 @@ tx.append((t, x)) tx.sort() - diff --git a/atcoder/abc/abc301-400/abc328/a.py b/atcoder/abc/abc301-400/abc328/a.py index 83785f9a..90ce27c1 100644 --- a/atcoder/abc/abc301-400/abc328/a.py +++ b/atcoder/abc/abc301-400/abc328/a.py @@ -5,4 +5,4 @@ for si in s: if si <= x: ans += si -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc328/b.py b/atcoder/abc/abc301-400/abc328/b.py index 3f0ef5d1..2bd6a3e4 100644 --- a/atcoder/abc/abc301-400/abc328/b.py +++ b/atcoder/abc/abc301-400/abc328/b.py @@ -9,4 +9,4 @@ md_set = set(list(str(m)) + list(str(di))) if len(md_set) == 1: ans += 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc328/c.py b/atcoder/abc/abc301-400/abc328/c.py index 5419ebf7..1df25bae 100644 --- a/atcoder/abc/abc301-400/abc328/c.py +++ b/atcoder/abc/abc301-400/abc328/c.py @@ -13,6 +13,8 @@ def cumsum(a): for v in a: r.append(r[-1] + v) return r + + cum = cumsum(ren) ans = [] diff --git a/atcoder/abc/abc301-400/abc328/d.py b/atcoder/abc/abc301-400/abc328/d.py index f5766bad..93076144 100644 --- a/atcoder/abc/abc301-400/abc328/d.py +++ b/atcoder/abc/abc301-400/abc328/d.py @@ -1,4 +1,5 @@ from collections import deque + s = list(input()) # Aで下げる q = deque([]) diff --git a/atcoder/abc/abc301-400/abc328/e.py b/atcoder/abc/abc301-400/abc328/e.py index 655b1f88..bbb0db92 100644 --- a/atcoder/abc/abc301-400/abc328/e.py +++ b/atcoder/abc/abc301-400/abc328/e.py @@ -1,8 +1,10 @@ -from collections import defaultdict, deque import itertools +from collections import defaultdict, deque + INF = float("inf") -class UnionFind(): + +class UnionFind: def __init__(self, n): self.n = n + 1 self.parents = [-1] * (n + 1) @@ -47,7 +49,7 @@ def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): - return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) + return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) n, m, k = map(int, input().split()) @@ -75,4 +77,4 @@ def __str__(self): if flag: ans = min(ans, cost) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc328/f.py b/atcoder/abc/abc301-400/abc328/f.py index ab33c570..58085c8b 100644 --- a/atcoder/abc/abc301-400/abc328/f.py +++ b/atcoder/abc/abc301-400/abc328/f.py @@ -1,5 +1,8 @@ from collections import defaultdict + INF = float("inf") + + class WeightedUnionFind: def __init__(self, n: int) -> None: self.par = [i for i in range(n + 1)] @@ -44,6 +47,7 @@ def diff(self, x: int, y: int) -> int: return -INF # コスト算出不可 return self.weight[x] - self.weight[y] + n, q = map(int, input().split()) abd = [] diff --git a/atcoder/abc/abc301-400/abc328/g.py b/atcoder/abc/abc301-400/abc328/g.py index 52f0af37..ab3d622a 100644 --- a/atcoder/abc/abc301-400/abc328/g.py +++ b/atcoder/abc/abc301-400/abc328/g.py @@ -1,16 +1,19 @@ from collections import defaultdict, deque + INF = float("inf") n, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) + def cost_k(a): cost = 0 for i in range(n): cost += abs(a[i] - b[i]) return cost + # dp[i][j]: 集合iを使ってjが最後の時の最小コスト dp = defaultdict(lambda: defaultdict(lambda: INF)) # dp = [[INF] * n for _ in range(2**n)] @@ -33,11 +36,17 @@ def cost_k(a): continue next_si = si | 1 << next_num if next_num == last_num + 1: - dp[next_si][next_num] = min(dp[next_si][next_num], dp[si][last_num] + abs(b[bit_count] - a[next_num])) + dp[next_si][next_num] = min( + dp[next_si][next_num], + dp[si][last_num] + abs(b[bit_count] - a[next_num]), + ) else: - dp[next_si][next_num] = min(dp[next_si][next_num], dp[si][last_num] + abs(b[bit_count] - a[next_num]) + c) + dp[next_si][next_num] = min( + dp[next_si][next_num], + dp[si][last_num] + abs(b[bit_count] - a[next_num]) + c, + ) for i in range(n): ans = min(ans, dp[2**n - 1][i]) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc329/a.py b/atcoder/abc/abc301-400/abc329/a.py index de510199..3c667cee 100644 --- a/atcoder/abc/abc301-400/abc329/a.py +++ b/atcoder/abc/abc301-400/abc329/a.py @@ -1,2 +1,2 @@ s = list(input()) -print(*s, sep=" ") \ No newline at end of file +print(*s, sep=" ") diff --git a/atcoder/abc/abc301-400/abc329/b.py b/atcoder/abc/abc301-400/abc329/b.py index 779222c2..241f6e31 100644 --- a/atcoder/abc/abc301-400/abc329/b.py +++ b/atcoder/abc/abc301-400/abc329/b.py @@ -8,4 +8,4 @@ if ai == max_a: continue ans = max(ans, ai) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc329/c.py b/atcoder/abc/abc301-400/abc329/c.py index f72a123f..82a8da73 100644 --- a/atcoder/abc/abc301-400/abc329/c.py +++ b/atcoder/abc/abc301-400/abc329/c.py @@ -1,4 +1,5 @@ from collections import defaultdict + n = int(input()) s = list(input()) @@ -18,4 +19,4 @@ for k, v in counter.items(): ans += v -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc329/d.py b/atcoder/abc/abc301-400/abc329/d.py index dc0c93c2..3ec7bd14 100644 --- a/atcoder/abc/abc301-400/abc329/d.py +++ b/atcoder/abc/abc301-400/abc329/d.py @@ -5,10 +5,12 @@ n, m = map(int, input().split()) a = list(map(int, input().split())) + def calc_value(person_num, value): # 同着の場合に若い番号を優先する return value * MAX_N + (MAX_N - person_num) + queue = [] heapq.heapify(queue) diff --git a/atcoder/abc/abc301-400/abc329/e.py b/atcoder/abc/abc301-400/abc329/e.py index 874e25a8..01b4116f 100644 --- a/atcoder/abc/abc301-400/abc329/e.py +++ b/atcoder/abc/abc301-400/abc329/e.py @@ -1,4 +1,5 @@ from collections import deque + n, m = map(int, input().split()) s = list(input()) t = input() @@ -7,24 +8,28 @@ for left_i in range(m): for right_i in range(m - left_i + 1): - t_set.add("#" * left_i + t[left_i:left_i + right_i] + "#" * (m - left_i - right_i)) + t_set.add( + "#" * left_i + t[left_i : left_i + right_i] + "#" * (m - left_i - right_i) + ) t_set.discard("#" * m) + def all_sharp(s): for i in range(len(s)): if s[i] != "#": return False return True + queue = deque() for start_i in range(len(s) - len(t) + 1): - if "".join(s[start_i:start_i + len(t)]) in t_set: + if "".join(s[start_i : start_i + len(t)]) in t_set: queue.append((start_i)) while True: count = 0 for start_i in range(len(s) - len(t) + 1): - if "".join(s[start_i:start_i + len(t)]) in t_set: + if "".join(s[start_i : start_i + len(t)]) in t_set: for j in range(start_i, start_i + len(t)): s[j] = "#" count += 1 @@ -45,4 +50,4 @@ def all_sharp(s): if all_sharp(s): print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc329/f.py b/atcoder/abc/abc301-400/abc329/f.py index 75d06466..b868f91c 100644 --- a/atcoder/abc/abc301-400/abc329/f.py +++ b/atcoder/abc/abc301-400/abc329/f.py @@ -1,5 +1,6 @@ import sys from collections import defaultdict + input = lambda: sys.stdin.readline().rstrip() n, q = map(int, input().split()) @@ -22,4 +23,4 @@ boxes[b] = boxes[a] boxes[a] = set() ans.append(len(boxes[b])) -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc330/a.py b/atcoder/abc/abc301-400/abc330/a.py index f681fbd8..62f9e864 100644 --- a/atcoder/abc/abc301-400/abc330/a.py +++ b/atcoder/abc/abc301-400/abc330/a.py @@ -6,4 +6,4 @@ for ai in a: if ai >= l: ans += 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc330/c.py b/atcoder/abc/abc301-400/abc330/c.py index d2992925..ed41667a 100644 --- a/atcoder/abc/abc301-400/abc330/c.py +++ b/atcoder/abc/abc301-400/abc330/c.py @@ -1,4 +1,5 @@ from math import sqrt + d = int(input()) heiho = [] @@ -24,4 +25,4 @@ l = mid ans = min(ans, abs(ansi - heiho[l])) ans = min(ans, abs(ansi - heiho[r])) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc330/d.py b/atcoder/abc/abc301-400/abc330/d.py index 9a2a9bb8..c24ab6a4 100644 --- a/atcoder/abc/abc301-400/abc330/d.py +++ b/atcoder/abc/abc301-400/abc330/d.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n = int(input()) s = [list(input()) for _ in range(n)] diff --git a/atcoder/abc/abc301-400/abc330/e.py b/atcoder/abc/abc301-400/abc330/e.py index 21eeac06..3f62eb8d 100644 --- a/atcoder/abc/abc301-400/abc330/e.py +++ b/atcoder/abc/abc301-400/abc330/e.py @@ -9,6 +9,7 @@ i, x = map(int, input().split()) ix.append((i, x)) + class MultiSet: def __init__(self) -> None: self.cnt_dict = defaultdict(int) @@ -45,6 +46,7 @@ def get_min(self) -> int: def include(self, num: int) -> bool: return self.cnt_dict.get(num, 0) > 0 + multiset = MultiSet() for ai in a: multiset.add(ai) diff --git a/atcoder/abc/abc301-400/abc330/f copy.py b/atcoder/abc/abc301-400/abc330/f copy.py index b2f91455..9d6bd55b 100644 --- a/atcoder/abc/abc301-400/abc330/f copy.py +++ b/atcoder/abc/abc301-400/abc330/f copy.py @@ -1,4 +1,5 @@ from collections import defaultdict + INF = float("inf") n, k = map(int, input().split()) xy = [] @@ -26,7 +27,7 @@ # dxyiのうち最もコスト消費が少なく小さくできるものを選択しつづける if positions[0] == positions[2]: break - next_dxy = [INF, -1] # (cost, dx, dy) + next_dxy = [INF, -1] # (cost, dx, dy) for i, (dx, dy) in enumerate(dxy): cost = 0 if dx % 2 == 0: @@ -79,4 +80,4 @@ counter["x"][positions[0]] = 0 positions[3] -= 1 positions[0] += 1 -print(positions[2] - positions[0]) \ No newline at end of file +print(positions[2] - positions[0]) diff --git a/atcoder/abc/abc301-400/abc330/f.py b/atcoder/abc/abc301-400/abc330/f.py index 1f486ef2..1612809c 100644 --- a/atcoder/abc/abc301-400/abc330/f.py +++ b/atcoder/abc/abc301-400/abc330/f.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + INF = float("inf") n, k = map(int, input().split()) xy = [] @@ -11,7 +12,7 @@ # 作成可能な正方形の辺の長さを2分探索する l = -1 -r = 10 ** 10 + 1 +r = 10**10 + 1 # queueに入ったデータの両端の差をvalueにする def calc_cost(value, queue): @@ -46,6 +47,7 @@ def calc_cost(value, queue): cost += cost2 return cost, left, right + def judge(value, max_cost): x_queue = [] y_queue = [] @@ -56,9 +58,16 @@ def judge(value, max_cost): y_queue = deque(list(sorted(y_queue))) cost_x, left_x, right_x = calc_cost(value, x_queue) cost_y, left_y, right_y = calc_cost(value, y_queue) - print(value, cost_x + cost_y, (k - (cost_x + cost_y)), right_x - left_x, right_y - left_y) + print( + value, + cost_x + cost_y, + (k - (cost_x + cost_y)), + right_x - left_x, + right_y - left_y, + ) return cost_x + cost_y <= max_cost + while r - l > 1: mid = (r + l) // 2 if judge(mid, k): @@ -66,4 +75,3 @@ def judge(value, max_cost): else: l = mid print(l, r) - diff --git a/atcoder/abc/abc301-400/abc331/a.py b/atcoder/abc/abc301-400/abc331/a.py index a5ba7d1a..099ee311 100644 --- a/atcoder/abc/abc301-400/abc331/a.py +++ b/atcoder/abc/abc301-400/abc331/a.py @@ -9,4 +9,4 @@ y += 1 m = 1 -print(y, m, d) \ No newline at end of file +print(y, m, d) diff --git a/atcoder/abc/abc301-400/abc331/b.py b/atcoder/abc/abc301-400/abc331/b.py index b6dfaa55..57d5fd1a 100644 --- a/atcoder/abc/abc301-400/abc331/b.py +++ b/atcoder/abc/abc301-400/abc331/b.py @@ -2,8 +2,8 @@ INF = float("inf") ans = INF for i in range(20): - for j in range(20): - for k in range(20): - if (i * 6) + (j * 8) + (12 * k) >= n: - ans = min(ans, i * s + j * m + k * l) -print(ans) \ No newline at end of file + for j in range(20): + for k in range(20): + if (i * 6) + (j * 8) + (12 * k) >= n: + ans = min(ans, i * s + j * m + k * l) +print(ans) diff --git a/atcoder/abc/abc301-400/abc331/b_dp1.py b/atcoder/abc/abc301-400/abc331/b_dp1.py index 0c815aa9..d4e353c8 100644 --- a/atcoder/abc/abc301-400/abc331/b_dp1.py +++ b/atcoder/abc/abc301-400/abc331/b_dp1.py @@ -1,7 +1,7 @@ n, s, m, l = map(int, input().split()) -INF = float('inf') +INF = float("inf") # dp[i]: i個の卵を買うのにかかる最小の金額 -dp = [INF] * (n + 13) # 12個が最大なので +dp = [INF] * (n + 13) # 12個が最大なので dp[0] = 0 # 貰うDP @@ -13,4 +13,4 @@ if i - 12 >= 0: dp[i] = min(dp[i], dp[i - 12] + l) -print(min(dp[n:])) \ No newline at end of file +print(min(dp[n:])) diff --git a/atcoder/abc/abc301-400/abc331/c.py b/atcoder/abc/abc301-400/abc331/c.py index 946f1df0..87ff0321 100644 --- a/atcoder/abc/abc301-400/abc331/c.py +++ b/atcoder/abc/abc301-400/abc331/c.py @@ -1,20 +1,21 @@ from collections import defaultdict + n = int(input()) a = list(map(int, input().split())) sum_a = sum(a) counter = defaultdict(int) for ai in a: - counter[ai] += 1 + counter[ai] += 1 uniq_a = list(sorted(list(set(a)))) ans = defaultdict(int) for ai in uniq_a: - sum_a -= (ai * counter[ai]) - ans[ai] = sum_a + sum_a -= ai * counter[ai] + ans[ai] = sum_a out = [] for ai in a: - out.append(ans[ai]) + out.append(ans[ai]) print(*out, sep=" ") diff --git a/atcoder/abc/abc301-400/abc331/d.py b/atcoder/abc/abc301-400/abc331/d.py index 5c8a0810..e67b210a 100644 --- a/atcoder/abc/abc301-400/abc331/d.py +++ b/atcoder/abc/abc301-400/abc331/d.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -7,51 +8,53 @@ queries = [] for _ in range(q): - query = list(map(int, input().split())) - queries.append(query) + query = list(map(int, input().split())) + queries.append(query) # B -> 1, W -> 0 p = [[1 if p[i][j] == "B" else 0 for j in range(n)] for i in range(n)] # 2N * 2Nに拡張 tmp_p = [[0 for _ in range(2 * n)] for _ in range(2 * n)] for i in range(n): - for j in range(n): - tmp_p[i][j] = p[i][j] - tmp_p[i + n][j] = p[i][j] - tmp_p[i][j + n] = p[i][j] - tmp_p[i + n][j + n] = p[i][j] + for j in range(n): + tmp_p[i][j] = p[i][j] + tmp_p[i + n][j] = p[i][j] + tmp_p[i][j + n] = p[i][j] + tmp_p[i + n][j + n] = p[i][j] p = tmp_p # 2次元imos法 imos = [[0 for _ in range(2 * n + 1)] for _ in range(2 * n + 1)] -for i in range(2*n): - for j in range(2*n): - imos[i + 1][j + 1] = p[i][j] + imos[i + 1][j] + imos[i][j + 1] - imos[i][j] +for i in range(2 * n): + for j in range(2 * n): + imos[i + 1][j + 1] = p[i][j] + imos[i + 1][j] + imos[i][j + 1] - imos[i][j] + def solve_query(query): - x1, y1, x2, y2 = query - # 基準点を(0, 0)にする - mod_x1 = x1 % n - mod_y1 = y1 % n - x2 = x2 - x1 + mod_x1 - y2 = y2 - y1 + mod_y1 - x1 = mod_x1 - y1 = mod_y1 - # 4つの領域に分ける - y_max = y2 + (n - (y2 % n)) - x_max = x2 + (n - (x2 % n)) - ret = 0 - - # 4隅 - ret += imos[(y2 % n)][(x2 % n)] - ret += imos[(y2 % n)][n - (x1 % n)] - ret += imos[(y2 % n)][x1] - ret += imos[y1][x_max] - - ret += imos[n][n] * (((y2 - y1) // n)) * ((x2 - x1) // n) - - return ret + x1, y1, x2, y2 = query + # 基準点を(0, 0)にする + mod_x1 = x1 % n + mod_y1 = y1 % n + x2 = x2 - x1 + mod_x1 + y2 = y2 - y1 + mod_y1 + x1 = mod_x1 + y1 = mod_y1 + # 4つの領域に分ける + y_max = y2 + (n - (y2 % n)) + x_max = x2 + (n - (x2 % n)) + ret = 0 + + # 4隅 + ret += imos[(y2 % n)][(x2 % n)] + ret += imos[(y2 % n)][n - (x1 % n)] + ret += imos[(y2 % n)][x1] + ret += imos[y1][x_max] + + ret += imos[n][n] * (((y2 - y1) // n)) * ((x2 - x1) // n) + + return ret + ans = [] for query in queries: - ans.append(solve_query(query)) + ans.append(solve_query(query)) print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc331/e.py b/atcoder/abc/abc301-400/abc331/e.py index ad961922..477f309c 100644 --- a/atcoder/abc/abc301-400/abc331/e.py +++ b/atcoder/abc/abc301-400/abc331/e.py @@ -1,4 +1,3 @@ - n, m, l = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) @@ -9,15 +8,15 @@ cd = [] for _ in range(l): - c, d = map(int, input().split()) - cd.append((c, d)) + c, d = map(int, input().split()) + cd.append((c, d)) cd = set(cd) ans = 0 for ai, a_idx in a_with_index: - for bi, b_idx in b_with_index: - if (a_idx, b_idx) in cd: - continue - ans = max(ans, ai + bi) - break -print(ans) \ No newline at end of file + for bi, b_idx in b_with_index: + if (a_idx, b_idx) in cd: + continue + ans = max(ans, ai + bi) + break +print(ans) diff --git a/atcoder/abc/abc301-400/abc331/f.py b/atcoder/abc/abc301-400/abc331/f.py index cf261d8a..d9d8efde 100644 --- a/atcoder/abc/abc301-400/abc331/f.py +++ b/atcoder/abc/abc301-400/abc331/f.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -8,25 +9,27 @@ queries = [] for _ in range(q): - query = list(input().split()) - queries.append(query) + query = list(input().split()) + queries.append(query) ans = [] + def is_re(s): - for i in range(len(s) // 2): - if s[i] != s[len(s) - i - 1]: - return "No" - return "Yes" + for i in range(len(s) // 2): + if s[i] != s[len(s) - i - 1]: + return "No" + return "Yes" + for query in queries: - if query[0] == "1": - _, x, c = query - x = int(x) - 1 - s[x] = c - else: - _, l, r = query - l = int(l) - 1 - r = int(r) - 1 - ans.append(is_re(s[l:r + 1])) + if query[0] == "1": + _, x, c = query + x = int(x) - 1 + s[x] = c + else: + _, l, r = query + l = int(l) - 1 + r = int(r) - 1 + ans.append(is_re(s[l : r + 1])) print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc332/a.py b/atcoder/abc/abc301-400/abc332/a.py index 201442c3..2f61ce77 100644 --- a/atcoder/abc/abc301-400/abc332/a.py +++ b/atcoder/abc/abc301-400/abc332/a.py @@ -7,4 +7,4 @@ if ans < s: ans += k -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc332/b.py b/atcoder/abc/abc301-400/abc332/b.py index 624edc49..3f2d35c8 100644 --- a/atcoder/abc/abc301-400/abc332/b.py +++ b/atcoder/abc/abc301-400/abc332/b.py @@ -14,4 +14,4 @@ if glass > g: cup = glass - g glass = g -print(glass, cup) \ No newline at end of file +print(glass, cup) diff --git a/atcoder/abc/abc301-400/abc332/c.py b/atcoder/abc/abc301-400/abc332/c.py index f4939f47..f160c856 100644 --- a/atcoder/abc/abc301-400/abc332/c.py +++ b/atcoder/abc/abc301-400/abc332/c.py @@ -3,7 +3,7 @@ ans = 0 -current = [m, 0] # 無地, ロゴ入り +current = [m, 0] # 無地, ロゴ入り for i in range(n): si = s[i] if si == "0": diff --git a/atcoder/abc/abc301-400/abc332/d.py b/atcoder/abc/abc301-400/abc332/d.py index e84f2a64..1f4819c9 100644 --- a/atcoder/abc/abc301-400/abc332/d.py +++ b/atcoder/abc/abc301-400/abc332/d.py @@ -1,5 +1,6 @@ import itertools from collections import deque + h, w = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(h)] B = [list(map(int, input().split())) for _ in range(h)] @@ -19,6 +20,7 @@ def calc_cost(vector): # print(base_vector, cost) return cost + # 列の入れ替え全列挙 ans = -1 for cols in itertools.permutations(range(w)): @@ -36,4 +38,3 @@ def calc_cost(vector): else: ans = min(ans, cost) print(ans) - diff --git a/atcoder/abc/abc301-400/abc332/e.py b/atcoder/abc/abc301-400/abc332/e.py index 57c0582a..e7f98095 100644 --- a/atcoder/abc/abc301-400/abc332/e.py +++ b/atcoder/abc/abc301-400/abc332/e.py @@ -1,6 +1,7 @@ from decimal import Decimal -from heapq import heappush, heappop, heapify -INF = float('inf') +from heapq import heapify, heappop, heappush + +INF = float("inf") SEARCH_DEPTH = 100 n, d = map(int, input().split()) @@ -8,6 +9,7 @@ w = sorted(w, reverse=True) w = [Decimal(x) for x in w] + def calc_v(xs): v = Decimal(0) mean = Decimal(sum(xs) / len(xs)) @@ -15,6 +17,7 @@ def calc_v(xs): v += (Decimal(x) - mean) ** 2 return Decimal(v / len(xs)) + def solve_greedy(w, d): # 分散が最小になるようなグループを選び続ける boxes = [0 for _ in range(d)] @@ -43,8 +46,9 @@ def solve_greedy(w, d): # print(candidates) return candidates[0][1], candidates[0][0] + boxes, v = solve_greedy(w, d) # print(boxes, v) print(v) -# print(calc_v([Decimal(6), Decimal(8), Decimal(6)])) \ No newline at end of file +# print(calc_v([Decimal(6), Decimal(8), Decimal(6)])) diff --git a/atcoder/abc/abc301-400/abc332/f.py b/atcoder/abc/abc301-400/abc332/f.py index cce6306c..1bb5c236 100644 --- a/atcoder/abc/abc301-400/abc332/f.py +++ b/atcoder/abc/abc301-400/abc332/f.py @@ -10,25 +10,26 @@ from math import gcd from typing import List + class SegTree: def __init__(self, n: int, mode: str = "sum") -> None: self.n = n self.mode = mode unit_elements = { - "min": 2 ** 31 - 1, - "max": -(10 ** 13), + "min": 2**31 - 1, + "max": -(10**13), "sum": 0, "mul": 1, "gcd": 0, } self.e = unit_elements[self.mode] # 単位元 self.lv = (self.n - 1).bit_length() - self.tree_size = 2 ** self.lv # n以上の最小の2のべき乗数 + self.tree_size = 2**self.lv # n以上の最小の2のべき乗数 self.tree_value = [self.e] * (2 * self.tree_size) self.tree_lazy = [None] * (2 * self.tree_size) def __str__(self) -> str: - if self.tree_size > 2 ** 4: + if self.tree_size > 2**4: return "Segtree size too big" out = "" i = 0 @@ -143,4 +144,3 @@ def query(self, l: int, r: int) -> int: L >>= 1 R >>= 1 return s - diff --git a/atcoder/abc/abc301-400/abc333/a.py b/atcoder/abc/abc301-400/abc333/a.py index 0472307f..ebeec484 100644 --- a/atcoder/abc/abc301-400/abc333/a.py +++ b/atcoder/abc/abc301-400/abc333/a.py @@ -4,4 +4,4 @@ for i in range(n): ans += str(n) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc333/b.py b/atcoder/abc/abc301-400/abc333/b.py index 9a1dda11..b78d9590 100644 --- a/atcoder/abc/abc301-400/abc333/b.py +++ b/atcoder/abc/abc301-400/abc333/b.py @@ -7,15 +7,15 @@ set(["B", "C"]), set(["C", "D"]), set(["D", "E"]), - set(["A", "E"]) + set(["A", "E"]), ], [ set(["A", "C"]), set(["B", "D"]), set(["C", "E"]), set(["D", "A"]), - set(["E", "B"]) - ] + set(["E", "B"]), + ], ] g1 = groups[0] g2 = groups[1] diff --git a/atcoder/abc/abc301-400/abc333/b_better.py b/atcoder/abc/abc301-400/abc333/b_better.py index 4d7da760..666f0846 100644 --- a/atcoder/abc/abc301-400/abc333/b_better.py +++ b/atcoder/abc/abc301-400/abc333/b_better.py @@ -1,4 +1,5 @@ from collections import defaultdict + s = input() t = input() diff --git a/atcoder/abc/abc301-400/abc333/d.py b/atcoder/abc/abc301-400/abc333/d.py index fadb0c1c..df30126a 100644 --- a/atcoder/abc/abc301-400/abc333/d.py +++ b/atcoder/abc/abc301-400/abc333/d.py @@ -1,4 +1,5 @@ from collections import defaultdict, deque + n = int(input()) uv = defaultdict(list) for _ in range(n - 1): @@ -28,4 +29,4 @@ counts.append(count) counts.sort() ans = sum(counts[:-1]) -print(ans + 1) \ No newline at end of file +print(ans + 1) diff --git a/atcoder/abc/abc301-400/abc333/e.py b/atcoder/abc/abc301-400/abc333/e.py index 44cc06d9..83fa2e79 100644 --- a/atcoder/abc/abc301-400/abc333/e.py +++ b/atcoder/abc/abc301-400/abc333/e.py @@ -43,4 +43,4 @@ posion_in_hand -= 1 ans_k = max(ans_k, posion_in_hand) print(ans_k) -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc301-400/abc333/f.py b/atcoder/abc/abc301-400/abc333/f.py index f0e153c1..70ac55e5 100644 --- a/atcoder/abc/abc301-400/abc333/f.py +++ b/atcoder/abc/abc301-400/abc333/f.py @@ -6,6 +6,7 @@ n = int(input()) MOD = 998244353 + class ModInt: def __init__(self, x, p=998244353): self.mod = p @@ -76,10 +77,10 @@ def __rpow__(self, other): else ModInt(pow(other, self.x, self.mod)) ) + # 長さiの列が全て消える確率 -tmp = [1, ModInt(1) / 2, -s = (1 + 2 + 4 + 8 + 16) +s = 1 + 2 + 4 + 8 + 16 ans1 = ModInt(1) ans1 /= ModInt(s) -print(ans1) \ No newline at end of file +print(ans1) diff --git a/atcoder/abc/abc301-400/abc334/a.py b/atcoder/abc/abc301-400/abc334/a.py index daf0dd2d..94cbb090 100644 --- a/atcoder/abc/abc301-400/abc334/a.py +++ b/atcoder/abc/abc301-400/abc334/a.py @@ -3,4 +3,4 @@ if b > g: print("Bat") else: - print("Glove") \ No newline at end of file + print("Glove") diff --git a/atcoder/abc/abc301-400/abc334/b.py b/atcoder/abc/abc301-400/abc334/b.py index bd131396..ca2458dd 100644 --- a/atcoder/abc/abc301-400/abc334/b.py +++ b/atcoder/abc/abc301-400/abc334/b.py @@ -1,4 +1,4 @@ -INF = 10 ** 19 +INF = 10**19 a, m, l, r = map(int, input().split()) a += INF a %= m @@ -8,4 +8,4 @@ l = l + ((a - l) % m) r = r - ((r - a) % m) -print((r - l) // m + 1) \ No newline at end of file +print((r - l) // m + 1) diff --git a/atcoder/abc/abc301-400/abc334/c.py b/atcoder/abc/abc301-400/abc334/c.py index 6df8d923..d9eb2314 100644 --- a/atcoder/abc/abc301-400/abc334/c.py +++ b/atcoder/abc/abc301-400/abc334/c.py @@ -1,5 +1,6 @@ from collections import deque -INF = float('inf') + +INF = float("inf") n, k = map(int, input().split()) a = list(map(int, input().split())) a = sorted(a) @@ -41,4 +42,4 @@ tmp_ans = a_prefix[i] + a_suffix[i] ans = min(ans, tmp_ans) # print(a_prefix, a_suffix) -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc334/d.py b/atcoder/abc/abc301-400/abc334/d.py index c6212910..d21af060 100644 --- a/atcoder/abc/abc301-400/abc334/d.py +++ b/atcoder/abc/abc301-400/abc334/d.py @@ -1,4 +1,5 @@ from bisect import bisect_left, bisect_right + n, q = map(int, input().split()) r = list(map(int, input().split())) r = sorted(r) @@ -8,6 +9,8 @@ def cumsum(a): for v in a: r.append(r[-1] + v) return r + + cum_r = cumsum(r) ans = [] @@ -16,4 +19,4 @@ def cumsum(a): # 二分探索 ans.append(bisect_right(cum_r, x) - 1) # print(r, cum_r) -print(*ans, sep='\n') \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc334/e.py b/atcoder/abc/abc301-400/abc334/e.py index 70d3b77e..4c808ac5 100644 --- a/atcoder/abc/abc301-400/abc334/e.py +++ b/atcoder/abc/abc301-400/abc334/e.py @@ -1,9 +1,11 @@ from collections import defaultdict + h, w = map(int, input().split()) s = [list(input()) for _ in range(h)] MOD = 998244353 + class ModInt: def __init__(self, x, p=998244353): self.mod = p @@ -74,7 +76,8 @@ def __rpow__(self, other): else ModInt(pow(other, self.x, self.mod)) ) -class UnionFind(): + +class UnionFind: def __init__(self, n): self.n = n + 1 self.parents = [-1] * (n + 1) @@ -119,25 +122,27 @@ def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): - return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) + return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) + def calc_num(y, x): return w * y + x + dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)] -uf_tree = UnionFind(h*w) +uf_tree = UnionFind(h * w) ans = ModInt(0) count_red = 0 for i in range(h): for j in range(w): - if s[i][j] == '.': + if s[i][j] == ".": count_red += 1 else: num = calc_num(i, j) for dx, dy in dxy: x = j + dx y = i + dy - if 0 <= x < w and 0 <= y < h and s[y][x] == '#': + if 0 <= x < w and 0 <= y < h and s[y][x] == "#": neighbor_num = calc_num(y, x) if not uf_tree.same(num, neighbor_num): uf_tree.union(num, neighbor_num) @@ -146,19 +151,19 @@ def calc_num(y, x): groups = set() for i in range(h): for j in range(w): - if s[i][j] == '#': + if s[i][j] == "#": num = calc_num(i, j) groups.add(uf_tree.find(num)) base_group_count = len(groups) for i in range(h): for j in range(w): - if s[i][j] == '.': + if s[i][j] == ".": num = calc_num(i, j) groups = set() for dx, dy in dxy: x = j + dx y = i + dy - if 0 <= x < w and 0 <= y < h and s[y][x] == '#': + if 0 <= x < w and 0 <= y < h and s[y][x] == "#": neighbor_num = calc_num(y, x) groups.add(uf_tree.find(neighbor_num)) if len(groups) == 1: @@ -173,4 +178,3 @@ def calc_num(y, x): ans /= ModInt(count_red) print(ans) - diff --git a/atcoder/abc/abc301-400/abc334/f.py b/atcoder/abc/abc301-400/abc334/f.py index c299332c..a0768250 100644 --- a/atcoder/abc/abc301-400/abc334/f.py +++ b/atcoder/abc/abc301-400/abc334/f.py @@ -1,4 +1,5 @@ from math import sqrt + INF = float("inf") n, k = map(int, input().split()) @@ -6,8 +7,10 @@ s = (sx, sy) xy = [] + def dist(x1, y1, x2, y2): - return sqrt((x1 - x2)**2 + (y1 - y2)**2) + return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) + for _ in range(n): x, y = map(int, input().split()) @@ -21,4 +24,8 @@ def dist(x1, y1, x2, y2): for j in range(k): if i - j < 0: break - dp[i] = min(dp[i], dp[i - j - 1] + dist(xy[i - j - 1][0], xy[i - j - 1][1], xy[i - 1][0], xy[i - 1][1])) + dp[i] = min( + dp[i], + dp[i - j - 1] + + dist(xy[i - j - 1][0], xy[i - j - 1][1], xy[i - 1][0], xy[i - 1][1]), + ) diff --git a/atcoder/abc/abc301-400/abc335/a.py b/atcoder/abc/abc301-400/abc335/a.py index 10e30aec..8c04b7a9 100644 --- a/atcoder/abc/abc301-400/abc335/a.py +++ b/atcoder/abc/abc301-400/abc335/a.py @@ -1,3 +1,3 @@ s = list(input()) s[-1] = "4" -print(*s, sep="") \ No newline at end of file +print(*s, sep="") diff --git a/atcoder/abc/abc301-400/abc335/b.py b/atcoder/abc/abc301-400/abc335/b.py index b004f4c4..5f022e86 100644 --- a/atcoder/abc/abc301-400/abc335/b.py +++ b/atcoder/abc/abc301-400/abc335/b.py @@ -10,4 +10,4 @@ l.sort() l = [" ".join(map(str, x)) for x in l] -print(*l, sep="\n") \ No newline at end of file +print(*l, sep="\n") diff --git a/atcoder/abc/abc301-400/abc335/c.py b/atcoder/abc/abc301-400/abc335/c.py index 964faf69..fecf1a6c 100644 --- a/atcoder/abc/abc301-400/abc335/c.py +++ b/atcoder/abc/abc301-400/abc335/c.py @@ -1,15 +1,11 @@ import sys + import pypyjit -pypyjit.set_param('max_unroll_recursion=-1') +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() -directions = { - "L": [-1, 0], - "R": [1, 0], - "U": [0, 1], - "D": [0, -1] -} +directions = {"L": [-1, 0], "R": [1, 0], "U": [0, 1], "D": [0, -1]} n, q = map(int, input().split()) queries = [] @@ -31,4 +27,4 @@ x = int(x) current_x = dragon[-x] ans.append(f"{current_x[0]} {current_x[1]}") -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/abc/abc301-400/abc335/e.py b/atcoder/abc/abc301-400/abc335/e.py index 864a35a3..3cadfeab 100644 --- a/atcoder/abc/abc301-400/abc335/e.py +++ b/atcoder/abc/abc301-400/abc335/e.py @@ -1,5 +1,6 @@ import sys from collections import defaultdict, deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) INF = float("inf") diff --git a/atcoder/abc/abc301-400/abc336/a.py b/atcoder/abc/abc301-400/abc336/a.py index c5cb2eec..9bd1f143 100644 --- a/atcoder/abc/abc301-400/abc336/a.py +++ b/atcoder/abc/abc301-400/abc336/a.py @@ -4,4 +4,4 @@ ans.append("o") ans.append("n") ans.append("g") -print("".join(ans)) \ No newline at end of file +print("".join(ans)) diff --git a/atcoder/abc/abc301-400/abc336/b.py b/atcoder/abc/abc301-400/abc336/b.py index 72e4dfce..8e0acf2c 100644 --- a/atcoder/abc/abc301-400/abc336/b.py +++ b/atcoder/abc/abc301-400/abc336/b.py @@ -7,4 +7,4 @@ else: break n >>= 1 -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/abc/abc301-400/abc336/c.py b/atcoder/abc/abc301-400/abc336/c.py index 61d1b0fa..a742fed8 100644 --- a/atcoder/abc/abc301-400/abc336/c.py +++ b/atcoder/abc/abc301-400/abc336/c.py @@ -10,7 +10,7 @@ def base_5(n): n //= 5 return ans[::-1] + mapping = [0, 2, 4, 6, 8] ans = int("".join(map(str, [mapping[x] for x in base_5(n - 1)]))) print(ans) - diff --git a/atcoder/abc/abc301-400/abc336/e.py b/atcoder/abc/abc301-400/abc336/e.py index 5b099c4b..54608d78 100644 --- a/atcoder/abc/abc301-400/abc336/e.py +++ b/atcoder/abc/abc301-400/abc336/e.py @@ -9,11 +9,10 @@ # 1桁目 for i in range(1, 135): for j in range(1, 10): - counts[0][i] = + counts[0][i] = 1 for i in range(1, 15): for j in range(135): counts[i][j] = counts[i - 1][j] counts[i][j] += counts[i - 1][(j - i * (10 ** (i - 1))) % 135] counts[i][i * (10 ** (i - 1)) % 135] += 1 - diff --git a/atcoder/abc/abc301-400/abc336/f.py b/atcoder/abc/abc301-400/abc336/f.py index d2dfdb2c..cde3da45 100644 --- a/atcoder/abc/abc301-400/abc336/f.py +++ b/atcoder/abc/abc301-400/abc336/f.py @@ -1,10 +1,12 @@ import sys -import pypyjit from collections import defaultdict -pypyjit.set_param('max_unroll_recursion=-1') + +import pypyjit + +pypyjit.set_param("max_unroll_recursion=-1") input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -INF = float('inf') +INF = float("inf") h, w = map(int, input().split()) s = [list(map(int, input().split())) for _ in range(h)] @@ -12,6 +14,7 @@ # 連続して同じところを操作すると元に戻るので、最初だけ4つの選択肢、そのあとは3つの選択肢 # 左上、右上、左下、右下 + def is_state_correct(X): for i in range(h): for j in range(w): @@ -19,8 +22,9 @@ def is_state_correct(X): return False return True + def spin(pattern_num, X): - # 左上、右上、左下、右下 + #  左上、右上、左下、右下 tmp_X = [[0 for _ in range(w)] for _ in range(h)] dxy = [[0, 0], [0, 1], [1, 0], [1, 1]] x = dxy[pattern_num][0] @@ -42,17 +46,22 @@ def spin(pattern_num, X): tmp_X[0][j] = X[0][j] return tmp_X + def state_str(X): - return '_'.join(['_'.join(map(str, x)) for x in X]) + return "_".join(["_".join(map(str, x)) for x in X]) + def display(X): - return '\n'.join([' '.join(map(str, x)) for x in X]) + return "\n".join([" ".join(map(str, x)) for x in X]) + visited = defaultdict(lambda: INF) visited[state_str(s)] = 0 ans = INF -def dfs(X, pre_pattern_num = -1, depth = 1): + + +def dfs(X, pre_pattern_num=-1, depth=1): for i in range(4): if i == pre_pattern_num: continue @@ -65,6 +74,7 @@ def dfs(X, pre_pattern_num = -1, depth = 1): continue dfs(tmp_X, i, depth + 1) + if is_state_correct(s): print(0) exit() @@ -75,4 +85,4 @@ def dfs(X, pre_pattern_num = -1, depth = 1): if ans == INF: print(-1) else: - print(ans) \ No newline at end of file + print(ans) diff --git a/atcoder/abc/abc301-400/abc337/a.py b/atcoder/abc/abc301-400/abc337/a.py index 27b6869d..2c59e113 100644 --- a/atcoder/abc/abc301-400/abc337/a.py +++ b/atcoder/abc/abc301-400/abc337/a.py @@ -12,4 +12,4 @@ elif x < y: print("Aoki") else: - print("Draw") \ No newline at end of file + print("Draw") diff --git a/atcoder/abc/abc301-400/abc337/b.py b/atcoder/abc/abc301-400/abc337/b.py index 3fe1ccf9..632e1500 100644 --- a/atcoder/abc/abc301-400/abc337/b.py +++ b/atcoder/abc/abc301-400/abc337/b.py @@ -13,4 +13,4 @@ if flatten in ["A", "AB", "ABC", "B", "BC", "C", "AC"]: print("Yes") else: - print("No") \ No newline at end of file + print("No") diff --git a/atcoder/abc/abc301-400/abc337/c.py b/atcoder/abc/abc301-400/abc337/c.py index 1f26823d..a7e40ad6 100644 --- a/atcoder/abc/abc301-400/abc337/c.py +++ b/atcoder/abc/abc301-400/abc337/c.py @@ -13,4 +13,4 @@ while len(ans) < n: ans.append(nexts[ans[-1]]) -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/atcoder/abc/abc301-400/abc337/d.py b/atcoder/abc/abc301-400/abc337/d.py index ca209c52..8a3dd919 100644 --- a/atcoder/abc/abc301-400/abc337/d.py +++ b/atcoder/abc/abc301-400/abc337/d.py @@ -1,5 +1,6 @@ from collections import deque -INF = float('inf') + +INF = float("inf") h, w, k = map(int, input().split()) s = [list(input()) for _ in range(h)] diff --git a/atcoder/abc/abc301-400/abc337/e.py b/atcoder/abc/abc301-400/abc337/e.py index efe1bd36..c97cf85a 100644 --- a/atcoder/abc/abc301-400/abc337/e.py +++ b/atcoder/abc/abc301-400/abc337/e.py @@ -24,4 +24,3 @@ x = int(response, 2) + 1 print(x, flush=True) - diff --git a/atcoder/abc/abc301-400/abc337/f.py b/atcoder/abc/abc301-400/abc337/f.py index fa7e6507..be99e32d 100644 --- a/atcoder/abc/abc301-400/abc337/f.py +++ b/atcoder/abc/abc301-400/abc337/f.py @@ -1,12 +1,13 @@ n, m, k = map(int, input().split()) c = list(map(int, input().split())) + class BIT: def __init__(self, n): - self.size=n - self.tree = [0] * (n+1) + self.size = n + self.tree = [0] * (n + 1) - def add(self, i,x): + def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i @@ -18,10 +19,11 @@ def sum(self, i): i -= i & -i return total + def InversionNumberByBIT(A): ans = 0 Bit = BIT(max(len(A) + 1, max(A) + 1)) for i in range(len(A)): ans += i - Bit.sum(A[i]) Bit.add(A[i], 1) - return ans \ No newline at end of file + return ans diff --git a/atcoder/aising2020/c.py b/atcoder/aising2020/c.py index 8197aed6..517507a8 100644 --- a/atcoder/aising2020/c.py +++ b/atcoder/aising2020/c.py @@ -1,10 +1,10 @@ n = int(input()) ans = [] -f = [0 for _ in range(10 ** 4 + 1)] +f = [0 for _ in range(10**4 + 1)] for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): - tmp = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x + tmp = x**2 + y**2 + z**2 + x * y + y * z + z * x if tmp <= n: f[tmp] += 1 for i in range(1, n + 1): diff --git a/atcoder/aising2020/d.py b/atcoder/aising2020/d.py index a6bd4f3e..60da66ea 100644 --- a/atcoder/aising2020/d.py +++ b/atcoder/aising2020/d.py @@ -45,7 +45,7 @@ def popcount(idx): base = 0 i = 2 while i <= n: - if i % (2 ** base) == 0: + if i % (2**base) == 0: base += 1 bit_cnt_table[i] = 1 + bit_cnt_table[i - 2 ** (base)] i += 1 diff --git a/atcoder/codequeen2023-final/a.py b/atcoder/codequeen2023-final/a.py index 05b367f1..75a87b14 100644 --- a/atcoder/codequeen2023-final/a.py +++ b/atcoder/codequeen2023-final/a.py @@ -6,4 +6,4 @@ ans += s_i if s_i == c: ans += s_i -print(ans) \ No newline at end of file +print(ans) diff --git a/atcoder/codequeen2023-final/b.py b/atcoder/codequeen2023-final/b.py index a7c728fc..22b1c95b 100644 --- a/atcoder/codequeen2023-final/b.py +++ b/atcoder/codequeen2023-final/b.py @@ -1,13 +1,16 @@ from collections import defaultdict + n = int(input()) rc = [] + def four(x, y): # x, yを入れたら縦横斜めの座標系に変換する r1 = x + y r2 = (n - 1 - x) + y return [x, y, r1, r2] + ans = [-1, -1] flag = True memo = defaultdict(lambda: defaultdict(lambda: False)) @@ -34,4 +37,4 @@ def four(x, y): if ans == [-1, -1]: print(-1) else: - print(f"{ans[0]} {ans[1]}") \ No newline at end of file + print(f"{ans[0]} {ans[1]}") diff --git a/atcoder/codequeen2023-final/c.py b/atcoder/codequeen2023-final/c.py index d30fa846..14b0ddee 100644 --- a/atcoder/codequeen2023-final/c.py +++ b/atcoder/codequeen2023-final/c.py @@ -1,15 +1,16 @@ import sys -from collections import deque, defaultdict +from collections import defaultdict, deque + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) n, s, t = map(int, input().split()) uv = [] edges = defaultdict(lambda: []) -for _ in range(n-1): +for _ in range(n - 1): u, v = map(int, input().split()) - edges[u-1].append(v-1) - edges[v-1].append(u-1) + edges[u - 1].append(v - 1) + edges[v - 1].append(u - 1) ans = [-1 for _ in range(n)] @@ -50,4 +51,4 @@ q.append([v_i, dist + 1]) visited[v_i] = True -print(*ans, sep="\n") \ No newline at end of file +print(*ans, sep="\n") diff --git a/atcoder/codequeen2023-final/d.py b/atcoder/codequeen2023-final/d.py index 620d12f6..99d86494 100644 --- a/atcoder/codequeen2023-final/d.py +++ b/atcoder/codequeen2023-final/d.py @@ -1,2 +1 @@ r, c, rs, cs, rt, ct = map(int, input().split()) - diff --git a/atcoder/codequeen2023-final/e.py b/atcoder/codequeen2023-final/e.py index 552ad717..e18f4011 100644 --- a/atcoder/codequeen2023-final/e.py +++ b/atcoder/codequeen2023-final/e.py @@ -9,4 +9,4 @@ for i in range(1, n + 1): # i番目が使用済みなので足すだけ dp[i][1] = dp[i - 1][0] - # i番目を使っていない場合はiとi-1の \ No newline at end of file + # i番目を使っていない場合はiとi-1の diff --git a/atcoder/diverta2019/D.py b/atcoder/diverta2019/D.py index d97a799d..85031c66 100644 --- a/atcoder/diverta2019/D.py +++ b/atcoder/diverta2019/D.py @@ -3,7 +3,7 @@ if n < 3: ans = 0 else: - for i in range(1, int(n ** 0.5) + 1): + for i in range(1, int(n**0.5) + 1): if n % i == n // i: ans += i i = (n // i) - 1 diff --git a/atcoder/dp/m.py b/atcoder/dp/m.py index c065f96c..3cf77b52 100644 --- a/atcoder/dp/m.py +++ b/atcoder/dp/m.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) @@ -22,4 +22,4 @@ dp[i][j] = va - vb dp[i][j] %= MOD -print(dp[n][0]) \ No newline at end of file +print(dp[n][0]) diff --git a/atcoder/dp/tdpc/c.py b/atcoder/dp/tdpc/c.py index 5da3e580..1042fb9e 100644 --- a/atcoder/dp/tdpc/c.py +++ b/atcoder/dp/tdpc/c.py @@ -1,8 +1,8 @@ k = int(input()) -r = [int(input()) for _ in range(2 ** k)] +r = [int(input()) for _ in range(2**k)] -dp = [[0 for _ in range(k + 1)] for _ in range(2 ** k + 1)] -for i in range(2 ** k + 1): +dp = [[0 for _ in range(k + 1)] for _ in range(2**k + 1)] +for i in range(2**k + 1): dp[i][0] = 1 @@ -11,10 +11,10 @@ def p(i, j): for i in range(1, k + 1): - for j in range(1, (2 ** k) + 1): - bot = ((j - 1) // (2 ** i)) * (2 ** i) + 1 + for j in range(1, (2**k) + 1): + bot = ((j - 1) // (2**i)) * (2**i) + 1 mid = bot + 2 ** (i - 1) - top = bot + 2 ** i + top = bot + 2**i # print(bot, mid, top) if bot <= j < mid: for l in range(mid, top): @@ -23,6 +23,6 @@ def p(i, j): for l in range(bot, mid): dp[j][i] += p(j, l) * dp[j][i - 1] * dp[l][i - 1] ans = [] -for i in range(2 ** k): +for i in range(2**k): ans.append("{:.10f}".format(dp[i + 1][k])) print("\n".join(ans)) diff --git a/atcoder/hitachi2020/d.py b/atcoder/hitachi2020/d.py index afcfbf14..2c8af5a3 100644 --- a/atcoder/hitachi2020/d.py +++ b/atcoder/hitachi2020/d.py @@ -14,7 +14,7 @@ a0.sort() ab.sort(reverse=True) -INF = 10 ** 12 +INF = 10**12 N = 40 m = len(ab) dp = [[INF for _ in range(N)] for _ in range(m + 1)] diff --git a/atcoder/iroha2019-day1/J.py b/atcoder/iroha2019-day1/J.py index bfa99e84..454370bb 100644 --- a/atcoder/iroha2019-day1/J.py +++ b/atcoder/iroha2019-day1/J.py @@ -2,7 +2,7 @@ def display_ans_list(max_n): for n in range(1, max_n + 1): l_ = [] - for i in range(2 ** n): + for i in range(2**n): if format(i, "b").zfill(n) == format(i, "b").zfill(n)[::-1]: l_.append(format(i, "b").zfill(n)) for k in range(n): diff --git a/atcoder/jsc2019-qual/jsc2019-qual_b.py b/atcoder/jsc2019-qual/jsc2019-qual_b.py index 73c07976..c3a96050 100644 --- a/atcoder/jsc2019-qual/jsc2019-qual_b.py +++ b/atcoder/jsc2019-qual/jsc2019-qual_b.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) diff --git a/atcoder/jsc2019-qual/jsc2019-qual_c.py b/atcoder/jsc2019-qual/jsc2019-qual_c.py index 067b82ff..1cb00de3 100644 --- a/atcoder/jsc2019-qual/jsc2019-qual_c.py +++ b/atcoder/jsc2019-qual/jsc2019-qual_c.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n = int(input()) s = input() diff --git a/atcoder/keta_DP/typical_dp_contest_E.py b/atcoder/keta_DP/typical_dp_contest_E.py index 8ffd3fe1..0c4d0e86 100644 --- a/atcoder/keta_DP/typical_dp_contest_E.py +++ b/atcoder/keta_DP/typical_dp_contest_E.py @@ -1,4 +1,4 @@ -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 def solve(num, mod): diff --git a/atcoder/keyence2020/c.py b/atcoder/keyence2020/c.py index 2b3f50cd..315057a0 100644 --- a/atcoder/keyence2020/c.py +++ b/atcoder/keyence2020/c.py @@ -2,11 +2,11 @@ a = [] for _ in range(k): a.append(s) -if s > 10 ** 8: +if s > 10**8: for _ in range(n - k): a.append(1) else: for _ in range(n - k): - a.append(10 ** 9) + a.append(10**9) a = list(map(str, a)) print(" ".join(a)) diff --git a/atcoder/keyence2020/d_tmp.py b/atcoder/keyence2020/d_tmp.py index 266f2a20..12888ef3 100644 --- a/atcoder/keyence2020/d_tmp.py +++ b/atcoder/keyence2020/d_tmp.py @@ -15,7 +15,7 @@ i = n - 1 flag = False count = 0 -for _ in range(10 ** 5): +for _ in range(10**5): if i == 0: flag = True break diff --git a/atcoder/kukan_dp/edu_dp_n.py b/atcoder/kukan_dp/edu_dp_n.py index 29f4dd3e..02a42940 100644 --- a/atcoder/kukan_dp/edu_dp_n.py +++ b/atcoder/kukan_dp/edu_dp_n.py @@ -22,7 +22,7 @@ def solve(left, r): if abs(left - r) == 0: return 0 - res = 10 ** 12 + res = 10**12 for mid in range(left, r): res = min(res, solve(left, mid) + solve(mid + 1, r)) diff --git a/atcoder/m-solutions2019/C.py b/atcoder/m-solutions2019/C.py index c1163341..b214bc3a 100644 --- a/atcoder/m-solutions2019/C.py +++ b/atcoder/m-solutions2019/C.py @@ -1,7 +1,7 @@ from math import factorial n, a, b, c = map(int, input().split()) -mod = 10 ** 9 + 7 +mod = 10**9 + 7 def comb(n, r): @@ -12,7 +12,7 @@ def comb(n, r): for m in range(n, 2 * n): e += ( comb(m - 1, n - 1) - * (a ** n * b ** (m - n) + a ** (m - n) * b ** n) + * (a**n * b ** (m - n) + a ** (m - n) * b**n) * m / (100 ** (n - 1) * (100 - c)) ) diff --git a/atcoder/m-solutions2019/E.py b/atcoder/m-solutions2019/E.py index b7fed170..880e8561 100644 --- a/atcoder/m-solutions2019/E.py +++ b/atcoder/m-solutions2019/E.py @@ -1,7 +1,7 @@ import math math.factorial(5) -mod = 10 ** 6 + 3 +mod = 10**6 + 3 q = int(input()) ans = "" for i in range(q): diff --git a/atcoder/m-solutions2020/f.py b/atcoder/m-solutions2020/f.py index d6c8ec19..7dfabab2 100644 --- a/atcoder/m-solutions2020/f.py +++ b/atcoder/m-solutions2020/f.py @@ -3,7 +3,7 @@ input = sys.stdin.readline -INF = 10 ** 12 +INF = 10**12 n = int(input()) xyu = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: set()))) diff --git a/atcoder/other/code-festival-2016-qualc/c.py b/atcoder/other/code-festival-2016-qualc/c.py index 837e545f..791bb184 100644 --- a/atcoder/other/code-festival-2016-qualc/c.py +++ b/atcoder/other/code-festival-2016-qualc/c.py @@ -1,8 +1,8 @@ n = int(input()) t = list(map(int, input().split())) a = list(map(int, input().split())) -INF = 10 ** 12 -MOD = 10 ** 9 + 7 +INF = 10**12 +MOD = 10**9 + 7 arr = [[1, INF] for _ in range(n)] cur_max = -1 diff --git a/atcoder/other/gigacode-2019/c.py b/atcoder/other/gigacode-2019/c.py index 398ad3db..a2eaa163 100644 --- a/atcoder/other/gigacode-2019/c.py +++ b/atcoder/other/gigacode-2019/c.py @@ -2,7 +2,7 @@ a = list(map(int, input().split())) b = list(map(int, input().split())) -INF = 10 ** 10 +INF = 10**10 money = 0 ans = INF diff --git a/atcoder/other/nomura2020/c.py b/atcoder/other/nomura2020/c.py index a181b3c9..e73d2e35 100644 --- a/atcoder/other/nomura2020/c.py +++ b/atcoder/other/nomura2020/c.py @@ -4,7 +4,7 @@ input = sys.stdin.readline -INF = 2 ** 50 +INF = 2**50 n = int(input()) a = list(map(int, input().split())) if n == 0 and a[0] == 0: diff --git a/atcoder/other/tmu001/a.py b/atcoder/other/tmu001/a.py index 8f0c4d50..816192fe 100644 --- a/atcoder/other/tmu001/a.py +++ b/atcoder/other/tmu001/a.py @@ -6,7 +6,7 @@ plus_l = [] cal_l = [] for j in range(len(s)): - bit = 2 ** j + bit = 2**j if i & bit > 0: plus_l.append(j) if len(plus_l) == 0: diff --git a/atcoder/other/tmu001/h.py b/atcoder/other/tmu001/h.py index d1e47d90..07e4867f 100644 --- a/atcoder/other/tmu001/h.py +++ b/atcoder/other/tmu001/h.py @@ -1,6 +1,6 @@ x, y = map(int, input().split()) i = 0 -while x * 2 ** i <= y: +while x * 2**i <= y: i += 1 print(i) diff --git a/atcoder/other/tmu002/c.py b/atcoder/other/tmu002/c.py index b890afac..98e109fe 100644 --- a/atcoder/other/tmu002/c.py +++ b/atcoder/other/tmu002/c.py @@ -1,6 +1,6 @@ import bisect -INF = 10 ** 15 +INF = 10**15 n, W = map(int, input().split()) w = [] v = [] @@ -25,20 +25,20 @@ def solve1(): items1 = [] items2 = [] - for i in range(2 ** a): + for i in range(2**a): w_ = 0 v_ = 0 for j in range(a): - if i & 2 ** j > 0: + if i & 2**j > 0: w_ += w[j] v_ += v[j] items1.append([w_, v_]) items1 = sorted(items1, key=lambda x: (x[0], -x[1])) - for i in range(2 ** b): + for i in range(2**b): w_ = 0 v_ = 0 for j in range(b): - if i & 2 ** j > 0: + if i & 2**j > 0: w_ += w[a + j] v_ += v[a + j] items2.append([w_, v_]) @@ -63,7 +63,7 @@ def solve1(): b_items.append(items2[i]) pre_v = items2[i][1] b_items.insert(0, [0, 0]) - b_items.append([10 ** 20, 0]) + b_items.append([10**20, 0]) b_w = [x[0] for x in b_items] ans = 0 diff --git a/atcoder/other/tmu002/d.py b/atcoder/other/tmu002/d.py index 9d7ad06a..a2c8f753 100644 --- a/atcoder/other/tmu002/d.py +++ b/atcoder/other/tmu002/d.py @@ -3,7 +3,7 @@ import sys input = sys.stdin.readline -INF = 10 ** 10 +INF = 10**10 n = int(input()) c = [0] * n diff --git a/atcoder/other/tmu002/e.py b/atcoder/other/tmu002/e.py index a5c1d2e0..7c4b52ff 100644 --- a/atcoder/other/tmu002/e.py +++ b/atcoder/other/tmu002/e.py @@ -11,14 +11,14 @@ def cmb(n, r): return over // under -MOD = 10 ** 9 + 7 +MOD = 10**9 + 7 n, m = map(int, input().split()) def fact(n): arr = [] temp = n - for i in range(2, int(-(-(n ** 0.5) // 1)) + 1): + for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: diff --git a/atcoder/other/tutorial/arc004_a.py b/atcoder/other/tutorial/arc004_a.py index f564d0d1..a4d0a9cb 100644 --- a/atcoder/other/tutorial/arc004_a.py +++ b/atcoder/other/tutorial/arc004_a.py @@ -12,7 +12,7 @@ def dis(x1, y1, x2, y2): for i in range(n): x[i], y[i] = map(int, input().split()) -ans = -(10 ** 9) +ans = -(10**9) for i in range(n): for j in range(n): diff --git a/atcoder/past/open/past201912-open/g.py b/atcoder/past/open/past201912-open/g.py index 82cb34e2..9997c399 100644 --- a/atcoder/past/open/past201912-open/g.py +++ b/atcoder/past/open/past201912-open/g.py @@ -3,7 +3,7 @@ input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) -INF = 10 ** 9 +INF = 10**9 d = defaultdict(lambda: defaultdict(lambda: -INF)) n = int(input()) diff --git a/atcoder/past/open/past201912-open/h.py b/atcoder/past/open/past201912-open/h.py index 86c1343c..e70de3fb 100644 --- a/atcoder/past/open/past201912-open/h.py +++ b/atcoder/past/open/past201912-open/h.py @@ -2,7 +2,7 @@ from math import ceil input = lambda: sys.stdin.readline().rstrip() -INF = 10 ** 10 +INF = 10**10 n = int(input()) c = list(map(int, input().split())) diff --git a/atcoder/past/open/past201912-open/i.py b/atcoder/past/open/past201912-open/i.py index f5b5ebc2..d4dbcfcc 100644 --- a/atcoder/past/open/past201912-open/i.py +++ b/atcoder/past/open/past201912-open/i.py @@ -4,9 +4,9 @@ input = lambda: sys.stdin.readline().rstrip() n, m = map(int, input().split()) -INF = 10 ** 12 -dp = [INF for _ in range(2 ** n)] -pre_dp = [INF for _ in range(2 ** n)] +INF = 10**12 +dp = [INF for _ in range(2**n)] +pre_dp = [INF for _ in range(2**n)] dp[0] = 0 pre_dp[0] = 0 @@ -15,10 +15,10 @@ c = int(c) s = "".join(list(map(lambda x: "1" if x == "Y" else "0", list(s)))) s = int(s, 2) - for i in range(2 ** n): + for i in range(2**n): t = i | s dp[t] = min(dp[t], pre_dp[t], pre_dp[i] + c) - for i in range(2 ** n): + for i in range(2**n): pre_dp[i] = dp[i] if dp[-1] == INF: print(-1) diff --git a/atcoder/past/open/past201912-open/l.py b/atcoder/past/open/past201912-open/l.py index ac57f9b1..8580046b 100644 --- a/atcoder/past/open/past201912-open/l.py +++ b/atcoder/past/open/past201912-open/l.py @@ -54,7 +54,7 @@ def dist(inp1, inp2): # 小さい方は全探索 ans = INF -for i in range(2 ** m): +for i in range(2**m): ignore_set = set() for j in range(m): if i >> j & 1: diff --git a/atcoder/past/open/past201912-open/m.py b/atcoder/past/open/past201912-open/m.py index 8e71b0dd..c7bd0ae2 100644 --- a/atcoder/past/open/past201912-open/m.py +++ b/atcoder/past/open/past201912-open/m.py @@ -42,7 +42,7 @@ def check(target_power): l = 0 -r = 10 ** 6 +r = 10**6 while (r - l) > 10 ** (-8): mid = (r + l) / 2 if check(mid): diff --git a/atcoder/past/open/past202004-open/g.py b/atcoder/past/open/past202004-open/g.py index 467e261c..426dd115 100644 --- a/atcoder/past/open/past202004-open/g.py +++ b/atcoder/past/open/past202004-open/g.py @@ -27,6 +27,6 @@ d -= x ans_i = 0 for _, v in deleted.items(): - ans_i += v ** 2 + ans_i += v**2 ans.append(ans_i) print("\n".join(list(map(str, ans)))) diff --git a/atcoder/past/open/past202004-open/i.py b/atcoder/past/open/past202004-open/i.py index dc39682f..78a21bb9 100644 --- a/atcoder/past/open/past202004-open/i.py +++ b/atcoder/past/open/past202004-open/i.py @@ -28,6 +28,6 @@ def battle(a, num): # print(new_a) new_a = battle(new_a, i) out = [] -for i in range(2 ** n): +for i in range(2**n): out.append(str(ans[a[i]])) print("\n".join(out)) diff --git a/atcoder/typical90/b.py b/atcoder/typical90/b.py index 234018f2..2525bac6 100644 --- a/atcoder/typical90/b.py +++ b/atcoder/typical90/b.py @@ -2,10 +2,10 @@ def bit_full_search(max_bit: int) -> Iterator[List[int]]: - for i in range(2 ** max_bit): + for i in range(2**max_bit): bit_list = [0 for _ in range(max_bit)] for j in range(max_bit): - if i & (2 ** j) > 0: + if i & (2**j) > 0: bit_list[max_bit - j - 1] = 1 yield bit_list diff --git a/atcoder/typical90/c.py b/atcoder/typical90/c.py index a9bad50b..64ba4c31 100644 --- a/atcoder/typical90/c.py +++ b/atcoder/typical90/c.py @@ -4,7 +4,7 @@ from typing import Dict input = sys.stdin.readline -INF = 10 ** 12 +INF = 10**12 n = int(input()) edges = defaultdict(lambda: []) diff --git a/atcoder/zone2021/c.py b/atcoder/zone2021/c.py index 73fcbddd..ed252dfe 100644 --- a/atcoder/zone2021/c.py +++ b/atcoder/zone2021/c.py @@ -3,7 +3,7 @@ from collections import defaultdict from itertools import combinations -MAX_VALUE = 2 * 10 ** 9 +MAX_VALUE = 2 * 10**9 def score(l1, l2, l3): diff --git a/config/requirements.txt b/config/requirements.txt index 4e49fe90..2cc06b4c 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -1,3 +1,8 @@ +click==8.1.7 +black==22.3.0 +flake8==4.0.1 +isort==5.10.1 +mypy==0.910 pysen==0.10.5 pytest==7.4.4 pyyaml==6.0 diff --git a/mayocon/2023/10/24/b.py b/mayocon/2023/10/24/b.py index a5bbbcda..4b98315e 100644 --- a/mayocon/2023/10/24/b.py +++ b/mayocon/2023/10/24/b.py @@ -13,7 +13,7 @@ print(len(n) - len(num)) exit() for i in range(len(num)): - next_num = num[:i] + num[i+1:] + next_num = num[:i] + num[i + 1 :] queue.append(next_num) -print(-1) \ No newline at end of file +print(-1) diff --git a/mayocon/2023/10/24/c.py b/mayocon/2023/10/24/c.py index 55771b4b..4bcfd3e2 100644 --- a/mayocon/2023/10/24/c.py +++ b/mayocon/2023/10/24/c.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() INF = float("inf") @@ -11,12 +12,12 @@ # i番目のbを使用してカンストさせる時の最小値 ans = INF -ab_sum = 0 # i - 1番目までのa + bの合計値 +ab_sum = 0 # i - 1番目までのa + bの合計値 for i in range(n): a, b = ab[i] if i > x: break ans = min(ans, ab_sum + a + (b * (x - i))) - ab_sum += (a + b) + ab_sum += a + b -print(ans) \ No newline at end of file +print(ans) diff --git a/mayocon/2023/10/24/d.py b/mayocon/2023/10/24/d.py index abd5cc30..a807fde2 100644 --- a/mayocon/2023/10/24/d.py +++ b/mayocon/2023/10/24/d.py @@ -16,10 +16,14 @@ if not flag: break expected_num = num_str[i] - a - if expected_num != num_str[i+1]: - if num_str[i+1] < expected_num and expected_num <= 9 and expected_num >= 0: - num_str[i+1] = expected_num - for j in range(i+2, len(num_str)): + if expected_num != num_str[i + 1]: + if ( + num_str[i + 1] < expected_num + and expected_num <= 9 + and expected_num >= 0 + ): + num_str[i + 1] = expected_num + for j in range(i + 2, len(num_str)): num_str[j] = 0 else: flag = False diff --git a/mayocon/2023/10/24/e.py b/mayocon/2023/10/24/e.py index b5d991f9..3d3f063b 100644 --- a/mayocon/2023/10/24/e.py +++ b/mayocon/2023/10/24/e.py @@ -1,11 +1,14 @@ from collections import deque + n, m = map(int, input().split()) # 移動は最大2n回 <= 200 output_count = 0 + def judge_output(v: int): print(v) + def judge_input(): kv = input() if kv in ["OK", "-1"]: @@ -15,6 +18,7 @@ def judge_input(): v = kv[1:] return k, v + # 深さ優先探索 dist_list = [-1 for _ in range(n + 1)] q = deque([(0, 1, [])]) @@ -26,9 +30,9 @@ def judge_input(): # まだ訪れていない頂点を訪れる v = [i for i in v if dist_list[i] == -1] if len(v) == 0: - next_v = l.pop() # 戻る + next_v = l.pop() # 戻る q.append([dist - 1, next_v, l]) else: next_v = v[0] q.append([dist + 1, next_v, l + [num]]) - judge_output(next_v) \ No newline at end of file + judge_output(next_v) diff --git a/mayocon/2023/10/24/f.py b/mayocon/2023/10/24/f.py index 394a4f08..4da3f8c6 100644 --- a/mayocon/2023/10/24/f.py +++ b/mayocon/2023/10/24/f.py @@ -2,6 +2,7 @@ a = list(map(int, input().split())) a.sort() + def oturi(x): # x円おつりが発生した時の最小枚数 count = 0 @@ -11,4 +12,5 @@ def oturi(x): x %= ai return count -# \ No newline at end of file + +# diff --git a/mayocon/2023/10/30/a.py b/mayocon/2023/10/30/a.py index 3eef4bef..7652f314 100644 --- a/mayocon/2023/10/30/a.py +++ b/mayocon/2023/10/30/a.py @@ -1,3 +1,3 @@ n, a, b = map(int, input().split()) -print(n - a + b) \ No newline at end of file +print(n - a + b) diff --git a/mayocon/2023/10/30/c.py b/mayocon/2023/10/30/c.py index 472ef75a..cee7c148 100644 --- a/mayocon/2023/10/30/c.py +++ b/mayocon/2023/10/30/c.py @@ -1,4 +1,5 @@ import sys + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) @@ -7,17 +8,20 @@ # tのlcm + def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) + def lcm(a, b): return a * b // gcd(a, b) + ans = 1 for ti in t: ans = lcm(ans, ti) -print(ans) \ No newline at end of file +print(ans) diff --git a/mayocon/2023/10/30/d.py b/mayocon/2023/10/30/d.py index 1c0ec5d9..259bfc59 100644 --- a/mayocon/2023/10/30/d.py +++ b/mayocon/2023/10/30/d.py @@ -1,6 +1,7 @@ -import sys import bisect +import sys from collections import defaultdict + input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(20000000) INF = float("inf") @@ -45,4 +46,4 @@ if len(hash_map.keys()) < (a_size + 1) * (b_size + 1): ans[0] = 0 -print(*ans, sep=" ") \ No newline at end of file +print(*ans, sep=" ") diff --git a/mayocon/2023/10/30/e.py b/mayocon/2023/10/30/e.py index 31ced829..10663fb6 100644 --- a/mayocon/2023/10/30/e.py +++ b/mayocon/2023/10/30/e.py @@ -6,7 +6,7 @@ h, w, k = map(int, input().split()) s = [list(map(int, list(input()))) for _ in range(h)] ans = float("inf") -for h_bit in range(2**h): +for h_bit in range(2**h): cut = 0 # i行目に対してグループ付け group = [0] * h @@ -44,4 +44,3 @@ # print(h_bit, ans, cut) # print(cut_history) print(ans) - \ No newline at end of file diff --git a/mayocon/2023/10/30/f.py b/mayocon/2023/10/30/f.py index 5e971a11..3f248ddc 100644 --- a/mayocon/2023/10/30/f.py +++ b/mayocon/2023/10/30/f.py @@ -1,6 +1,7 @@ # 前計算で各S, Gと各お菓子の最短距離を求めておく import time from collections import deque + INF = float("inf") start_at = time.time() h, w, t = map(int, input().split()) @@ -40,7 +41,7 @@ dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)] for start_pos in range(2 + n): visited = [[False] * w for _ in range(h)] - que = deque([[0, positions[start_pos]]]) # [distance, pos] + que = deque([[0, positions[start_pos]]]) # [distance, pos] count = 0 while que: cost, pos = que.popleft() @@ -49,8 +50,13 @@ break for dy, dx in dxy: next_pos = (pos[0] + dy, pos[1] + dx) - - if next_pos[0] < 0 or next_pos[0] >= h or next_pos[1] < 0 or next_pos[1] >= w: + + if ( + next_pos[0] < 0 + or next_pos[0] >= h + or next_pos[1] < 0 + or next_pos[1] >= w + ): continue if visited[next_pos[0]][next_pos[1]]: continue @@ -80,7 +86,9 @@ for k in range(2 + n): if i & (1 << k): continue - dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + distance_matrix[j][k]) + dp[i | (1 << k)][k] = min( + dp[i | (1 << k)][k], dp[i][j] + distance_matrix[j][k] + ) ans = -1 for i in range(len(dp)): @@ -92,7 +100,7 @@ if i & (1 << j): count += 1 ans = max(ans, count) - # print("i:", i, "ans:", ans) + # print("i:", i, "ans:", ans) # print(dp) # print(distance_matrix) -print(ans) \ No newline at end of file +print(ans) diff --git a/sandbox/number_quiz.py b/sandbox/number_quiz.py index 2510936b..bd7e9f52 100644 --- a/sandbox/number_quiz.py +++ b/sandbox/number_quiz.py @@ -23,7 +23,6 @@ a = list(map(int, input().split())) - def solve(a: List[int], x: int) -> str: """ 数列Aを入れた時に数字Xを作ることができるかを判定する @@ -35,4 +34,3 @@ def solve(a: List[int], x: int) -> str: str: (Yes & answer) or No """ pass - diff --git a/sandbox/pgbattle/a.py b/sandbox/pgbattle/a.py index bc3fb433..087ede11 100644 --- a/sandbox/pgbattle/a.py +++ b/sandbox/pgbattle/a.py @@ -10,4 +10,4 @@ elif p == 0: print("0") else: - print("-") \ No newline at end of file + print("-") diff --git a/sandbox/pgbattle/b.py b/sandbox/pgbattle/b.py index 7ca27ad6..8d39481a 100644 --- a/sandbox/pgbattle/b.py +++ b/sandbox/pgbattle/b.py @@ -12,6 +12,6 @@ count += 1 count_question += 1 if count == 3: - ans += 3 ** -count_question + ans += 3**-count_question -print(ans) \ No newline at end of file +print(ans) diff --git a/sandbox/pgbattle/c.py b/sandbox/pgbattle/c.py index 8fde6659..49d8195b 100644 --- a/sandbox/pgbattle/c.py +++ b/sandbox/pgbattle/c.py @@ -1,9 +1,11 @@ from collections import defaultdict + MOD = 998244353 + class Facts: # O(max_num) - def __init__(self, max_num: int = 10 ** 5, p: int = 10 ** 9 + 7) -> None: + def __init__(self, max_num: int = 10**5, p: int = 10**9 + 7) -> None: self.p = p self.max_num = max_num self.fact = [1] * (self.max_num + 1) @@ -54,6 +56,7 @@ def mod_pow(self, a: int, b: int) -> int: b >>= 1 return ans + n, k = map(int, input().split()) a = list(map(int, input().split())) @@ -85,4 +88,4 @@ def mod_pow(self, a: int, b: int) -> int: for peri in perms: ans *= peri ans %= MOD -print(ans) \ No newline at end of file +print(ans) diff --git a/sandbox/pgbattle/d.py b/sandbox/pgbattle/d.py index e2c2b953..b1d716a0 100644 --- a/sandbox/pgbattle/d.py +++ b/sandbox/pgbattle/d.py @@ -1,2 +1 @@ n, m = map(int, input().split()) -