I slept until just before, I was sleepy, I was sleepy. Perhaps because of that, I was late in solving the A and B problems, and I also gave out a helpless WA. So Yoshi!
Break through in two and a half minutes. Just write.
N = int(input())
if N % 1000 == 0:
print(0)
else:
print(1000 - N % 1000)
ABC173B - Judge Status Summary
Break through in 4 minutes. Just write.
N = int(input())
S = [input() for _ in range(N)]
d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for s in S:
d[s] += 1
print('AC x', d['AC'])
print('WA x', d['WA'])
print('TLE x', d['TLE'])
print('RE x', d['RE'])
Break through in 6 and a half minutes. At first glance when it is a bit full search by looking at the constraints. Recently, there are many bit full searches?
from itertools import product
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
result = 0
for a in product([True, False], repeat=H):
for b in product([True, False], repeat=W):
t = 0
for y in range(H):
if a[y]:
continue
for x in range(W):
if b[x]:
continue
if c[y][x] == '#':
t += 1
if t == K:
result += 1
print(result)
Break through in 14 minutes. WA1. N -1 to N anyway Chombo. I couldn't help if I tried even one sample.
If you try by hand and sort A in descending order, a 1 </ sub>, a 2 </ sub>, ..., a N </ sub> , A 1 </ sub> + a 2 </ sub> + a 2 </ sub> + a 3 </ sub> + a 3 </ sub> + ... I knew it was going to be, so I submitted it and AC.
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
result = 0
for i in range(N - 1):
result += A[(i + 1) // 2]
print(result)
Break through in 41 minutes. WA1. The positive route was wrongly identified.
First, look at the number and consider whether it will be positive, 0, or negative. If it is positive, the absolute value will be large, and if it is negative, the absolute value will be small. Good. Note that if positive, you can only use two negative values.
N, K = map(int, input().split())
A = list(map(int, input().split()))
m = 1000000007
a = [e for e in A if e > 0]
b = [e for e in A if e < 0]
c = [e for e in A if e == 0]
#Plus route
if len(a) >= K - (min(K, len(b)) // 2) * 2:
a.sort(reverse=True)
b.sort()
result = 1
i = 0
j = 0
k = 0
while k < K:
if k < K - 1 and i < len(a) - 1 and j < len(b) - 1:
x = a[i] * a[i + 1]
y = b[j] * b[j + 1]
if y >= x:
result *= y
result %= m
j += 2
k += 2
else:
result *= a[i]
result %= m
i += 1
k += 1
elif k < K - 1 and j < len(b) - 1:
y = b[j] * b[j + 1]
result *= y
result %= m
j += 2
k += 2
elif i < len(a):
result *= a[i]
result %= m
i += 1
k += 1
elif j < len(b):
result *= b[j]
result %= m
j += 1
k += 1
print(result)
#0 route
elif len(c) != 0:
print(0)
#Minus route
else:
a.sort()
b.sort(reverse=True)
result = 1
i = 0
j = 0
k = 0
while k < K:
if i < len(a) and j < len(b):
if a[i] <= -b[i]:
result *= a[i]
result %= m
i += 1
k += 1
else:
result *= b[j]
result %= m
j += 1
k += 1
elif i < len(a):
result *= a[i]
result %= m
i += 1
k += 1
elif j < len(b):
result *= b[j]
result %= m
j += 1
k += 1
print(result)
I couldn't solve it. I could only think of a solution for * O * (* N * 2 </ sup>).
Recommended Posts