結果
問題 | No.608 God's Maze |
ユーザー | mkawa2 |
提出日時 | 2021-12-03 00:53:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,459 bytes |
コンパイル時間 | 78 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-05 03:16:40 |
合計ジャッジ時間 | 4,193 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 30 ms
10,752 KB |
testcase_02 | AC | 32 ms
10,752 KB |
testcase_03 | AC | 32 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 29 ms
10,752 KB |
testcase_06 | AC | 29 ms
10,752 KB |
testcase_07 | WA | - |
testcase_08 | AC | 29 ms
10,752 KB |
testcase_09 | AC | 29 ms
10,752 KB |
testcase_10 | AC | 29 ms
10,752 KB |
testcase_11 | AC | 30 ms
10,880 KB |
testcase_12 | AC | 29 ms
10,752 KB |
testcase_13 | AC | 30 ms
10,880 KB |
testcase_14 | AC | 30 ms
10,880 KB |
testcase_15 | AC | 30 ms
10,880 KB |
testcase_16 | AC | 29 ms
10,752 KB |
testcase_17 | AC | 29 ms
10,880 KB |
testcase_18 | AC | 29 ms
10,752 KB |
testcase_19 | AC | 28 ms
10,752 KB |
testcase_20 | AC | 30 ms
10,880 KB |
testcase_21 | AC | 29 ms
10,752 KB |
testcase_22 | AC | 30 ms
10,880 KB |
testcase_23 | AC | 29 ms
10,752 KB |
testcase_24 | AC | 29 ms
10,880 KB |
testcase_25 | AC | 30 ms
10,880 KB |
testcase_26 | AC | 30 ms
10,752 KB |
testcase_27 | AC | 30 ms
10,880 KB |
testcase_28 | AC | 30 ms
10,752 KB |
testcase_29 | WA | - |
testcase_30 | AC | 83 ms
12,412 KB |
testcase_31 | AC | 61 ms
11,904 KB |
testcase_32 | AC | 68 ms
12,284 KB |
testcase_33 | AC | 87 ms
12,416 KB |
testcase_34 | AC | 74 ms
12,288 KB |
testcase_35 | AC | 37 ms
11,264 KB |
testcase_36 | AC | 45 ms
11,392 KB |
testcase_37 | AC | 50 ms
11,392 KB |
testcase_38 | AC | 71 ms
12,032 KB |
testcase_39 | AC | 36 ms
11,008 KB |
testcase_40 | AC | 51 ms
11,776 KB |
testcase_41 | AC | 48 ms
11,392 KB |
testcase_42 | AC | 86 ms
12,416 KB |
testcase_43 | AC | 45 ms
11,520 KB |
testcase_44 | AC | 78 ms
12,288 KB |
testcase_45 | AC | 77 ms
12,160 KB |
testcase_46 | AC | 39 ms
11,008 KB |
testcase_47 | AC | 31 ms
11,008 KB |
testcase_48 | AC | 80 ms
12,416 KB |
testcase_49 | AC | 45 ms
11,392 KB |
testcase_50 | AC | 29 ms
10,880 KB |
testcase_51 | WA | - |
testcase_52 | AC | 29 ms
10,752 KB |
testcase_53 | AC | 29 ms
10,880 KB |
testcase_54 | AC | 29 ms
10,752 KB |
testcase_55 | AC | 29 ms
10,752 KB |
testcase_56 | AC | 28 ms
10,752 KB |
testcase_57 | AC | 30 ms
10,752 KB |
testcase_58 | WA | - |
testcase_59 | AC | 29 ms
10,880 KB |
testcase_60 | AC | 29 ms
10,752 KB |
testcase_61 | AC | 29 ms
10,880 KB |
testcase_62 | AC | 28 ms
10,752 KB |
testcase_63 | AC | 29 ms
10,880 KB |
testcase_64 | AC | 29 ms
10,880 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 == r == si: return 3 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)