ABC解説

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

A. Job Interview

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    print("Yes" if s.count("x") == 0 and s.count("o") > 0 else "No")


if __name__ == '__main__':
    solve()

B. Coloring Matrix

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    b = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    d0 = True
    d90 = True
    d180 = True
    d270 = True
    for i in range(n):
        for j in range(n):
            if a[i][j] == 1:
                if b[i][j] != 1:
                    d0 = False
            if a[-j-1][i] == 1:
                if b[i][j] != 1:
                    d90 = False
            if a[-i-1][-j-1] == 1:
                if b[i][j] != 1:
                    d180 = False
            if a[j][-i-1] == 1:
                if b[i][j] != 1:
                    d270 = False
    print("Yes" if max(d0, d90, d180, d270) else "No")


if __name__ == '__main__':
    solve()

C. Cards Query Problem

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    q = int(input().rstrip('\n'))
    box = collections.defaultdict(list)
    card = collections.defaultdict(lambda: collections.defaultdict(int))
    for i in range(q):
        query = list(map(int, input().rstrip('\n').split()))
        if query[0] == 1:
            box[query[2]] += [query[1]]
            card[query[1]][query[2]]
        elif query[0] == 2:
            print(*sorted(box[query[1]]))
        elif query[0] == 3:
            print(*sorted(card[query[1]].keys()))


if __name__ == '__main__':
    solve()

D. Writing a Numeral

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 998244353
    q = int(input().rstrip('\n'))
    ans = 1
    dq = collections.deque([1])
    for i in range(q):
        query = list(map(int, input().rstrip('\n').split()))
        if query[0] == 1:
            ans = (ans * 10 + query[1]) % mod
            dq.append(query[1])
        elif query[0] == 2:
            digit = len(dq) - 1
            n = dq.popleft()
            ans = (ans - (pow(10, digit, mod) * n) % mod) % mod
        else:
            print(ans)


if __name__ == '__main__':
    solve()

-ABC解説