- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 58 lines of Python from the credited upstream file abc264_c.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def main():5 from itertools import product6 import sys7 8 input = sys.stdin.readline9 10 h1, w1 = map(int, input().split())11 a = [list(map(int, input().split())) for _ in range(h1)]12 h2, w2 = map(int, input().split())13 b = [list(map(int, input().split())) for _ in range(h2)]14 15 rows = list(product([0, 1], repeat=h1))16 cols = list(product([0, 1], repeat=w1))17 18 for row in rows:19 if sum(row) != h2:20 continue21 22 for col in cols:23 if sum(col) != w2:24 continue25 26 c = list()27 28 for i, ri in enumerate(row):29 if ri == 0:30 continue31 32 tmp = list()33 34 for j, cj in enumerate(col):35 if cj == 0:36 continue37 38 tmp.append(a[i][j])39 40 c.append(tmp)41 42 count = 043 44 for i in range(h2):45 for j in range(w2):46 if c[i][j] == b[i][j]:47 count += 148 49 if count == h2 * w2:50 print("Yes")51 exit()52 53 print("No")54 55 56if __name__ == "__main__":57 main()58