ABC解説

AtCoder Beginner Contest 291(Sponsored by TOYOTA SYSTEMS)

A. camel Case

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    for i in range(len(s)):
        if 65 <= ord(s[i]) <= 90:
            print(i + 1)
            exit()


if __name__ == '__main__':
    solve()

B. Trimmed Mean

import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    x = sorted(list(map(int, input().rstrip('\n').split())))[n:n * 4]
    print(sum(x) / len(x))


if __name__ == '__main__':
    solve()

C. LRUD Instructions 2

import collections
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    x, y = 0, 0
    d = collections.defaultdict(int)
    d[0, 0]
    for i in range(n):
        if s[i] == "R":
            x += 1
        elif s[i] == "L":
            x -= 1
        elif s[i] == "U":
            y += 1
        elif s[i] == "D":
            y -= 1
        if (x, y) in d:
            print("Yes")
            exit()
        d[x, y]
    print("No")


if __name__ == '__main__':
    solve()

D. Flip Cards

import random
import sys


def solve():
    input = sys.stdin.readline
    mod = 998244353
    n = int(input().rstrip('\n'))
    ls = [[0] * 2 for _ in range(n)]
    ls[0][0] = 1
    ls[0][1] = 1
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    for i in range(1, n):
        for j in range(2):
            for k in range(2):
                if ab[i][j] != ab[i-1][k]:
                    ls[i][j] += ls[i-1][k]
                    ls[i][j] %= mod
    print(sum(ls[-1]) % mod)


if __name__ == '__main__':
    solve()

-ABC解説