ABC解説

AtCoder Beginner Contest 294

A. Filter

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()))
    print(*list(filter(lambda x: x % 2 == 0, a)))


if __name__ == '__main__':
    solve()

B. ASCII Art

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        a = list(map(int, input().rstrip('\n').split()))
        for j in range(w):
            a[j] = "." if a[j] == 0 else chr(a[j] + 64)
        print("".join(a))


if __name__ == '__main__':
    solve()

C. Merge Sequences

import sys


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()))
    b = list(map(int, input().rstrip('\n').split()))
    c = sorted(a + b)
    ans_a = []
    ans_b = []
    for i in range(n + m):
        if len(a) > len(ans_a) and c[i] == a[len(ans_a)]:
            ans_a.append(i + 1)
        if len(b) > len(ans_b) and c[i] == b[len(ans_b)]:
            ans_b.append(i + 1)
    print(*ans_a)
    print(*ans_b)


if __name__ == '__main__':
    solve()

D. Bank

import sys
import collections
import heapq


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, q = list(map(int, input().rstrip('\n').split()))
    q1 = [i + 1 for i in range(n)]
    q2 = []
    heapq.heapify(q1)
    heapq.heapify(q2)
    d = collections.defaultdict(int)
    for i in range(q):
        e = list(map(int, input().rstrip('\n').split()))
        if e[0] == 1:
            heapq.heappush(q2, heapq.heappop(q1))
        elif e[0] == 2:
            d[e[1]]
        else:
            while True:
                p = heapq.heappop(q2)
                if p not in d:
                    print(p)
                    heapq.heappush(q2, p)
                    break


if __name__ == '__main__':
    solve()

-ABC解説