0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

from ABC301 to ABC310 (A, B)

Last updated at Posted at 2023-08-01

はじめに

備忘録ではありますが、解法や変数名、書式にはこだわっています。
よりよい書き方があればご指摘ください。
Python独自の文法も、読みやすさを優先しながら使用します。

A

ABC301

n = int(input())
s = input()

# 勝つために必要な勝利数
need = n // 2 if n % 2 == 0 else n // 2 + 1
count = {"T": 0, "A": 0}
for player in s:
    count[player] += 1
    if count[player] == need:
        print(player)
        break
_ = input()
s = input()

t, a = s.count("T"), s.count("A")
if t < a or (t == a and s[-1] == "T"):
    print("A")
else:
    print("T")

ABC302

a, b = [int(i) for i in input().split()]

print(a // b if a % b == 0 else a // b + 1)

ABC303

_ = input()
s = input().translate(str.maketrans({"1": "l", "0": "o"}))
t = input().translate(str.maketrans({"1": "l", "0": "o"}))

if s == t:
    print("Yes")
else:
    print("No")

ABC304

n = int(input())
sa = [input().split() for _ in range(n)]

# ABC275_A, ABC299_B
index = 0
for i in range(1, n):
    if int(sa[i][1]) < int(sa[index][1]):
        index = i

# 範囲外のものは前に (ABC300_B)
for i in range(n):
    print(sa[(index + i) % n][0])

ABC305

n = int(input())

# すでにいる or 戻る
if n % 5 <= 2:
    print(n - n % 5)
# 進む
else:
    print(n + 5 - n % 5)

ABC306

_ = input()
s = input()

for char in s:
    print(char * 2, end="")

ABC307

n = int(input())
a = [int(i) for i in input().split()]

for i in range(n):
    print(sum(a[i * 7: i * 7 + 7]), end=" ")

ABC308

s = [int(i) for i in input().split()]

# 条件1
if s != sorted(s):
    print("No")
else:
    for elem in s:
        # 条件2 & 条件3
        if not 100 <= elem <= 675 or elem % 25:
            print("No")
            break
    # 最終的に break していない -> 全ての要素において条件が満たされている
    else:
        print("Yes")

ABC309

a, b = [int(i) for i in input().split()]

if b - a == 1 and not a % 3 == 0:
    print("Yes")
else:
    print("No")

ABC310

_, p, q = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]

answer = p
for food_price in d:
    if q + food_price < answer:
        answer = q + food_price

print(answer)

B

ABC301

_ = input()
a = [int(i) for i in input().split()]

while True:
    n = len(a)
    for i in range(n - 1):
        if abs(a[i] - a[i + 1]) != 1:
            if a[i] < a[i + 1]:
                a[i + 1: i + 1] = range(a[i] + 1, a[i + 1])
            else:
                a[i + 1: i + 1] = range(a[i + 1] + 1, a[i])[::-1]
            break
    else:
        break

print(*a)
n = int(input())
a = [int(i) for i in input().split()]
 
for i in range(n - 1):
    print(a[i])
    if abs(a[i] - a[i + 1]) != 1:
        if a[i] < a[i + 1]:
            print(*range(a[i] + 1, a[i + 1]))
        else:
            print(*range(a[i + 1] + 1, a[i])[::-1])
print(a[-1])

ABC302

h, w = [int(i) for i in input().split()]
s = [input() for _ in range(h)]

# 上から時計回りで8方向に対応する差分を用意 (row: 行, column: 列)
rc_diff = [
    (+1, 0), (+1, +1), (0, +1), (-1, +1),
    (-1, 0), (-1, -1), (0, -1), (+1, -1),
]

for i in range(h):
    for j in range(w):

        for k in range(8):
            a = ""
            r, c = i, j
            for _ in range(5):
                # 範囲外アクセスを回避
                if r < 0 or h - 1 < r or c < 0 or w - 1 < c:
                    break
                a += s[r][c]
                r += rc_diff[k][0]
                c += rc_diff[k][1]
            else:
                if a == "snuke":
                    r, c = i, j
                    for _ in range(5):
                        print(r + 1, c + 1)
                        r += rc_diff[k][0]
                        c += rc_diff[k][1]

ABC303

n, m = [int(i) for i in input().split()]

# 並んだ二人組を真にする
pair = [[False] * n for _ in range(n)]
for _ in range(m):
    a = [int(i) for i in input().split()]
    for i in range(n - 1):
        pair[a[i] - 1][a[i + 1] - 1] = True

count = 0
# 組合せ
for i in range(n):
    for j in range(i + 1, n):
        if pair[i][j] or pair[j][i]:
            continue
        count += 1

print(count)

ABC304

from math import floor

n = int(input())

for i in range(3, 10):
    if n <= 10**i - 1:
        print(floor(n / 10**(i - 3)) * 10**(i - 3))
        break

ABC305

p, q = input().split()

distance = [3, 1, 4, 1, 5, 9]
print(
    sum(distance[
        slice(*sorted([ord(p) - ord("A"), ord(q) - ord("A")]))
    ])
)

ABC306

a = [int(i) for i in input().split()]

total = 0
for i, elem in enumerate(a):
    total += elem * 2**i

print(total)

ABC307

n = int(input())
s = [input() for _ in range(n)]

# 順列
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        t = s[i] + s[j]
        m = len(t)
        for k in range(m):
            # 添え字ガチャ? (ABC298B)
            if not t[k] == t[m - k - 1]:
                break
        else:
            print("Yes")
            exit()
else:
    print("No")

ABC308

_ = input()
c = input().split()
d = input().split()
p = [int(i) for i in input().split()]

# d と p であり、動的計画法ではない
dp = dict(zip(d, p[1:]))

total = 0
for color in c:
    # 存在しないキーはデフォルト値 (p[0]) を返す
    total += dp.get(color, p[0])

print(total)

ABC309

from copy import deepcopy

n = int(input())
a = [list(input()) for _ in range(n)]

a_deepcopy = deepcopy(a)

# 上・右
for i in range(1, n):
    a[0][i] = a_deepcopy[0][i - 1]
    a[i][n - 1] = a_deepcopy[i - 1][n - 1]

# 下・左
for i in range(n - 1):
    a[n - 1][i] = a_deepcopy[n - 1][i + 1]
    a[i][0] = a_deepcopy[i + 1][0]


for linear in a:
    print(*linear, sep="")

ABC310

n, _ = [int(i) for i in input().split()]
pcf = [[int(i) for i in input().split()] for _ in range(n)]

# 順列
for i in range(n):
    for j in range(n):
        # 条件1
        if i == j or not pcf[j][0] <= pcf[i][0]:
            continue

        # 条件2
        for function in pcf[i][2:]:
            if function not in pcf[j][2:]:
                break
        # 条件3
        else:
            if pcf[j][0] < pcf[i][0] or pcf[i][1] < pcf[j][1]:
                print("Yes")
                exit()
else:
    print("No")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?