結果
問題 | No.608 God's Maze |
ユーザー | mkawa2 |
提出日時 | 2021-12-03 00:47:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,429 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 71,040 KB |
最終ジャッジ日時 | 2024-07-05 03:10:20 |
合計ジャッジ時間 | 5,582 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 43 ms
52,352 KB |
testcase_02 | AC | 42 ms
52,096 KB |
testcase_03 | AC | 40 ms
52,480 KB |
testcase_04 | AC | 43 ms
52,352 KB |
testcase_05 | AC | 42 ms
52,096 KB |
testcase_06 | AC | 44 ms
51,968 KB |
testcase_07 | WA | - |
testcase_08 | AC | 44 ms
52,352 KB |
testcase_09 | AC | 43 ms
52,608 KB |
testcase_10 | AC | 45 ms
51,968 KB |
testcase_11 | AC | 43 ms
52,096 KB |
testcase_12 | AC | 43 ms
52,096 KB |
testcase_13 | AC | 42 ms
52,096 KB |
testcase_14 | AC | 42 ms
52,560 KB |
testcase_15 | AC | 43 ms
52,224 KB |
testcase_16 | AC | 43 ms
52,352 KB |
testcase_17 | AC | 43 ms
51,968 KB |
testcase_18 | AC | 43 ms
52,608 KB |
testcase_19 | AC | 42 ms
52,608 KB |
testcase_20 | AC | 41 ms
52,352 KB |
testcase_21 | AC | 40 ms
52,096 KB |
testcase_22 | AC | 40 ms
52,096 KB |
testcase_23 | AC | 40 ms
51,968 KB |
testcase_24 | AC | 40 ms
51,888 KB |
testcase_25 | AC | 41 ms
52,224 KB |
testcase_26 | AC | 40 ms
52,480 KB |
testcase_27 | AC | 40 ms
52,096 KB |
testcase_28 | AC | 39 ms
52,736 KB |
testcase_29 | WA | - |
testcase_30 | AC | 56 ms
65,612 KB |
testcase_31 | AC | 54 ms
66,688 KB |
testcase_32 | AC | 53 ms
64,512 KB |
testcase_33 | AC | 59 ms
71,040 KB |
testcase_34 | AC | 58 ms
68,992 KB |
testcase_35 | AC | 54 ms
60,928 KB |
testcase_36 | AC | 56 ms
62,720 KB |
testcase_37 | AC | 58 ms
64,256 KB |
testcase_38 | AC | 59 ms
64,768 KB |
testcase_39 | AC | 57 ms
63,488 KB |
testcase_40 | AC | 55 ms
62,848 KB |
testcase_41 | AC | 57 ms
62,676 KB |
testcase_42 | AC | 62 ms
66,304 KB |
testcase_43 | AC | 60 ms
64,640 KB |
testcase_44 | AC | 61 ms
65,920 KB |
testcase_45 | AC | 66 ms
69,776 KB |
testcase_46 | AC | 57 ms
63,104 KB |
testcase_47 | AC | 46 ms
58,444 KB |
testcase_48 | AC | 66 ms
69,888 KB |
testcase_49 | AC | 60 ms
64,128 KB |
testcase_50 | AC | 41 ms
52,608 KB |
testcase_51 | WA | - |
testcase_52 | AC | 41 ms
52,352 KB |
testcase_53 | AC | 42 ms
52,352 KB |
testcase_54 | AC | 41 ms
51,840 KB |
testcase_55 | AC | 40 ms
52,096 KB |
testcase_56 | AC | 41 ms
52,096 KB |
testcase_57 | AC | 41 ms
52,096 KB |
testcase_58 | WA | - |
testcase_59 | AC | 41 ms
52,224 KB |
testcase_60 | AC | 42 ms
52,096 KB |
testcase_61 | AC | 42 ms
52,096 KB |
testcase_62 | AC | 42 ms
52,480 KB |
testcase_63 | AC | 41 ms
52,480 KB |
testcase_64 | AC | 41 ms
51,968 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 # md = 10**9+7 md = 998244353 def rindex(aa, v): for i in range(len(aa))[::-1]: if aa[i] == v: return i return -1 def solve(aa, si): res = -1 if len(aa)-1 < si: return inf l = aa.index(1) r = rindex(aa, 1) if l < si: res += si-l for i in range(l, si): aa[i] ^= 1 si = l aa[si] ^= 1 for i in range(si, r): if i == r and aa[i] == 0: break res += 1 aa[i] ^= 1 if aa[i]: aa[i] ^= 1 aa[i+1] ^= 1 res += 2 if aa[r]: res += 1 return res si = II()-1 aa = [(c == "#")*1 for c in SI()] n = len(aa) s = sum(aa) if s == 0: print(0) exit() if s == 1: i = aa.index(1) print(abs(si-i)) exit() ans = min(solve(aa[:], si), solve(aa[::-1], n-1-si)) print(ans)