문제 링크: https://www.acmicpc.net/problem/2138
백준 알고리즘 중급 1/3 710에서 5번째 - 2138번 전구와 스위치를 풀어보았다.
풀이: https://dogsavestheworld.tistory.com/137
C++
Python
n=int(input())
b=list(map(int, input()))
target=list(map(int, input()))
def change(A, B):
L = A[:]
press = 0
for i in range(1, n):
if L[i-1] == B[i-1]:
continue
press += 1
for j in range(i-1, i+2):
if j<n:
L[j] = 1 - L[j]
return press if L == B else 1e9
res=change(b, target)
b[0]=1-b[0]
b[1]=1-b[1]
res=min(res,change(b,target)+1)
print(res if res!=1e9 else-1)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
행렬 풀이 (0) | 2023.03.04 |
---|---|
ATM 풀이 (0) | 2023.03.04 |
회의실 배정 풀이 (1) | 2023.03.04 |
동전 0 풀이 (0) | 2023.03.04 |
4연산 풀이 (0) | 2023.03.04 |