ABC146 Impressions

Participated in AtCoder Beginner Contest 146

I usually participate in the contest → I end up reviewing it, but I wanted to keep a record of my thoughts during the contest, so I decided to write an article. (I don't know how long it will last)

Problem A --Can't Wait for Holiday

I implemented it honestly.

A.py


S = input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
else:
    print(1)

Problem B-ROT N

I didn't know how to convert characters to ASCII code, so I asked Google teacher and found out ʻord () and chr () `.

Express the target character as 0 to 25, add N to shift it N times, and divide by 26 to find the remainder. Finally, add ʻord ("A") `to revert to the ASCII code in the uppercase alphabet. The answer was found by doing this for each character.

B.py


N = int(input())
S = input()

new_s = []
for c in S:
    new_s.append(chr((ord(c) - ord("A") + N) % 26 + ord("A")))

print("".join(new_s))

Problem C --Buy an Integer

At first I did a full search for N, but it was TLE. (That's right) I thought that PyPy would pass (?), And I repeated TLE. On the way, I realized that a binary search can be used to find the "maximum value among the conditions". I was able to pass it.

It is regrettable that I stuck to one method too much and took 30 minutes to reach the binary search.

C.py


a,b,x = map(int, input().split())

left = 0
right = 10**9 + 1
while right > left + 1:
    n = (left + right) // 2
    if a * n + b * len(str(n)) <= x:
        left = n
    else:
        right = n

print(left)

Problem D-Coloring Edges on Tree

It was totally useless. The graph problem gets a rejection reaction the moment I see it, so I want to study hard somewhere, but I haven't touched it ...

Do you have any good learning materials? ??

Summary

I want to turn green soon!

Recommended Posts

ABC146 Impressions
ABC168
ABC164
ABC174
ABC175
ABC170
ABC182
ABC153
AtCoder ABC176
ABC167 WriteUp
AtCoder ABC177
Beginner ABC154 (Python)
Beginner ABC156 (Python)
abc154 participation report
AtCoder ABC187 Python
AtCoder ABC188 Python
Beginner ABC155 (Python)
Beginner ABC157 (Python)
AtCoder ABC 175 Python