[PYTHON] AtCoder Beginner Contest 148 Participation Report

AtCoder Beginner Contest 148 Participation Report

ABC148A - Round One

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)))

ABC148C - Snack

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))

ABC148E - Double Factorial

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)

ABC148D - Brick Break

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)

ABC148F - Playing Tag on Tree

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

AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 151 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest 166 Participation Report
AtCoder Beginner Contest 153 Participation Report
AtCoder Beginner Contest 145 Participation Report
AtCoder Beginner Contest 184 Participation Report
AtCoder Beginner Contest 165 Participation Report
AtCoder Beginner Contest 160 Participation Report
AtCoder Beginner Contest 169 Participation Report
AtCoder Beginner Contest 178 Participation Report
AtCoder Beginner Contest 163 Participation Report
AtCoder Beginner Contest 159 Participation Report
AtCoder Beginner Contest 164 Participation Report
AtCoder Beginner Contest 168 Participation Report
AtCoder Beginner Contest 150 Participation Report
AtCoder Beginner Contest 158 Participation Report
AtCoder Beginner Contest 156 Participation Report
AtCoder Beginner Contest 162 Participation Report
AtCoder Beginner Contest 157 Participation Report
AtCoder Beginner Contest 167 Participation Report
AtCoder Beginner Contest 179 Participation Report
AtCoder Beginner Contest 182 Participation Report
AtCoder Beginner Contest 146 Participation Report
AtCoder Beginner Contest 152 Participation Report
AtCoder Beginner Contest 155 Participation Report
AtCoder Beginner Contest 174 Participation Report
AtCoder Beginner Contest 171 Participation Report
AtCoder Beginner Contest 149 Participation Report
AtCoder Beginner Contest 148 Participation Report
AtCoder Beginner Contest 188 Participation Report
AtCoder Beginner Contest 170 Participation Report
AtCoder Beginner Contest 187 Participation Report
AtCoder Beginner Contest 183 Participation Report
AtCoder Beginner Contest # 003 Participation Note
AtCoder Grand Contest 040 Participation Report
AtCoder Regular Contest 105 Participation Report
AtCoder Regular Contest 104 Participation Report
ACL Beginner Contest Participation Report
Atcoder Beginner Contest 146 Participation Diary
AtCoder Chokudai Contest 005 Participation Report
AtCoder Grand Contest 047 Participation Report
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
AtCoder HHKB Programming Contest 2020 Participation Report
AtCoder Keyence Programming Contest 2020 Participation Report
AtCoder Panasonic Programming Contest 2020 Participation Report
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 181 Note
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Library Practice Contest Participation Report (Python)