Break through in 2 minutes. Just write. 1 type, 2 types, that's it.
S = input()
if len(set(S)) == 1:
print('No')
else:
print('Yes')
Break through in 3 and a half minutes. Calculate how many operations N includes. If n times, there are n * A blue balls. For the halfway, if it is within A, the number is Otherwise there are A blue balls.
N, A, B = map(int, input().split())
result = 0
result += N // (A + B) * A
result += min(N % (A + B), A)
print(result)
Break through in 4 and a half minutes. A ≤ B ≤ 100 means that at most 1000 is the answer, so it's OK to brute force! It was safer than Clever.
A, B = map(int, input().split())
for i in range(2000):
if int(i * 0.08) == A and int(i * 0.1) == B:
print(i)
exit()
print(-1)
Postscript: Since there was a problem to be solved by * O * (1) in the explanation PDF.
A, B = map(int, input().split())
x_low = (A * 100 + 7) // 8
x_high = ((A + 1) * 100 + 7) // 8 - 1
y_low = (B * 100 + 9) // 10
y_high = ((B + 1) * 100 + 9) // 10 - 1
result = max(x_low, y_low)
if result > min(x_high, y_high):
result = -1
print(result)
Break through in 17 minutes. Of course, if you operate the character string as you were told, TLE is straight. You can see that you use deque because you add from the right and left. After that, it becomes TLE if you invert each time. If necessary, just do it once at the end.
from collections import deque
S = input()
Q = int(input())
t = deque(S)
reverse = False
for _ in range(Q):
query = input()
if query[0] == '1':
reverse = not reverse
elif query[0] == '2':
_, F, C = query.split()
if F == '1':
if reverse:
t.append(C)
else:
t.appendleft(C)
elif F == '2':
if reverse:
t.appendleft(C)
else:
t.append(C)
result = ''.join(t)
if reverse:
result = result[::-1]
print(result)
Lost. I couldn't think of any way to remove from * O * (* N * 2 </ sup>). I wrote during the contest, but 5 minutes before the end, I drew the remainder and the number of combinations for each digit. I realized that if I proceeded one digit at a time, I could solve it with DP, but it was too late.
Addendum: It's easy when P is 2 and 5, and it can be divided when the last digit is a multiple of 2 or a multiple of 5, so the rest can be calculated by adding up the numbers that can be extended to the left. For other Ps , For example S 6 </ sub> S 5 </ sub> S 4 </ sub> S 3 </ sub> S 2 </ sub> S 1 </ sub> S 0 </ sub> S 6 </ sub> S 5 </ sub> S 4 </ sub> S 3 </ strong> If sub> is divisible by P, then S 6 </ sub> S 5 </ sub> S 4 </ sub> S 3 </ sub> S 2 </ sub> S 1 </ sub> S 0 </ sub> ≡ S 2 </ sub> S 1 </ sub> S 0 </ sub> Since it is (mod P), it can be obtained by extending it to the left while recording the remainder and accumulating the number of the same remainder.
N, P = map(int, input().split())
S = input()
S = S[::-1]
result = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
result += N - i
else:
t = [0] * P
m = 1
n = 0
for i in range(len(S)):
t[n] += 1
n += int(S[i]) * m
n %= P
result += t[n]
m *= 10
m %= P
print(result)
Recommended Posts