-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
72 lines (47 loc) · 1.5 KB
/
template.py
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
64
65
66
67
68
69
70
71
72
import numpy as np
from sys import stdin
from collections import deque, defaultdict, Counter
from copy import copy
import functools as fntls
import itertools as ittls
import operator as op
import math
import re
import string
import heapq as q
INF = float('inf')
def solve():
pass
def lines():
return stdin.read().strip().split('\n')
def intgridin():
return [[int(c) for c in r] for r in lines()]
def groups():
return [g.split('\n') for g in stdin.read().strip().split('\n\n')]
def ints(l, _type=int):
# found this code by mserrano in mcpower's utils. thanks
return list(map(_type, re.findall(r"(?:(?<!\d)-)?\d+", l)))
def btwn(v, l, h):
return (v > l and v < h) or (v < l and v > h)
def btwne(v, l, h):
return (v >= l and v <= h) or (v <= l and v >= h)
def btwni(v, l, h):
return v >= l and v < h
def valids(ijl, hii, hij):
for i, j in ijl:
if (btwni(i, -INF if hii == INF else 0, hii)
and btwni(j, -INF if hii == INF else 0, hij)):
yield (i, j)
def neigh4(i, j, hii=INF, hij=INF):
yield from valids([(i - 1, j), \
(i + 1, j), \
(i, j - 1), \
(i, j + 1)], hii, hij)
def neigh8(i, j, hii=INF, hij=INF):
yield from neigh4(i, j, hii, hij)
yield from valids([(i - 1, j - 1), \
(i - 1, j + 1), \
(i + 1, j - 1), \
(i + 1, j + 1)], hii, hij)
if __name__ == '__main__':
solve()