👏

2021/11/28に公開

# A - First Grid

``````x1 = input()
x2 = input()
if x1 == ".#" and x2 == "#.":
print("No")
elif x1 == "#." and x2 == ".#":
print("No")
else:
print("Yes")
``````

# B - Hard Calculation

1の位から計算すると楽。`a //= 10``a /= 10`にすると除算のときに余りが発生し、値が途中で変化してしまうので注意。

``````a, b = map(int, input().split())

while a > 0 and b > 0:
if a % 10 + b % 10 >= 10:
print("Hard")
exit()
a //= 10
b //= 10
print("Easy")
``````

# C - Cheese

``````N, weight = map(int, input().split())
cheese = [list(map(int, input().split())) for i in range(N)]
cheese.sort(key=lambda x: x[0], reverse=True)

result_num = 0
for value, w in cheese:
weight -= w
result_num += w * value
if weight <= 0:
result_num -= abs(weight) * value
break
print(result_num)
``````

# D - Longest X

``````s = list(input())
k = int(input())

# 累積和
cumulative_sum = [0] * (len(s) + 1)

for i, value in enumerate(s):
if value == ".":
cumulative_sum[i + 1] = cumulative_sum[i] + 1
else:
cumulative_sum[i + 1] = cumulative_sum[i]

right = 0
ans = 0
for left, value in enumerate(s):
while right < len(s) and cumulative_sum[right + 1] - cumulative_sum[left] <= k:
right += 1
ans = max(ans, right - left)

print(ans)
``````

ログインするとコメントできます