Approach
Sorting and greedy selection
For ABC312 B — TaK Code, the implementation first exposes a useful order, then scans that order while making locally justified choices.
- Choose the key that reveals the greedy or grouping structure.
- Sort the relevant records by that key.
- Scan in order, maintaining the invariant that makes each local choice safe.
Code notes
- 57 lines of Python from the credited upstream file abc312_b.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Sorting is typically the dominant term unless the subsequent scan uses a more expensive nested operation.
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 import sys6 7 input = sys.stdin.readline8 9 t = [10 "###.?????",11 "###.?????",12 "###.?????",13 "....?????",14 "?????????",15 "?????....",16 "?????.###",17 "?????.###",18 "?????.###",19 ]20 21 n, m = map(int, input().split())22 s = [list(input().rstrip()) for _ in range(n)]23 ans = list()24 25 for i in range(n):26 if i + 9 > n:27 continue28 29 for j in range(m):30 if j + 9 > m:31 continue32 33 flag = True34 35 36 for y in range(9):37 for x in range(9):38 if t[y][x] == "?":39 continue40 41 if s[i + y][j + x] != t[y][x]:42 flag = False43 break44 45 46 if flag:47 ans.append((i + 1, j + 1))48 49 50 51 for i, j in sorted(ans):52 print(i, j)53 54 55if __name__ == "__main__":56 main()57