結果
問題 |
No.2432 Flip and Move
|
ユーザー |
![]() |
提出日時 | 2025-04-16 01:07:37 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,919 bytes |
コンパイル時間 | 636 ms |
コンパイル使用メモリ | 81,376 KB |
実行使用メモリ | 739,640 KB |
最終ジャッジ日時 | 2025-04-16 01:09:51 |
合計ジャッジ時間 | 43,247 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 TLE * 6 MLE * 6 |
ソースコード
H, W = map(int, input().split()) K = int(input()) i, j = 1, 1 dv = 1 # down direction (1 for down, -1 for up) dh = 1 # right direction (1 for right, -1 for left) state_map = {} path = [] current_step = 0 cycle_found = False start_step = 0 cycle_length = 0 while current_step < K: state = (i, j, dv, dh) if state in state_map: start_step = state_map[state] cycle_length = current_step - start_step cycle_found = True break state_map[state] = current_step path.append((i - 1, j - 1)) # Convert to 0-based indices # Move vertically new_i = i + dv if 1 <= new_i <= H: i = new_i else: dv *= -1 # Move horizontally new_j = j + dh if 1 <= new_j <= W: j = new_j else: dh *= -1 current_step += 1 if not cycle_found: # All steps are in the initial path grid = [[0 for _ in range(W)] for _ in range(H)] for x, y in path[:K]: grid[x][y] += 1 else: initial_steps = start_step cycle_steps = cycle_length total_cycles = (K - initial_steps) // cycle_steps remainder_steps = (K - initial_steps) % cycle_steps initial_path = path[:initial_steps] cycle_path = path[initial_steps: initial_steps + cycle_steps] remainder_path = cycle_path[:remainder_steps] grid = [[0 for _ in range(W)] for _ in range(H)] # Count initial steps for x, y in initial_path: grid[x][y] += 1 # Count cycles cycle_counts = [[0 for _ in range(W)] for _ in range(H)] for x, y in cycle_path: cycle_counts[x][y] += 1 for x in range(H): for y in range(W): grid[x][y] += cycle_counts[x][y] * total_cycles # Count remainder steps for x, y in remainder_path: grid[x][y] += 1 # Generate the output for row in grid: print(''.join(['#' if cnt % 2 else '.' for cnt in row]))