結果

問題 No.608 God's Maze
ユーザー mkawa2mkawa2
提出日時 2021-12-03 00:29:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,265 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 9,740 KB
最終ジャッジ日時 2023-09-18 11:51:11
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,148 KB
testcase_01 AC 16 ms
8,032 KB
testcase_02 AC 17 ms
8,016 KB
testcase_03 AC 16 ms
8,076 KB
testcase_04 AC 17 ms
8,036 KB
testcase_05 AC 16 ms
7,960 KB
testcase_06 AC 17 ms
8,008 KB
testcase_07 AC 17 ms
8,004 KB
testcase_08 AC 16 ms
7,964 KB
testcase_09 AC 16 ms
8,036 KB
testcase_10 AC 16 ms
7,956 KB
testcase_11 AC 16 ms
8,016 KB
testcase_12 AC 16 ms
7,960 KB
testcase_13 AC 16 ms
7,964 KB
testcase_14 AC 16 ms
8,080 KB
testcase_15 AC 17 ms
8,148 KB
testcase_16 AC 16 ms
8,140 KB
testcase_17 AC 16 ms
8,008 KB
testcase_18 AC 17 ms
8,136 KB
testcase_19 AC 17 ms
7,976 KB
testcase_20 AC 16 ms
8,144 KB
testcase_21 AC 17 ms
8,084 KB
testcase_22 AC 16 ms
8,004 KB
testcase_23 AC 17 ms
8,076 KB
testcase_24 AC 16 ms
7,964 KB
testcase_25 AC 16 ms
8,008 KB
testcase_26 AC 16 ms
8,080 KB
testcase_27 AC 17 ms
7,960 KB
testcase_28 AC 17 ms
8,136 KB
testcase_29 AC 52 ms
9,656 KB
testcase_30 AC 64 ms
9,584 KB
testcase_31 AC 43 ms
8,980 KB
testcase_32 AC 52 ms
9,188 KB
testcase_33 AC 67 ms
9,684 KB
testcase_34 AC 55 ms
9,560 KB
testcase_35 AC 24 ms
8,504 KB
testcase_36 AC 31 ms
8,688 KB
testcase_37 AC 33 ms
8,704 KB
testcase_38 AC 53 ms
9,440 KB
testcase_39 AC 23 ms
8,588 KB
testcase_40 AC 35 ms
8,848 KB
testcase_41 AC 34 ms
8,664 KB
testcase_42 AC 67 ms
9,740 KB
testcase_43 AC 31 ms
8,576 KB
testcase_44 AC 59 ms
9,616 KB
testcase_45 AC 58 ms
9,460 KB
testcase_46 AC 25 ms
8,640 KB
testcase_47 AC 16 ms
8,008 KB
testcase_48 AC 61 ms
9,644 KB
testcase_49 AC 30 ms
8,680 KB
testcase_50 AC 16 ms
8,140 KB
testcase_51 RE -
testcase_52 AC 16 ms
8,084 KB
testcase_53 AC 16 ms
8,016 KB
testcase_54 AC 16 ms
8,076 KB
testcase_55 AC 17 ms
8,136 KB
testcase_56 AC 16 ms
8,024 KB
testcase_57 AC 17 ms
7,960 KB
testcase_58 AC 17 ms
8,008 KB
testcase_59 AC 16 ms
8,080 KB
testcase_60 AC 16 ms
7,960 KB
testcase_61 AC 17 ms
8,104 KB
testcase_62 AC 17 ms
8,008 KB
testcase_63 AC 17 ms
8,136 KB
testcase_64 AC 17 ms
8,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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:
        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)
0