結果
| 問題 |
No.608 God's Maze
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-28 02:42:38 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 821 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2025-01-02 10:31:22 |
| 合計ジャッジ時間 | 5,033 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 65 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = [int(x) % 2 for x in read().rstrip()]
def solve(S, N):
ret = 0
L = S.index(1)
while N > L:
N -= 1
ret += 1
S[N] ^= 1
if S[N] == 1:
if N == len(S) - 1:
return 3
S[N + 1] ^= 1
S[N] = 0
ret += 2
if sum(S) == 0:
return ret
R = max(n for n, x in enumerate(S) if x == 1)
while N < R:
N += 1
ret += 1
S[N] ^= 1
if S[N] == 1:
if N + 1 == R:
return ret + 2
ret += 2
S[N] = 0
S[N + 1] ^= 1
return ret
print(min(solve(S[:], N - 1), solve(S[::-1], len(S) - N)))
maspy