ABC解説

AtCoder Beginner Contest 295

A. Probably English

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    d = {"and", "not", "that", "the", "you"}
    n = int(input().rstrip('\n'))
    w = list(map(str, str(input().rstrip('\n')).split()))
    for i in range(n):
        if w[i] in d:
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    solve()

B. Bombs

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    r, c = list(map(int, input().rstrip('\n').split()))
    b = [list(str(input().rstrip('\n'))) for _ in range(r)]
    st = []
    for i in range(r):
        for j in range(c):
            if b[i][j] != "." and b[i][j] != "#":
                st.append([i, j, int(b[i][j])])
    for i, j, d in st:
        ql = [[0, i, j]]
        ql = collections.deque(ql)
        fq = collections.defaultdict(list)
        fq[i, j]
        while True:
            if len(ql) != 0:
                cost, xv, yv = ql.popleft()
                if cost <= d:
                    b[xv][yv] = "."
                    for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                        if 0 <= xv < r and 0 <= yv < c:
                            if (xv, yv) not in fq:
                                ql.append([cost + 1, xv, yv])
                                fq[xv, yv]
            else:
                break
    for i in range(r):
        print("".join(b[i]))


if __name__ == '__main__':
    solve()

C. Socks

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = collections.Counter(list(map(int, input().rstrip('\n').split())))
    ans = 0
    for k, v in a.items():
        ans += v // 2
    print(ans)


if __name__ == '__main__':
    solve()

D. Three Days Ago

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    dp = [[0] * 10 for _ in range(len(s) + 1)]
    d = collections.defaultdict(list)
    d[0] += [0]
    for i in range(len(s) + 1):
        if i > 0:
            dp[i][int(s[i-1])] += 1
            b = 0
            for j in range(10):
                dp[i][j] += dp[i-1][j]
                dp[i][j] %= 2
                if dp[i][j] == 1:
                    b += pow(10, j)
            d[b] += [i]
    ans = 0
    for k, v in d.items():
        ans += sum([i for i in range(len(v))])
    print(ans)


if __name__ == '__main__':
    solve()

-ABC解説