[PYTHON] AtCoderBeginnerContest169 Review & Summary (first half)

AtCoder ABC169 This is a summary of the AtCoder Beginner Contest 169 problems that took place on 2020-05-31 (Sun), starting with problem A and taking into account the considerations. The first half deals with problems up to ABC. The problem is quoted, but please check the contest page for details. Click here for the contest page Official commentary PDF

Problem A Multiplication 1

Problem statement Find $ A × B $.

It took the input and output the product.

abc169a.py


a, b = map(int, input().split())
print(a * b)

Problem B Multiplication 2

Problem statement $ N $ integers $ A_1, ..., A_N $ are given. Find $ A_1 × ... × A_N $. However, if the result exceeds $ 10 ^ {18} $, output "-1" instead.

I participated in Python, but I had a hard time. It would be bad if there was a 0 at the end of the input, so I wrote a program that keeps multiplying all the values and it became "TLE". If I could check if there was a 0 at the beginning, I wouldn't have had to struggle so much with Python, but I spent more time than I expected, and the penalties overlapped (remorse). I was optimistic that it would be okay because there is no upper limit for Python int types, but I didn't realize that the calculation cost would increase steadily.

abc169b.py


n = int(input())
a_list = list(map(int, input().split()))
if 0 in a_list:
    print(0)
else:
    ans = 1
    flag = 1
    for i in range(0, n):
        ans *= int(a_list[i])
        if ans > 10 ** 18:
            flag = 0
            break
    if flag == 0:
        print(-1)
    else:
        print(ans)

By the way, I issued pena 4 times.

C problem Multiplication 3

Problem statement Truncate $ A × B $ after the decimal point and output the result as an integer. Constraints ・ $ 0 \ leq A \ leq 10 ^ {15} $ ・ $ 0 \ leq B <10 $ ・ $ A $ is an integer ・ $ B $ is given up to the decimal point of $ 2 $

I knew that there would be an error in the calculation of decimal numbers, so I thought that if I multiply it by 100 to make it an integer, I could calculate it without problems, so I submitted a method to calculate by multiplying the input $ B $ by 100. However, I became "WA" and was desperate. The code that returned the first submitted "WA".

abc169c.py


a, b = input().split()
a = int(a)
b = int(float(b) * 100)
print(a * b // 100)

I didn't know what was the cause, and I made a lot of trial and error, but it didn't go through, and at the end I did not convert the input $ B $ to float, but directly converted it from a character string to a number string as a three-digit integer. I was able to pass "AC". I learned that an error occurs even when a decimal number is multiplied by 100 to make an integer (I could solve the example without any problem, so I could not understand the cause at all).

abc169c.py


a, b = input().split()
a = int(a)
b = int(''.join(b.split(".")))
x = a * b
print(x // 100)

The C problem was also 4 pena before issuing "AC".

This is the end of the first half. Personally, I felt like an assortment of parts that I was not good at, and I was impatient that I ended up with only problem A and the rate rattled, which I think is the reason why it took a long time to solve. I was really desperate during the contest because I didn't know the reason (because the display method of the judge results changed without notice and I didn't even know how many problems I had). Thank you for reading to the end of the first half.

The second half will explain the DEF problem. Continued in the second half.

Recommended Posts

AtCoderBeginnerContest175 Review & Summary (first half)
AtCoderBeginnerContest164 Review & Summary (first half)
AtCoderBeginnerContest169 Review & Summary (first half)
AtCoderBeginnerContest174 Review & Summary (first half)
AtCoderBeginnerContest173 Review & Summary (First Half)
AtCoderBeginnerContest165 Review & Summary (first half)
AtCoderBeginnerContest170 Review & Summary (first half)
AtCoderBeginnerContest167 Review & Summary (first half)
AtCoderBeginnerContest177 Review & Summary (first half)
AtCoderBeginnerContest168 Review & Summary (first half)
AtCoderBeginnerContest178 Review & Summary (first half)
AtCoderBeginnerContest171 Review & Summary (first half)
AtCoderBeginnerContest166 Review & Summary (first half)
AtCoderBeginnerContest161 Review & Summary (first half)
AtCoderBeginnerContest172 Review & Summary (first half)
AtCoderBeginnerContest176 Review & Summary (first half)
AtCoderBeginnerContest178 Review & Summary (second half)
AtCoderBeginnerContest161 Review & Summary (second half)
AtCoderBeginnerContest164 Review & Summary (second half)
AtCoderBeginnerContest176 Review & Summary (second half)
AtCoderBeginnerContest168 Review & Summary (second half)
AtCoderBeginnerContest169 Review & Summary (second half)
AtCoderBeginnerContest166 Review & Summary (second half)
AtCoderBeginnerContest171 Review & Summary (second half)
AtCoderBeginnerContest174 Review & Summary (second half)
AtCoderBeginnerContest173 Review & Summary (second half)
AtCoderBeginnerContest177 Review & Summary (second half)
AtCoderBeginnerContest180 Review & Summary
AtCoderBeginnerContest182 Review & Summary
AtCoderBeginnerContest183 Review & Summary
AtCoderBeginnerContest179 Review & Summary
Django Girls Tutorial Summary First Half
AtCoder Review of past questions (first half of 12 / 8,9)