설명하기 쉽게 하기 위해서, 용어를 통일해서 쓰도록 하겠다. (통일하려고 노력해볼 것이긴 한데 잘 될지는 모르겠다..)
def compute_game(ordered_positions, get_next_positions, is_win_pos=None):
is_win_pos = is_win_pos or {}
for pos in ordered_positions:
is_win_pos[pos] = any(
not is_win_pos[next_pos] for next_pos in get_next_positions(pos)
)
return is_win_posdef get_next_positions(pos):
if pos >= 1:
yield pos - 1
if pos >= 3:
yield pos - 3
if pos >= 4:
yield pos - 4
def main():
N = int(input())
is_win_pos = compute_game(range(1, N + 1), get_next_positions, {0: True})
print('SK' if is_win_pos[N] else 'CY') def main():
N = int(input())
is_win_pos = [True]
for i in range(1, N + 1):
is_win_pos.append(
any(not is_win_pos[i - x] for x in (1, 3, 4) if i - x >= 0)
)
print('SK' if is_win_pos[N] else 'CY') def compute_game(ordered_positions, get_prev_positions, is_win_pos=None):
is_win_pos = is_win_pos or {}
for pos in ordered_positions:
if not is_win_pos[pos]:
for prev_pos in get_prev_positions(pos):
is_win_pos[prev_pos] = True
return is_win_posis_win_pos = [False] * (max_n + 1)
sq_nums = [j * j for j in range(1, math.isqrt(max_n) + 1)]
for i in range(1, max_n + 1):
for sq in sq_nums:
if sq > i:
break
if not is_win_pos[i - sq]:
is_win_pos[i] = True
breakis_win_pos = [False] * (max_n + 1)
sq_nums = [j * j for j in range(1, math.isqrt(max_n) + 1)]
for i in range(max_n + 1):
if not is_win_pos[i]:
for sq in sq_nums:
if i + sq > max_n:
break
is_win_pos[i + sq] = Truemax_score = [None] * (b + 1)
max_score[b] = 0
remaining_score = 0
for i in reversed(range(b)):
if i + 1 in primes:
remaining_score += 1
max_score[i] = remaining_score - min(
max_score[j] for j in range(i + 1, min(i + a, b) + 1)
)
first_score = max_score[0]
second_score = remaining_score - first_scoremax_score = [-INF] * (b + 1)
max_score[b] = 0
for i in reversed(range(b)):
score_gain = 0
for j in range(i + 1, min(i + a, b) + 1):
if j in primes:
score_gain += 1
max_score[i] = max(max_score[i], score_gain - max_score[j])
score_diff = max_score[0]
def is_win_pos_in_wythoff_game(x, y):
x, y = sorted((x, y))
k = math.ceil(x / PHI)
return (int(k * PHI), int(k * PHI_SQ)) != (x, y)
| 문제 | 게임유형 | 필요한 이론 |
|---|---|---|
| | 트리에서 돌 이동 | 트리 dp |
| | 트리에서 돌 이동 | 트리 dp |
| | 트리에서 돌 이동 | 트리 dp |
| | 1xN 그리드에서 돌 이동 | 없음 |
| | 그리드에서 돌 이동 | 홀짝성의 불변성 |
| | 트리에서 돌 이동 | 트리의 특성, 조건 잘 따지기 |
| | 님게임 변형 | 강제수 반복해서 선택지를 빼앗기 |
| | 체스 변형 | 없음. 조건 잘 따지기 |