complete 2252.py 2623.py 9527.py 31403.py 32822.py
This commit is contained in:
38
zeta_python/completed/2252.py
Normal file
38
zeta_python/completed/2252.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
class TopoSort:
|
||||||
|
def __init__(self, N, E):
|
||||||
|
self.__N = N
|
||||||
|
self.__edges = E
|
||||||
|
self.__targets = [[] for _ in range(self.__N)]
|
||||||
|
self.__indeg = [0] * self.__N
|
||||||
|
for u, v in self.__edges:
|
||||||
|
self.__indeg[v] += 1
|
||||||
|
self.__targets[u].append(v)
|
||||||
|
|
||||||
|
def sort(self) -> list[int]:
|
||||||
|
indeg = self.__indeg.copy()
|
||||||
|
Q = []
|
||||||
|
for i, d in enumerate(indeg):
|
||||||
|
if d == 0:
|
||||||
|
Q.append(i)
|
||||||
|
line = []
|
||||||
|
while Q:
|
||||||
|
u = Q.pop()
|
||||||
|
line.append(u)
|
||||||
|
for v in self.__targets[u]:
|
||||||
|
indeg[v] -= 1
|
||||||
|
if indeg[v] == 0:
|
||||||
|
Q.append(v)
|
||||||
|
|
||||||
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
E = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]
|
||||||
|
solver = TopoSort(N, E)
|
||||||
|
print(" ".join(map(lambda x: str(int(x) + 1), solver.sort())))
|
||||||
43
zeta_python/completed/2623.py
Normal file
43
zeta_python/completed/2623.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
class TopoSort:
|
||||||
|
def __init__(self, N, E):
|
||||||
|
self.__N = N
|
||||||
|
self.__edges = E
|
||||||
|
self.__targets = [[] for _ in range(self.__N)]
|
||||||
|
self.__indeg = [0] * self.__N
|
||||||
|
for u, v in self.__edges:
|
||||||
|
self.__indeg[v] += 1
|
||||||
|
self.__targets[u].append(v)
|
||||||
|
|
||||||
|
def sort(self) -> list[int]:
|
||||||
|
indeg = self.__indeg.copy()
|
||||||
|
Q = []
|
||||||
|
for i, d in enumerate(indeg):
|
||||||
|
if d == 0:
|
||||||
|
Q.append(i)
|
||||||
|
line = []
|
||||||
|
while Q:
|
||||||
|
u = Q.pop()
|
||||||
|
line.append(u)
|
||||||
|
for v in self.__targets[u]:
|
||||||
|
indeg[v] -= 1
|
||||||
|
if indeg[v] == 0:
|
||||||
|
Q.append(v)
|
||||||
|
if len(line) != N:
|
||||||
|
return [-1]
|
||||||
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
E = []
|
||||||
|
for _ in range(M):
|
||||||
|
order = list(map(lambda x: int(x) - 1, input().split()))
|
||||||
|
for u, v in zip(order[1:-1], order[2:]):
|
||||||
|
E.append((u, v))
|
||||||
|
solver = TopoSort(N, E)
|
||||||
|
print("\n".join(map(lambda x: str(int(x) + 1), solver.sort())))
|
||||||
3
zeta_python/completed/31403.py
Normal file
3
zeta_python/completed/31403.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
a, b, c = input(), input(), int(input())
|
||||||
|
print(int(a) + int(b) - int(c))
|
||||||
|
print(int(a + b) - int(c))
|
||||||
27
zeta_python/completed/32822.py
Normal file
27
zeta_python/completed/32822.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
class DiffGameSolver:
|
||||||
|
def __init__(self, N, A: list[int], B: list[int], betas: list[int]):
|
||||||
|
self.__diff_max_by_columns = []
|
||||||
|
for i in range(N):
|
||||||
|
self.__diff_max_by_columns.append(
|
||||||
|
max(abs(A[j][i] - B[j][i]) for j in range(N))
|
||||||
|
)
|
||||||
|
|
||||||
|
self.__betas = betas
|
||||||
|
|
||||||
|
def solve(self) -> int:
|
||||||
|
return sum([self.__diff_max_by_columns[beta] for beta in self.__betas])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
A = [list(map(int, input().split())) for _ in range(N)]
|
||||||
|
B = [list(map(int, input().split())) for _ in range(N)]
|
||||||
|
betas = list(map(lambda x: int(x) - 1, input().split()))
|
||||||
|
|
||||||
|
solver = DiffGameSolver(N, A, B, betas)
|
||||||
|
print(solver.solve())
|
||||||
17
zeta_python/completed/9527.py
Normal file
17
zeta_python/completed/9527.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
def S(n: int):
|
||||||
|
s = n & 1
|
||||||
|
for i in range(60 - 1, 0, -1):
|
||||||
|
if n & (1 << i):
|
||||||
|
s += S.points[i - 1] + (n - (1 << i) + 1)
|
||||||
|
n -= 1 << i
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
S.points = [0] * 60
|
||||||
|
S.points[0] = 1
|
||||||
|
for i in range(1, 60):
|
||||||
|
S.points[i] = 2 * S.points[i - 1] + (1 << i)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
A, B = map(int, input().split())
|
||||||
|
print(S(B) - S(A - 1))
|
||||||
Reference in New Issue
Block a user