This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = 998244353 | |
# mod を法とする x の逆元を計算する | |
def mod_inv(x, mod): | |
return pow(x, mod - 2, mod) | |
def ntt(a, depth, root): | |
n = len(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cmath | |
def fft(a, inv): | |
n = len(a) | |
if n == 1: | |
return a | |
even = [] | |
odd = [] | |
for i in range(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cmath | |
def eval(p, N, k): | |
if N == 2: | |
p0, p1 = p[k], p[k + 1] | |
p[k], p[k + 1] = p0 + p1, p0 - p1 | |
else: | |
for i in range(N // 2): | |
j = k + 2 * i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def conv(f, g): | |
siz = len(f) + len(g) - 1 | |
siz = (1 << siz - 1).bit_length() | |
f = np.fft.rfft(f, siz) | |
g = np.fft.rfft(g, siz) | |
f *= g | |
f = np.fft.irfft(f, siz) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], | |
[10, INF, 4, 3, INF], | |
[16, 4, INF, 2, 3], | |
[INF, 3, 2, INF, 6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distance(): | |
N = 5 # ノードの個数 | |
INF = float("inf") # 十分大きい定数 | |
# edge[m, n]には、ノードmからノードnへの距離を格納 | |
# 二つのノードが隣接していない場合には INF を格納 | |
edge = [ | |
[INF, 10, 16, INF, INF], | |
[10, INF, 4, 3, INF], | |
[16, 4, INF, 2, 3], | |
[INF, 3, 2, INF, 6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
input = sys.stdin.readline | |
N, M, Q = map(int, input().split()) | |
G = [[] for _ in range(N)] | |
for _ in range(M): | |
x, y = map(lambda n: int(n) - 1, input().split()) | |
G[y].append(x) # 子が親へのポインタを持つようなグラフ | |
ans = [] | |
for i in range(N): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MLEになるバージョン | |
import sys | |
sys.setrecursionlimit(10**7) | |
input = sys.stdin.readline | |
def dfs(n): | |
if (dp[n] >> n) & 1: | |
return dp[n] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
A = list(map(int, input().split())) | |
s = sum(A) | |
dp = 1 | |
for i in range(N): | |
dp |= dp << A[i] | |
ans = (s + 1) // 2 | |
while ans <= 2000 * 2000 + 1: | |
if (dp >> ans) & 1: | |
break |
NewerOlder