- 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
- 51 lines of Python from the credited upstream file abc375_c.py.
- The implementation visibly relies on sequence storage.
- 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 3from typing import List4 5 678def rotate_90_degrees_to_right(array: List[List]):9 return [list(ai)[::-1] for ai in zip(*array)]10 11 12def main():13 import sys14 15 input = sys.stdin.readline16 17 n = int(input())18 s = [list(input().rstrip()) for _ in range(n)]19 20 21 s90 = rotate_90_degrees_to_right(s[:])22 s180 = rotate_90_degrees_to_right(s90[:])23 s270 = rotate_90_degrees_to_right(s180[:])24 ans = [[""] * n for _ in range(n)]25 26 def write(k, grid):27 for j in range(k, n - k):28 ans[k][j] = grid[k][j]29 ans[n - k - 1][j] = grid[n - k - 1][j]30 ans[j][k] = grid[j][k]31 ans[j][n - k - 1] = grid[j][n - k - 1]32 33 for i in range(1, n 2 + 1):34 i2 = i - 135 36 if i % 4 == 1:37 write(i2, s90)38 elif i % 4 == 2:39 write(i2, s180)40 elif i % 4 == 3:41 write(i2, s270)42 else:43 write(i2, s)44 45 for ans_i in ans:46 print("".join(ans_i))47 48 49if __name__ == "__main__":50 main()51