목차

궁전 게임

ps
링크acmicpc.net/…
출처BOJ
문제 번호16879
문제명궁전 게임
레벨플래티넘 1
분류

스프라그-그런디

시간복잡도O(n)
인풋사이즈n<=300,000
사용한 언어Python
제출기록30840KB / 400ms
최고기록400ms
해결날짜2022/06/07

풀이

코드

"""Solution code for "BOJ 16879. 궁전 게임".

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

Tags: [Sprague-Grundy]
"""

import sys


def main():
    N = int(sys.stdin.readline())
    grundy_num = 0
    for _ in range(N):
        x, y = [int(x) for x in sys.stdin.readline().split()]
        grundy_num ^= ((x // 3) ^ (y // 3)) * 3 + (x + y) % 3
    print('koosaga' if grundy_num else 'cubelover')


if __name__ == '__main__':
    main()