[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ / Python
๐ Problem Solving/Programmers
https://programmers.co.kr/learn/courses/30/lessons/64061
import sys
input = sys.stdin.readline
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
moves = list(map(int, input().split()))
def solution(board, moves):
basket = []
answer = 0
for i in range(len(moves)):
for j in range(len(board)):
if board[j][moves[i] - 1] == 0:
continue
basket.append(board[j][moves[i] - 1])
board[j][moves[i] - 1] = 0
if len(basket) != 1 and basket[len(basket) - 1] == basket[len(basket) - 2]:
del basket[len(basket) - 1]
del basket[len(basket) - 1]
answer += 2
break
return answer
print(solution(board, moves))
ํด์ค
ํฌ๋ ์ธ์ ์ธ๋ฑ์ค์ ์ธํ์ด ์์นํ๋ฉด ํด๋น ์ธํ ์์น์ ๊ฐ์ 0์ผ๋ก ๋ฐ๊พธ๊ณ ๊ทธ ๊ฐ์ basket์ ๋ฃ์ด์ค๋ค.
์ด๋ basket์ ๋ง์ง๋ง ๊ฐ๊ณผ ๋ฐ๋ก ์ด์ ๊ฐ์ด ๊ฐ์ผ๋ฉด ํด๋น ๋ฐ์ดํฐ๋ฅผ ์ง์์ฃผ๊ณ answer๋ฅผ 2์ฉ ๋๋ ค์ค๋ค.
'๐ Problem Solving > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] ํฐ์ผ๋ชฌ / Python (0) | 2021.06.01 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] ๋ด์ / Python (0) | 2021.06.01 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] K๋ฒ์งธ์ / Python (0) | 2021.06.01 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] ๋ชจ์๊ณ ์ฌ / Python (0) | 2021.06.01 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] ์์ฃผํ์ง ๋ชปํ ์ ์ / Python (0) | 2021.06.01 |