-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.py
More file actions
63 lines (42 loc) · 1.38 KB
/
b.py
File metadata and controls
63 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# https://contest.yandex.ru/contest/22450/run-report/156249691/
from __future__ import annotations
from collections.abc import Iterable
type GridRow = Iterable[int | None]
type Grid = Iterable[GridRow]
def get_max_score(grid: Grid,
*,
min_digit: int = 1,
max_digit: int = 9,
max_keys: int,
players_count: int = 2) -> int:
digits_counter = [0] * (max_digit - min_digit + 1)
for grid_row in grid:
for digit in grid_row:
if digit is not None:
digits_counter[digit - min_digit] += 1
total_max_keys = max_keys * players_count
max_score = sum(
0 < digit_count <= total_max_keys
for digit_count in digits_counter
)
return max_score
def read_int() -> int:
return int(input().strip())
def read_grid(*, width: int, height: int) -> Grid:
for y in range(height):
yield read_grid_row(width=width)
def read_grid_row(*, width: int) -> GridRow:
for char in input().strip()[:width]:
digit: int | None = None
try:
digit = int(char)
except ValueError:
pass
yield digit
def main() -> None:
max_keys = read_int()
grid = read_grid(width=4, height=4)
max_score = get_max_score(grid, max_keys=max_keys)
print(max_score)
if __name__ == '__main__':
main()