ABC解説

Sky株式会社プログラミングコンテスト2023(AtCoder Beginner Contest 289)

A. flip

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    print("".join(["0" if v != "0" else "1" for v in str(input().rstrip('\n'))]))


if __name__ == '__main__':
    solve()

B. V

import sys


def func(n, a, ls):
    if n in a:
        ls += [n]
        return func(n + 1, a, ls)
    else:
        ls += [n]
        ls.reverse()
        return ls


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    ans = []
    for i in range(n):
        if i + 1 not in ans:
            ans += func(i + 1, a, [])
    print(*ans)


if __name__ == '__main__':
    solve()

C. Coverage

import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    a = []
    for i in range(m):
        c = int(input().rstrip('\n'))
        a.append(sum([pow(2, v-1) for v in list(map(int, input().rstrip('\n').split()))]))
    p = pow(2, n) - 1
    ans = 0
    for i in range(m + 1):
        for v in itertools.combinations(a, i):
            b = 0
            for j in range(i):
                b |= v[j]
            if b == p:
                ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

D. Step Up Robot

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    m = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for v in b:
        d[v]
    x = int(input().rstrip('\n'))
    dp = [False] * (x + 1)
    dp[0] = True
    for i in range(x + 1):
        if dp[i]:
            for v in a:
                if i + v < x + 1:
                    if i + v not in d:
                        dp[i + v] = True
    print("Yes" if dp[x] else "No")


if __name__ == '__main__':
    solve()

-ABC解説