「AtCoder Beginner Contest 123」を解きました(リアルタイムでは参加できませんでした)。
A - Five Antennas(100点)
- 一番大きい座標と小さい座標の差がKより大きいかで条件分岐
- 最初問題文のa~eの不等号を見落としていたので無駄にmax, minを取ってしまった
A = [int(input()) for i in range(5)] K = int(input()) if (A[-1]-A[0] <= K): print("Yay!") else: print(":(")
B - Five Dishes(200点)
- 10の位まで繰り上げる
- 1の位が1~9のうちで1に近いほど、最後の料理に採用されやすい
A = [int(input()) for i in range(5)] B = [a - a % 10 + 10 if a % 10 != 0 else a for a in A] diff = [(b - a) for a, b in zip(A, B)] print(sum(B)-max(diff))
C - Five Transportations(300点)
- 結局のところ、一番輸送量が小さい経路で詰まる
- 一番輸送量が小さい経路を一番最初に通過すると考えると分かりやすい
import math N = int(input()) A = [int(input()) for i in range(5)] print(math.ceil(N/min(A))+4)
D - Cake 123(400点)
- Kが高々3000以下なので、A, Bの直積を考えた後に上位3000だけ残し、Cとの直積を考える
- 降順sort部分を "AB = sorted(AB)[::-1]" にするとTLEした
import itertools X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) AB = [a + b for (a, b) in list(itertools.product(A, B))] AB.sort(reverse=True) ans = [ab + c for (ab, c) in list(itertools.product(AB[:min(3000, X*Y*Z)], C))] ans.sort(reverse=True) for i in range(K): print(ans[i])