AtCoder Beginner Contest 158 Participation Report

AtCoder Beginner Contest 158 Participation Report

ABC158A - Station and Bus

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

ABC158B - Count Balls

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)

ABC158C - Tax Increase

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)

ABC158D - String Formation

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)

ABC158E - Divisible Substring

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

AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 151 Participation Report
AtCoder Beginner Contest 176 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 164 Participation Report
AtCoder Beginner Contest 150 Participation Report
AtCoder Beginner Contest 158 Participation Report
AtCoder Beginner Contest 180 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 041 Participation Report
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 Acing 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 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 167 Review
AtCoder Library Practice Contest Participation Report (Python)
AtCoder Beginner Contest 182 Note