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()