Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/16897
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
N*M 크기의 체스판 위 (1,1) 지점에 말이 하나 놓여 있다.
말은 한 번의 이동에서 오른쪽으로 한 칸, 아래로 한 칸, 오른쪽 아래 방향으로 K칸 이동할 수 있다.
두 사람이 번갈아가며 말을 이동시키며, 말을 더 이상 이동시킬 수 없는 사람이 진다.
누가 이기는지 구해보자.
🔍 풀이 방법
어떤 칸이 (N, M)으로부터 떨어진 행, 열의 수를 각각 x, y라 하고, 이 상태에서 선공이 이기는지 여부를 g[x][y]라 둔다.
g[x][y] = 1이면 선공 승, 0이면 후공 승이다.
K = 1일 때는 반드시 g[x][y] = (x&1) | (y&1) 이다.
따라서 K = 1이 아닐 때만 생각한다.
z = min(x,y) / (K+1)로 두면, g[x][y] = g[x-z(K+1)][y-z(K+1)] 이다.
이제 두 가지 경우로 나뉜다.
g[x][y]가 0이면 후공이 승리하고, 0이 아니면 선공이 승리한다.
⏳ 회고
ez