Break through in 1 minute. Just write.
A, B = map(int, input().split())
print(2 * A + 100 - B)
Break through in 4 minutes. I was a little worried, but realized that I should try everything.
N, *A = map(int, open(0).read().split())
result = 0
for i in range(2, 1000):
t = 0
for a in A:
if a % i == 0:
t += 1
result = max(result, t)
print(result)
Break through in 6 minutes. Needless to say, if the total number of each digit is a multiple of 3, then it is a multiple of 3. So, if the total number of each digit is divided by 3, then the remainder is considered first. The story is over because it is a multiple of 3 from. If the remainder is 1 or 2, it will always be a multiple of 3 if you erase 1 or 2 digits, but you need to check if there are enough digits to erase.
N = input()
t = [int(c % 3) for c in N]
x = sum(t)
if x % 3 == 0:
print(0)
elif x % 3 == 1:
if 1 in t:
print(1)
else:
print(2)
elif x % 3 == 2:
if 2 in t:
print(1)
else:
print(2)
Break through in 17 minutes. It's easy to see that the coordinates at the start of each round are the sum of the cumulative sums up to that point. The maximum coordinates for each round are the coordinates at the start of each round. Since it is the sum of the maximum values, you can take the maximum of them.
from itertools import accumulate
N, *A = map(int, open(0).read().split())
a = list(accumulate(A))
result = 0
c = 0
m = 0
for i in range(N):
m = max(a[i], m)
result = max(result, c + m)
c += a[i]
print(result)
Break through in 60 minutes. I thought too hard. I should have painted it without thinking ...
from sys import stdin
readline = stdin.readline
H, W, N, M = map(int, readline().split())
AB = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(N)]
CD = [tuple(map(lambda x: int(x) - 1, readline().split())) for _ in range(M)]
t = [[0] * W for _ in range(H)]
ly = [[] for _ in range(H)]
lt = [[] for _ in range(W)]
for a, b in AB:
ly[a].append(b)
lt[b].append(a)
for i in range(H):
ly[i].sort()
for i in range(W):
lt[i].sort()
by = [[] for _ in range(H)]
bt = [[] for _ in range(W)]
for c, d in CD:
by[c].append(d)
bt[d].append(c)
for i in range(H):
by[i].append(W)
by[i].sort()
for i in range(W):
bt[i].append(H)
bt[i].sort()
result = 0
for h in range(H):
lyh = ly[h]
i = 0
pd = -1
for d in by[h]:
j = i
while j < len(lyh) and lyh[j] < d:
j += 1
if i != j:
for w in range(pd + 1, d):
t[h][w] = 1
i = j
pd = d
for w in range(W):
ltw = lt[w]
i = 0
pc = -1
for c in bt[w]:
j = i
while j < len(ltw) and ltw[j] < c:
j += 1
if i != j:
for h in range(pc + 1, c):
t[h][w] = 1
i = j
pc = c
print(sum(sum(x) for x in t))
Recommended Posts