結果
| 問題 |
No.2432 Flip and Move
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:33:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,471 bytes |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 380,156 KB |
| 最終ジャッジ日時 | 2025-03-20 20:34:33 |
| 合計ジャッジ時間 | 36,695 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 TLE * 2 |
ソースコード
import math
h, w = map(int, input().split())
k = int(input())
def lcm(a, b):
return a * b // math.gcd(a, b)
c = lcm(2 * h, 2 * w)
current_row = 1
current_col = 1
v_dir = 1 # 1 for down, -1 for up
h_dir = 1 # 1 for right, -1 for left
flips_cycle = []
for _ in range(c):
flips_cycle.append((current_row, current_col))
# Process vertical movement
next_row = current_row + v_dir
if 1 <= next_row <= h:
current_row = next_row
else:
v_dir *= -1
# Process horizontal movement
next_col = current_col + h_dir
if 1 <= next_col <= w:
current_col = next_col
else:
h_dir *= -1
q, r = divmod(k, c)
# Compute flips in cycle
flips_in_cycle = {}
for coord in flips_cycle:
if coord in flips_in_cycle:
flips_in_cycle[coord] += 1
else:
flips_in_cycle[coord] = 1
# Compute flips in residual
flips_in_residual = {}
for coord in flips_cycle[:r]:
if coord in flips_in_residual:
flips_in_residual[coord] += 1
else:
flips_in_residual[coord] = 1
# Prepare the grid
grid = [['.' for _ in range(w)] for _ in range(h)]
for i in range(h):
for j in range(w):
coord = (i+1, j+1)
cycle_count = flips_in_cycle.get(coord, 0)
residual_count = flips_in_residual.get(coord, 0)
total_parity = ((cycle_count % 2) * (q % 2) + residual_count % 2) % 2
if total_parity:
grid[i][j] = '#'
for row in grid:
print(''.join(row))
lam6er