Skip to content

Commit

Permalink
Merge pull request #29 from AlgoLeadMe/9-alstjr7437
Browse files Browse the repository at this point in the history
9-alstjr7437
  • Loading branch information
alstjr7437 authored Feb 20, 2024
2 parents db22a6a + 30f3dc6 commit b4ade6a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
| 6์ฐจ์‹œ | 2024.01.30 | ๊ทธ๋ฆฌ๋”” | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150369">ํƒ๋ฐฐ ๋ฐฐ๋‹ฌ๊ณผ ์ˆ˜๊ฑฐํ•˜๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/17 |
| 7์ฐจ์‹œ | 2024.02.08 | ์Šคํƒ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/12909">์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/22 |
| 8์ฐจ์‹œ | 2024.02.14 | DP | <a href="https://www.acmicpc.net/problem/12865">ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/24 |
| 9์ฐจ์‹œ | 2024.02.17 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/2138">์ „๊ตฌ์™€ ์Šค์œ„์น˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/29 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def solution(first, target, count):
# ์ฒซ๋ฒˆ์งธ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅธ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
if count == 1:
first[0] = 1 - first[0]
first[1] = 1 - first[1]
# ๋ฒ„ํŠผ ์ˆœํšŒ
for i in range(1,n):
if first[i-1] == target[i-1]: # ๋ฐ”๊ฟ”์•ผํ•˜๋Š”์ง€ ๋น„๊ต
continue
count += 1
for j in range(i-1, i+2): # 1๋ฒˆ์ด๋ฉด 0~2๋ฒˆ๊นŒ์ง€ ์ „๊ตฌ ๋ฐ”๊พธ๊ธฐ
if j < n: # n์ด 3์ผ๋•Œ 3์„ ๋ˆ„๋ฅด๋ฉด 2,3๋งŒ ๋˜๋„๋ก
first[j] = 1 - first[j]
if first == target:
return count
else :
return -1

n = int(input())
first = list(map(int, input()))
target = list(map(int, input()))

# ์ฒซ๋ฒˆ์งธ ์ „๊ตฌ์˜ ์Šค์œ„์น˜๋ฅผ ๋ˆ„๋ฅด๋Š” ๊ฒฝ์šฐ
result1 = solution(first[:], target, 1)
# ์ฒซ๋ฒˆ์งธ ์ „๊ตฌ์˜ ์Šค์œ„์น˜๋ฅผ ๋ˆ„๋ฅด์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
result2 = solution(first[:], target, 0)

if result1 == -1:
print(result2)
elif result2 == -1:
print(result1)
else :
print(min(result1, result2))

0 comments on commit b4ade6a

Please sign in to comment.