목차

턴 게임

ps
링크acmicpc.net/…
출처BOJ
문제 번호12934
문제명턴 게임
레벨골드 5
분류

그리디

시간복잡도O(1)
사용한 언어Python
제출기록32976KB / 72ms
최고기록56ms
해결날짜2022/01/31

풀이

코드

"""Solution code for "BOJ 12934. 턴 게임".

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

Tags: [Greedy]
"""

import math


def main():
    x, y = [int(x) for x in input().split()]

    max_turn = (math.isqrt(8 * (x + y) + 1) - 1) // 2
    if (max_turn + 1) * max_turn // 2 != x + y:
        answer = -1
    elif x == 0:
        answer = 0
    else:
        t = max_turn * 2 - 1
        answer = math.ceil((t - (t * t + 8 * (max_turn - x))**0.5) / 2) + 1

    print(answer)


if __name__ == '__main__':
    main()