ABC解説

トヨタ自動車プログラミングコンテスト2023#2(AtCoder Beginner Contest 302)

A. Attack

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b = list(map(int, input().rstrip('\n').split()))
    print((a + b - 1) // b)


if __name__ == '__main__':
    solve()

B. Find snuke

import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(n)]
    for v in itertools.permutations(s, n):
        is_ok = True
        for i in range(1, n):
            cnt = 0
            for j in range(m):
                if v[i][j] != v[i-1][j]:
                    cnt += 1
            if cnt != 1:
                is_ok = False
        if is_ok:
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    solve()

C. Almost Equal

import sys
import bisect


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m, d = list(map(int, input().rstrip('\n').split()))
    a = sorted(list(map(int, input().rstrip('\n').split())))
    b = sorted(list(map(int, input().rstrip('\n').split())))
    ans = -1
    for i in range(n):
        pos = bisect.bisect_right(b, a[i] + d)
        if pos != 0:
            if abs(b[pos-1] - a[i]) <= d:
                ans = max(ans, b[pos-1] + a[i])
    print(ans)


if __name__ == '__main__':
    solve()

D. Impartial Gift

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 "".join([s[i+k][j] if 0 <= i + k < h else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i + k + 1, j + 1)
            if "".join([s[i][j+k] if 0 <= j + k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i + 1, j + k + 1)
            if "".join([s[i-k][j] if 0 <= i - k < h else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i - k + 1, j + 1)
            if "".join([s[i][j-k] if 0 <= j - k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i + 1, j - k + 1)
            if "".join([s[i+k][j+k] if 0 <= i + k < h and 0 <= j + k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i + k + 1, j + k + 1)
            if "".join([s[i-k][j-k] if 0 <= i - k < h and 0 <= j - k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i - k + 1, j - k + 1)
            if "".join([s[i-k][j+k] if 0 <= i - k < h and 0 <= j + k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i - k + 1, j + k + 1)
            if "".join([s[i+k][j-k] if 0 <= i + k < h and 0 <= j - k < w else "x" for k in range(5)]) == "snuke":
                for k in range(5):
                    print(i + k + 1, j - k + 1)


if __name__ == '__main__':
    solve()

-ABC解説