https://atcoder.jp/contests/abc186/
A - Brick
n, w = map(int, input().split())
print(n // w)
B - Blocks on Grid
Match to the smallest number of all squares. Since it is an order of about 10 to the 4th power, it seems good to turn the loop honestly
h, w = map(int, input().split())
blocks = []
for i in range(h):
blocks += list(map(int, input().split()))
min_block = min(blocks)
ans = 0
for a in blocks:
ans += a - min_block
print(ans)
C - Unlucky 7
How many numbers from 1 to N do not contain 7 in either decimal or octal?
Since N is 10 to the 5th power or less, it seems good to check for all numbers below N.
n = int(input())
ans = 0
for a in range(1, n+1):
ten = str(a)
eight = format(a, 'o')
if "7" not in ten and "7" not in eight:
ans += 1
print(ans)
D - Sum of difference
N Add to this number to get the sum of all the differences. Should I loop for a combination? That would exceed the amount of calculation. If you sort in advance by size, you will not need to calculate the absolute value.
n = int(input())
numbers = sorted(list(map(int, input().split())))
ans = 0
other_sum = sum(numbers)
other_len = len(numbers)
for i, a in enumerate(numbers):
other_sum -= a
other_len -= 1
ans += (other_sum) - a * (other_len)
print(ans)
Recommended Posts