🐷

2022/04/02に公開

# A - Seismic magnitude scales

``````import sys
import heapq, math, itertools
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
mod = 10**9+7
inf = float('inf')
#sys.setrecursionlimit(10**7)

def main():
a,b = map(int, inputs().split())
print(pow(32, a-b))

if __name__ == '__main__':
main()
``````

#マグニチュードは1増えると32倍なので2増えると当然1024倍!!!!!

# B - typo

``````import sys
import heapq, math, itertools
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
mod = 10**9+7
inf = float('inf')
#sys.setrecursionlimit(10**7)

def main():
s = input()
t = input()
lst = [s]
for i in range(len(s)-1):
nx = s[:i]+s[i+1]+s[i]+s[i+2:]
lst.append(nx)
print('Yes' if t in lst else 'No')
if __name__ == '__main__':
main()
``````

# C - Select Mul

``````import sys
import heapq, math, itertools
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
mod = 10**9+7
inf = float('inf')
#sys.setrecursionlimit(10**7)

def main():
n = list(input())
ans = -inf
for i in range(2**len(n)):
l1,l2 = [], []
for j in range(len(n)):
if (i>>j)&1:
l1.append(n[j])
else:
l2.append(n[j])
l1 = ''.join(sorted(l1, reverse=True))
l2 = ''.join(sorted(l2, reverse=True))
if l1 and l2:
if l1[0]!='0' and l2[0]!='0':
ans = max(ans, int(l1)*int(l2))
print(ans)

if __name__ == '__main__':
main()
``````

Nを文字列としてみると高々10文字程度なので、全探索できそうです。

また、積をなるべく大きくするため、部分文字列のうち大きい数字を先頭に置いた方がよいことを考慮しましょう。

# D - Online games

``````import sys
import heapq, math, itertools
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
mod = 10**9+7
inf = float('inf')
#sys.setrecursionlimit(10**7)

def main():
n = int(input())
dic = defaultdict(int)
for _ in range(n):
a,b = map(int, inputs().split())
dic[a] += 1
dic[a+b] -= 1
dic = sorted(dic.items(), key=lambda x:x[0])
ans = {i:0 for i in range(n+1)}
pre, num = 0,0
for (a,b) in dic:
ans[num] += a - pre
num += b
pre = a
ans = [ans[i] for i in range(1, n+1)]
print(*ans)
if __name__ == '__main__':
main()
``````

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