목차

Crimson Sexy Jalapeños

ps
링크acmicpc.net/…
출처BOJ
문제 번호18174
문제명Crimson Sexy Jalapeños
레벨플래티넘 3
분류

게임 이론

시간복잡도O(n+m+k)
인풋사이즈n<=10^4, m<=10^4, k<=100
사용한 언어Python 3.11
제출기록13812KB / 4272ms
최고기록684ms
해결날짜2023/07/14

풀이

코드

"""Solution code for "BOJ 18174. Crimson Sexy Jalapeños".

- Problem link: https://www.acmicpc.net/problem/18174
- Solution link: http://www.teferi.net/ps/problems/boj/18174

Tags: [game theory]
"""

import functools
import operator
import sys


def main():
    R, C, K = [int(x) for x in sys.stdin.readline().split()]
    coords = [[int(x) for x in sys.stdin.readline().split()] for _ in range(K)]

    nums = {
        'left': min(c for r, c in coords) - 1,
        'right': C - max(c for r, c in coords),
        'top': min(r for r, c in coords) - 1,
        'bottom': R - max(r for r, c in coords),
    }

    g = functools.reduce(operator.xor, nums.values())
    if g == 0:
        print('pass')
    else:
        direc, num = next(x for x in nums.items() if g ^ x[1] < x[1])
        nums[direc] = g ^ num
        print(direc, num - nums[direc])
    sys.stdout.flush()

    while (line := sys.stdin.readline().rstrip()) != 'yuck!':
        direc, num = line.split()
        g = nums[direc] ^ (nums[direc] - int(num))
        nums[direc] -= int(num)

        direc, num = next(x for x in nums.items() if g ^ x[1] < x[1])
        nums[direc] = g ^ num
        print(direc, num - nums[direc])
        sys.stdout.flush()


if __name__ == '__main__':
    main()