結果

問題 No.2432 Flip and Move
ユーザー chineristACchineristAC
提出日時 2023-08-18 23:14:16
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,829 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 517,308 KB
最終ジャッジ日時 2024-05-06 05:51:31
合計ジャッジ時間 17,862 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,992 KB
testcase_01 AC 41 ms
52,864 KB
testcase_02 AC 376 ms
249,496 KB
testcase_03 MLE -
testcase_04 AC 124 ms
107,648 KB
testcase_05 AC 126 ms
108,032 KB
testcase_06 AC 177 ms
132,820 KB
testcase_07 AC 867 ms
375,296 KB
testcase_08 AC 1,062 ms
401,340 KB
testcase_09 AC 1,536 ms
511,896 KB
testcase_10 AC 256 ms
194,832 KB
testcase_11 AC 310 ms
195,512 KB
testcase_12 AC 264 ms
169,560 KB
testcase_13 AC 215 ms
155,616 KB
testcase_14 AC 310 ms
198,912 KB
testcase_15 AC 1,214 ms
473,264 KB
testcase_16 AC 276 ms
152,448 KB
testcase_17 AC 486 ms
229,476 KB
testcase_18 AC 190 ms
134,912 KB
testcase_19 AC 375 ms
199,900 KB
testcase_20 AC 492 ms
226,076 KB
testcase_21 AC 403 ms
187,064 KB
testcase_22 AC 385 ms
200,696 KB
testcase_23 AC 182 ms
126,464 KB
testcase_24 AC 489 ms
215,168 KB
testcase_25 AC 361 ms
206,700 KB
testcase_26 AC 290 ms
181,044 KB
testcase_27 AC 94 ms
83,072 KB
testcase_28 AC 109 ms
80,512 KB
testcase_29 AC 419 ms
186,344 KB
testcase_30 AC 502 ms
247,824 KB
testcase_31 AC 285 ms
157,672 KB
testcase_32 AC 107 ms
89,984 KB
testcase_33 AC 471 ms
233,908 KB
testcase_34 AC 278 ms
146,304 KB
testcase_35 AC 203 ms
129,920 KB
testcase_36 AC 46 ms
52,992 KB
testcase_37 AC 39 ms
53,120 KB
testcase_38 AC 39 ms
53,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import *

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = self.segfunc(self.tree[k],x)
        while k > 1:
            k >>= 1
            self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1])

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

H,W = mi()
K = int(input())

visit = [[[0]*W for i in range(H)] for d in range(4)]
visit[0][0][0] = 0

trail = [(0,0)]
loop_l = -1
while True:
    d,pos = trail[-1]
    h,w = pos//W,pos % W

    if d & 1 == 0:
        if h+1 < H:
            h += 1
        else:
            d ^= 1
    else:
        if 0 <= h-1:
            h -= 1
        else:
            d ^= 1

    if d & 2 == 0:
        if w+1 < W:
            w += 1
        else:
            d ^= 2
    else:
        if 0 <= w-1:
            w -= 1
        else:
            d ^= 2
    
    if visit[d][h][w] == 0:
        visit[d][h][w] = 1
        trail.append((d,h*W+w))
    else:
        loop_l = trail.index((d,h*W+w))
        break

assert len(trail) <= 4 * H * W

if K <= len(trail):
    res = [[0]*W for i in range(H)]
    for d,pos in trail[:K]:
        h,w = pos//W,pos % W
        res[h][w] ^= 1

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


L = len(trail) - loop_l
loop_cnt = (K-loop_l) // L

for i in range(H):
    for j in range(W):
        visit[0][i][j] = 0
res = visit[0]

for d,pos in trail[:loop_l]:
    h,w = pos//W,pos%W
    res[h][w] ^= 1
for d,pos in trail[loop_l:]:
    h,w = pos//W,pos%W
    if L & 1:
        res[h][w] ^= 1
for d,pos in trail[loop_l:loop_l+((K-loop_l)%L)]:
    h,w = pos//W,pos%W
    res[h][w] ^= 1

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