Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Type check with mypy
run: |
mypy . --exclude example/
mypy .
- name: Test with pytest
run: |
pytest
6 changes: 4 additions & 2 deletions atcoder/mincostflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ def get_edge(self, i: int) -> Edge:
def edges(self) -> List[Edge]:
return [self.get_edge(i) for i in range(len(self._edges))]

def flow(self, s: int, t: int, flow_limit: Optional[int] = None) -> Tuple[int, int]:
def flow(self, s: int, t: int,
flow_limit: Optional[int] = None) -> Tuple[int, int]:
return self.slope(s, t, flow_limit)[-1]

def slope(self, s: int, t: int, flow_limit: Optional[int] = None) -> List[Tuple[int, int]]:
def slope(self, s: int, t: int,
flow_limit: Optional[int] = None) -> List[Tuple[int, int]]:
assert 0 <= s < self._n
assert 0 <= t < self._n
assert s != t
Expand Down
Empty file added example/__init__.py
Empty file.
11 changes: 7 additions & 4 deletions example/lazysegtree_practice_k.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://atcoder.jp/contests/practice2/tasks/practice2_k

import sys
from typing import Tuple

from atcoder.lazysegtree import LazySegTree
from atcoder.modint import ModContext, Modint
Expand All @@ -11,16 +12,18 @@ def main() -> None:
n, q = map(int, sys.stdin.readline().split())
a = [(Modint(ai), 1) for ai in map(int, sys.stdin.readline().split())]

def op(x: (Modint, int), y: (Modint, int)) -> (Modint, int):
def op(x: Tuple[Modint, int],
y: Tuple[Modint, int]) -> Tuple[Modint, int]:
return x[0] + y[0], x[1] + y[1]

e = Modint(0), 0

def mapping(x: (Modint, Modint), y: (Modint, int)) -> (Modint, int):
def mapping(x: Tuple[Modint, Modint],
y: Tuple[Modint, int]) -> Tuple[Modint, int]:
return x[0] * y[0] + x[1] * y[1], y[1]

def composition(x: (Modint, Modint),
y: (Modint, Modint)) -> (Modint, Modint):
def composition(x: Tuple[Modint, Modint],
y: Tuple[Modint, Modint]) -> Tuple[Modint, Modint]:
return x[0] * y[0], x[0] * y[1] + x[1]

id_ = Modint(1), Modint(0)
Expand Down
7 changes: 4 additions & 3 deletions example/lazysegtree_practice_k_wo_modint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://atcoder.jp/contests/practice2/tasks/practice2_k

import sys
from typing import Tuple

from atcoder.lazysegtree import LazySegTree

Expand All @@ -11,15 +12,15 @@ def main() -> None:
n, q = map(int, sys.stdin.readline().split())
a = [(ai, 1) for ai in map(int, sys.stdin.readline().split())]

def op(x: (int, int), y: (int, int)) -> (int, int):
def op(x: Tuple[int, int], y: Tuple[int, int]) -> Tuple[int, int]:
return (x[0] + y[0]) % mod, x[1] + y[1]

e = 0, 0

def mapping(x: (int, int), y: (int, int)) -> (int, int):
def mapping(x: Tuple[int, int], y: Tuple[int, int]) -> Tuple[int, int]:
return (x[0] * y[0] + x[1] * y[1]) % mod, y[1]

def composition(x: (int, int), y: (int, int)) -> (int, int):
def composition(x: Tuple[int, int], y: Tuple[int, int]) -> Tuple[int, int]:
return (x[0] * y[0]) % mod, (x[0] * y[1] + x[1]) % mod

id_ = 1, 0
Expand Down
6 changes: 4 additions & 2 deletions example/lazysegtree_practice_l.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://atcoder.jp/contests/practice2/tasks/practice2_l

import sys
from typing import Tuple

from atcoder.lazysegtree import LazySegTree

Expand All @@ -14,12 +15,13 @@ def main() -> None:
else:
a.append((0, 1, 0))

def op(x: (int, int, int), y: (int, int, int)) -> (int, int, int):
def op(x: Tuple[int, int, int],
y: Tuple[int, int, int]) -> Tuple[int, int, int]:
return x[0] + y[0], x[1] + y[1], x[2] + y[2] + x[1] * y[0]

e = (0, 0, 0)

def mapping(x: bool, y: (int, int, int)) -> (int, int, int):
def mapping(x: bool, y: Tuple[int, int, int]) -> Tuple[int, int, int]:
if not x:
return y
return y[1], y[0], y[0] * y[1] - y[2]
Expand Down
7 changes: 4 additions & 3 deletions example/maxflow_practice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://atcoder.jp/contests/practice2/tasks/practice2_d

import sys
from typing import Tuple

from atcoder.maxflow import MFGraph

Expand All @@ -15,7 +16,7 @@ def main() -> None:
def enc(i: int, j: int) -> int:
return i * m + j

def dec(v: int) -> (int, int):
def dec(v: int) -> Tuple[int, int]:
return v // m, v % m

for i in range(n):
Expand Down Expand Up @@ -58,8 +59,8 @@ def dec(v: int) -> (int, int):
grid[i][j] = '>'
grid[ii][jj] = '<'

for s in grid:
print("".join(s))
for r in grid:
print("".join(r))


if __name__ == '__main__':
Expand Down
7 changes: 4 additions & 3 deletions example/mincostflow_practice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://atcoder.jp/contests/practice2/tasks/practice2_e

import sys
from typing import List

from atcoder.mincostflow import MCFGraph

Expand All @@ -12,7 +13,7 @@ def main() -> None:
g = MCFGraph(t + 1)
grid = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
big = 10 ** 9
edges = list([] for _ in range(n))
edges: List[List[int]] = list([] for _ in range(n))
for i in range(n):
g.add_edge(s, i, k, 0)
g.add_edge(i + n, t, k, 0)
Expand All @@ -29,8 +30,8 @@ def main() -> None:
if g.get_edge(edges[i][j]).flow > 0:
result[i][j] = 'X'

for s in result:
print("".join(s))
for r in result:
print("".join(r))


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions example/scc_practice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def main() -> None:
scc = g.scc()

print(len(scc))
for v in scc:
print(len(v), end='')
for x in v:
for c in scc:
print(len(c), end='')
for x in c:
print(f' {x}', end='')
print('')

Expand Down