結果
問題 | No.608 God's Maze |
ユーザー | mkawa2 |
提出日時 | 2021-12-03 00:56:57 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 1,303 bytes |
コンパイル時間 | 79 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-07-05 03:19:52 |
合計ジャッジ時間 | 4,245 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,880 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 29 ms
10,752 KB |
testcase_03 | AC | 31 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 30 ms
10,752 KB |
testcase_06 | AC | 29 ms
10,752 KB |
testcase_07 | AC | 30 ms
10,880 KB |
testcase_08 | AC | 29 ms
10,752 KB |
testcase_09 | AC | 28 ms
10,880 KB |
testcase_10 | AC | 28 ms
10,752 KB |
testcase_11 | AC | 28 ms
10,880 KB |
testcase_12 | AC | 29 ms
10,880 KB |
testcase_13 | AC | 29 ms
10,752 KB |
testcase_14 | AC | 29 ms
10,752 KB |
testcase_15 | AC | 29 ms
10,752 KB |
testcase_16 | AC | 28 ms
10,752 KB |
testcase_17 | AC | 29 ms
10,880 KB |
testcase_18 | AC | 30 ms
10,880 KB |
testcase_19 | AC | 29 ms
10,752 KB |
testcase_20 | AC | 29 ms
10,752 KB |
testcase_21 | AC | 29 ms
10,624 KB |
testcase_22 | AC | 30 ms
10,752 KB |
testcase_23 | AC | 28 ms
10,752 KB |
testcase_24 | AC | 29 ms
10,880 KB |
testcase_25 | AC | 30 ms
10,752 KB |
testcase_26 | AC | 29 ms
10,752 KB |
testcase_27 | AC | 30 ms
10,752 KB |
testcase_28 | AC | 29 ms
10,880 KB |
testcase_29 | AC | 71 ms
12,416 KB |
testcase_30 | AC | 86 ms
12,416 KB |
testcase_31 | AC | 62 ms
11,904 KB |
testcase_32 | AC | 70 ms
11,904 KB |
testcase_33 | AC | 89 ms
12,544 KB |
testcase_34 | AC | 75 ms
12,160 KB |
testcase_35 | AC | 37 ms
11,136 KB |
testcase_36 | AC | 45 ms
11,136 KB |
testcase_37 | AC | 50 ms
11,264 KB |
testcase_38 | AC | 74 ms
11,864 KB |
testcase_39 | AC | 37 ms
11,008 KB |
testcase_40 | AC | 51 ms
11,520 KB |
testcase_41 | AC | 50 ms
11,520 KB |
testcase_42 | AC | 89 ms
12,544 KB |
testcase_43 | AC | 45 ms
11,136 KB |
testcase_44 | AC | 79 ms
12,032 KB |
testcase_45 | AC | 77 ms
12,160 KB |
testcase_46 | AC | 39 ms
11,136 KB |
testcase_47 | AC | 29 ms
10,752 KB |
testcase_48 | AC | 83 ms
12,032 KB |
testcase_49 | AC | 46 ms
11,264 KB |
testcase_50 | AC | 29 ms
10,752 KB |
testcase_51 | AC | 28 ms
10,752 KB |
testcase_52 | AC | 29 ms
10,624 KB |
testcase_53 | AC | 29 ms
10,752 KB |
testcase_54 | AC | 28 ms
10,880 KB |
testcase_55 | AC | 29 ms
10,880 KB |
testcase_56 | AC | 28 ms
10,752 KB |
testcase_57 | AC | 29 ms
10,752 KB |
testcase_58 | AC | 29 ms
10,624 KB |
testcase_59 | AC | 30 ms
10,752 KB |
testcase_60 | AC | 29 ms
10,880 KB |
testcase_61 | AC | 29 ms
10,880 KB |
testcase_62 | AC | 29 ms
11,008 KB |
testcase_63 | AC | 30 ms
10,752 KB |
testcase_64 | AC | 30 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 solve(aa, si): res = 0 while aa and aa[-1] == 0: aa.pop() if len(aa)-1 < si: return inf l = aa.index(1) if l == si == len(aa)-1: return 3 if l < si: res += si-l for i in range(l, si): aa[i] ^= 1 si = l for i in range(si+1, len(aa)-1): res += 1 aa[i] ^= 1 if aa[i-1]: res += 2 aa[i-1] ^= 1 aa[i] ^= 1 if aa[-2]: res += 2 else: res += 1 return res si = II()-1 aa = [(c == "#")*1 for c in SI()] n = len(aa) if sum(aa) == 0: print(0) exit() ans = min(solve(aa[:], si), solve(aa[::-1], n-1-si)) print(ans)