結果
問題 | No.2432 Flip and Move |
ユーザー | chineristAC |
提出日時 | 2023-08-18 23:20:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 734 ms / 2,000 ms |
コード長 | 2,835 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 293,472 KB |
最終ジャッジ日時 | 2024-11-28 10:23:21 |
合計ジャッジ時間 | 13,136 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,992 KB |
testcase_01 | AC | 40 ms
53,248 KB |
testcase_02 | AC | 351 ms
225,612 KB |
testcase_03 | AC | 734 ms
293,472 KB |
testcase_04 | AC | 104 ms
83,968 KB |
testcase_05 | AC | 98 ms
84,096 KB |
testcase_06 | AC | 167 ms
119,500 KB |
testcase_07 | AC | 442 ms
244,652 KB |
testcase_08 | AC | 460 ms
225,884 KB |
testcase_09 | AC | 604 ms
272,216 KB |
testcase_10 | AC | 232 ms
180,240 KB |
testcase_11 | AC | 285 ms
179,044 KB |
testcase_12 | AC | 205 ms
156,872 KB |
testcase_13 | AC | 193 ms
138,416 KB |
testcase_14 | AC | 223 ms
144,512 KB |
testcase_15 | AC | 532 ms
267,688 KB |
testcase_16 | AC | 237 ms
160,596 KB |
testcase_17 | AC | 409 ms
207,876 KB |
testcase_18 | AC | 173 ms
121,180 KB |
testcase_19 | AC | 326 ms
168,648 KB |
testcase_20 | AC | 446 ms
213,132 KB |
testcase_21 | AC | 358 ms
170,480 KB |
testcase_22 | AC | 344 ms
180,004 KB |
testcase_23 | AC | 176 ms
112,420 KB |
testcase_24 | AC | 480 ms
208,628 KB |
testcase_25 | AC | 388 ms
175,100 KB |
testcase_26 | AC | 314 ms
162,432 KB |
testcase_27 | AC | 88 ms
77,056 KB |
testcase_28 | AC | 97 ms
79,616 KB |
testcase_29 | AC | 333 ms
172,408 KB |
testcase_30 | AC | 424 ms
219,104 KB |
testcase_31 | AC | 225 ms
154,232 KB |
testcase_32 | AC | 117 ms
90,240 KB |
testcase_33 | AC | 423 ms
218,012 KB |
testcase_34 | AC | 234 ms
172,092 KB |
testcase_35 | AC | 186 ms
117,840 KB |
testcase_36 | AC | 38 ms
52,480 KB |
testcase_37 | AC | 44 ms
53,120 KB |
testcase_38 | AC | 46 ms
53,248 KB |
ソースコード
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)] visit[0][0] = 1 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[h][w] >> d) & 1 == 0: visit[h][w] ^= 1<<d trail.append((d,h*W+w)) else: loop_l = trail.index((d,h*W+w)) break if K <= len(trail): for i in range(H): for j in range(W): visit[i][j] = 0 res = visit 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[i][j] = 0 res = visit 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)