Skip to content

BOJ2644_돌_게임_실버5_조재은 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
n = int(input())

# 각 상태에 대해 승리 여부를 저장하는 배열
# 초기값은 -1로 설정(미정)
win = [-1] * (n+1)

# 초기 상태 설정
# 1개의 돌이 남았을 때는 현재 플레이어가 승리(SK)
# 2개의 돌이 남았을 때는 다음 플레이어가 승리(CY), 현재 플레이어는 패배
# 3개의 돌이 남았을 때는 현재 플레이어가 승리(SK)
win[1] = 1 # SK 승리
win[2] = 0 # CY 승리
win[3] = 1 # SK 승리

# 동적 프로그래밍을 사용하여 나머지 상태 계산
for i in range(4, n+1):
# 현재 플레이어가 이기는 조건:
# 이전 상태(i-1 또는 i-3) 중 하나라도 다음 플레이어가 이기는 경우(= 현재 플레이어가 해당 돌을 가져가면 승리)
if win[i-1] == 0 or win[i-3] == 0:
win[i] = 1 # 현재 플레이어(SK) 승리
else:
win[i] = 0 # 다음 플레이어(CY) 승리

# 결과 출력
if win[n] == 1:
print("SK")
else:
print("CY")