👏

2022/04/01に公開

# A - AtCoder Quiz 2

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():
x = int(input())
if 0<=x<40:
print(40-x)
elif 40<=x<70:
print(70-x)
elif 70<=x<90:
print(90-x)
else:
print('expert')

if __name__ == '__main__':
main()


どのランクに認定されるかを判別し、そのランク帯における上限との差分を出します

# B - Maritozzo

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() for _ in range(3)]
t = input()
ans = ''
for c in t:
ans += s[int(c)-1]
print(ans)

if __name__ == '__main__':
main()


マリトッツォを食べた事はありません

# C - Neo-lexicographic Ordering

import sys
import heapq, math, itertools
from string import ascii_lowercase
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():
x = input()
n = int(input())
dic = {a:b for a,b in zip(x, ascii_lowercase)}
trans = str.maketrans(dic)
lst = []
for _ in range(n):
s = input()
lst.append((s, s.translate(trans)))
lst = sorted(lst, key=lambda x:x[1])
for p,q in lst:
print(p)

if __name__ == '__main__':
main()


str.maketrans(dict)によって作成した辞書を入力文字列 S_iに適用して、通常の辞書順における文字列S_i'を取得します。

# D - Strange Lunchbox

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())
x,y = map(int, inputs().split())
box = [list(map(int, inputs().split())) for _ in range(n)]
dp = [[[inf]*(x+1) for _ in range(y+1)] for _ in range(n+1)]
for i in range(n+1):
dp[i][0][0] = 0
for i in range(n):
[a,b] = box[i]
for j in range(y+1):
for k in range(x+1):
# 使わない場合
dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k])

# 使う場合
dp[i+1][min(j+b, y)][min(k+a, x)] = min(dp[i+1][min(j+b, y)][min(k+a, x)], dp[i][j][k]+1)
print(dp[n][y][x] if dp[n][y][x]!=inf else -1)

if __name__ == '__main__':
main()


dp[i][j][k] := i個目までの弁当を用いて、j個のたい焼きとk個のたこ焼きを食べるための、弁当の個数の最小値

それぞれの弁当を食べる場合、食べない場合の推移を考えて、dp[n][y][x]が求める値です。