Break through in two and a half minutes. It's easy, but I thought it would be difficult to write something simple.
A = int(input())
B = int(input())
print(*(set([1, 2, 3]) - set([A, B])))
ABC148B - Strings with the Same Length
Break through in one and a half minutes. Just write. I didn't use it thinking that it was a zip.
N = int(input())
S, T = input().split()
print(''.join(S[i] + T[i] for i in range(N)))
Break through in 3 minutes. The answer is the least common multiple, but I wondered how to solve it, and if I knew the greatest common divisor, I googled "Least common multiple Python" and found that lcm (a, b) = a * b / gcd (a, b)
came out, so write it and finish.
from fractions import gcd
A, B = map(int, input().split())
print(A * B // gcd(A, B))
Break through in about 20 minutes. WA1. I thought about D for a while, but it was difficult, so I skipped it and tried this. For the time being, I implemented f (n) naive and tried to move it. Whenever N is odd, 0 was immediately understood.
When input example 3 was played with N // 10
, it was quite different, so when I tried increasing it by n, the number was shifted at f (50), and 50 contains 5, so it becomes a car. N // 10 + N // 50
does not match the input example 3, and the next 250 car in the brain is finally understood and implemented. while t <= N:
is while t <N: I wrote
and ate WA, but AC.
from sys import exit
N = int(input())
if N % 2 == 1:
print(0)
exit()
result = 0
t = 10
while t <= N:
result += N // t
t *= 5
print(result)
It breaks through in about 27 minutes. I just thought about processing from the right, skipped it as difficult and came back from E, but it is obviously easy from the situation of the standings, so maybe I will process from the left if I think too much It was easy considering that orz.
N = int(input())
a = [int(s) - 1 for s in input().split()]
result = 0
for i in range(N):
if a[i] != (i - result):
result += 1
if result == N:
print(-1)
else:
print(result)
I couldn't break through. I knew that it was the minimax method, but the question was only once in the past, and I ended up wondering what would happen if breadth-first was prioritized.
Postscript: It wasn't the minimax method (explosion). As per the explanation PDF, it should be implemented as if it were caught in front of the place farthest from Mr. Aoki and the place closest to Mr. Takahashi.
from sys import exit
N, u, v = map(int, input().split())
if u == v:
print(0)
exit()
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
A, B = map(int, input().split())
edges[A].append(B)
edges[B].append(A)
def calc_destination(start, edges):
destination = [-1] * (N + 1)
destination[start] = 0
q = [start]
while len(q) != 0:
current = q.pop()
for n in edges[current]:
if destination[n] != -1:
continue
destination[n] = destination[current] + 1
q.append(n)
return destination
tak = calc_destination(u, edges)
aok = calc_destination(v, edges)
result = 0
for i in range(1, N + 1):
aoki = aok[i]
if tak[i] >= aoki:
continue
if aoki > result:
result = aoki
print(result - 1)
Recommended Posts