-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2138.py
More file actions
55 lines (45 loc) · 973 Bytes
/
2138.py
File metadata and controls
55 lines (45 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
input = sys.stdin.readline
def switch(i):
global xor_bulbs
xor_bulbs[i] ^= 1
if i - 1 >= 0:
xor_bulbs[i - 1] ^= 1
if i + 1 < n:
xor_bulbs[i + 1] ^= 1
def check():
for i in range(n):
if xor_bulbs[i] == 1:
return False
return True
n = int(input())
bulbs = list(map(int, input().rstrip()))
target = list(map(int, input().rstrip()))
xor_bulbs = [0] * n
for i in range(n):
xor_bulbs[i] = bulbs[i] ^ target[i]
# 첫 번째 스위치를 고정
answer = 0
if xor_bulbs[0] == 1:
answer += 1
switch(1)
for i in range(2, n):
if xor_bulbs[i - 1] == 1:
answer += 1
switch(i)
if check():
print(answer)
exit()
for i in range(n):
xor_bulbs[i] = bulbs[i] ^ target[i]
# 첫 번째 스위치를 켰을 때
switch(0)
answer = 1
for i in range(1, n):
if xor_bulbs[i - 1] == 1:
answer += 1
switch(i)
if check():
print(answer)
else:
print(-1)