ABC解説

AtCoder Beginner Contest 297

A. Double Click

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, d = list(map(int, input().rstrip('\n').split()))
    t = list(map(int, input().rstrip('\n').split()))
    for i in range(1, n):
        if t[i] - t[i-1] <= d:
            print(t[i])
            exit()
    print(-1)


if __name__ == '__main__':
    solve()

B. chess960

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    if s.index("B") % 2 == s.rindex("B") % 2:
        print("No")
    else:
        if s.index("R") < s.index("K") < s.rindex("R"):
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    solve()

C. PC on the Table

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "T" and j < w - 1 and s[i][j + 1] == "T":
                s[i][j] = "P"
                s[i][j + 1] = "C"
    for i in range(h):
        print("".join(s[i]))


if __name__ == '__main__':
    solve()

D. Count Subtractions

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b = list(map(int, input().rstrip('\n').split()))
    ans = 0
    while a != 1 and b != 1 and a != b:
        if a > b:
            dv, md = divmod(a, b)
            ans += dv if md != 0 else dv - 1
            a = md if md != 0 else b
        else:
            dv, md = divmod(b, a)
            ans += dv if md != 0 else dv - 1
            b = md if md != 0 else a
    print(ans + abs(a - b))


if __name__ == '__main__':
    solve()

-ABC解説