結果

問題 No.2432 Flip and Move
ユーザー ntuda
提出日時 2023-08-19 14:03:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 455 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 160,896 KB
最終ジャッジ日時 2024-11-29 07:17:26
合計ジャッジ時間 10,801 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
K = int(input())
S = [[0] * W for _ in range(H)]

def turn(k):
    x, y = 0, 0
    dx, dy = 1, 1
    cycle = 0
    cnt = 0
    flag = 1
    while flag and cycle < k:
        cycle += 1
        S[x][y] ^= 1
        #print(x,y,S[x][y])
        if S[x][y] == 1:
            cnt+= 1
        else:
            cnt -= 1
        if cnt == 0:
            flag = 0
        if dx == 1:
            if x < H - 1:
                x += 1
            else:
                dx = -1
        else:
            if x > 0:
                x -= 1
            else:
                dx = 1
        if dy == 1:
            if y < W - 1:
                y += 1
            else:
                dy = -1
        else:
            if y > 0:
                y -= 1
            else:
                dy = 1
    return cycle

c = turn(K)
#print(c)
turn(K % c)

for i in range(H):
    print("".join(["." if s == 0 else "#" for s in S[i]]))
0