ABC解説

大和証券プログラミングコンテスト2022 Autumn (AtCoder Beginner Contest 277)

A. ^{-1}

import sys


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


if __name__ == '__main__':
    solve()

B. Playing Cards Validation

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(int)
    for i in range(n):
        s = str(input().rstrip('\n'))
        if not s[0] in ["H", "D", "C", "S"]:
            print("No")
            exit()
        if not s[1] in ["A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"]:
            print("No")
            exit()
        if s in d:
            print("No")
            exit()
        d[s]
    print("Yes")


if __name__ == '__main__':
    solve()

C. Ladder Takahashi

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    tmd = collections.defaultdict(list)
    for i in range(n):
        tma, tmb = list(map(int, input().rstrip('\n').split()))
        tmd[tma-1] += [tmb-1]
        tmd[tmb-1] += [tma-1]

    ql = [[0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0]
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    ql.append([cost + 1, tmv])
                    fq[tmv]
        else:
            break
    print(max(fq.keys()) + 1)


if __name__ == '__main__':
    solve()

-ABC解説