ABC解説

東京海上日動プログラミングコンテスト2023(AtCoder Beginner Contest 299)

A. Treasure Chest

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    print("in" if s.find("|") < s.find("*") < s.rfind("|") else "out")


if __name__ == '__main__':
    solve()

B. Trick Taking

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, t = list(map(int, input().rstrip('\n').split()))
    c = list(map(int, input().rstrip('\n').split()))
    r = list(map(int, input().rstrip('\n').split()))
    mx = 0
    ans = 0
    for i in range(n):
        if c[i] == t:
            r[i] += pow(10, 20)
        if c[i] == c[0]:
            r[i] += pow(10, 15)
        if mx < r[i]:
            mx = r[i]
            ans = i
    print(ans + 1)


if __name__ == '__main__':
    solve()

C. Dango

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n')).split("-")
    ans = 0
    for i in range(len(s)):
        ans = max(ans, s[i].count("o"))
    print(ans if ans != 0 and len(s) != 1 else -1)


if __name__ == '__main__':
    solve()

D. Find by Query

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    st = 1
    ed = n
    for i in range(20):
        bin_v = (st + ed) // 2
        print("?", bin_v, flush=True)
        a = int(input().rstrip('\n'))
        if a == 0:
            st = bin_v
        else:
            ed = bin_v
    print("!", bin_v, flush=True)


if __name__ == '__main__':
    solve()

-ABC解説