AtCoder Beginner Contest 161 Participation Report

AtCoder Beginner Contest 161 Participation Report

ABC161A - ABC Swap

Break through in 3 minutes. Just write. It took a long time because the online code test was clogged.

X, Y, Z = map(int, input().split())

X, Y = Y, X
X, Z = Z, X
print(X, Y, Z)

ABC161B - Popular Vote

Break through in 4 minutes. Since the threshold is 1/4 * M of the total number of votes, first find it and check if there are M or more products with more votes than that threshold. Online code test is clogged and takes time I have.

N, M = map(int, input().split())
A = list(map(int, input().split()))

threshold = sum(A) / (4 * M)
if len([a for a in A if a >= threshold]) >= M:
    print('Yes')
else:
    print('No')

ABC161C - Replacing Integer

Break through in 6 minutes. If N exceeds K, first take the remainder. After N becomes less than K, it will converge if it is turned appropriately, because AC is output after throwing it 1000 times appropriately. The result is okay. I will reconsider it seriously later.

N, K = map(int, input().split())

result = N
if N > K:
    result = min(result, N % K)
for i in range(1000):
    result = min(result, abs(result - K))
print(result)

Addendum: Let N% K be x. Since x <K, the absolute value of the difference between x and K is K --x. By the way, the absolute value of the difference between K and K --x is x. Therefore, x and The smaller K-x is the answer.

N, K = map(int, input().split())

x = N % K
print(min(x, K - x))

ABC161D - Lunlun Number

Break through in 49 minutes. Naturally, TLE is required in the loop while increasing the number by 1, so consider skipping. The number of run-runs is 21 after 12. 13 has a problem with 3, but 1 instead of 3. The run-run number does not occur until the digit becomes 2. If a problem occurs, advance the upper digit by one and flush the digits below it to 0. That alone, 13 → 20 → 30 Therefore, if the value of the problematic digit is smaller than the previous digit, we decided to advance the value of the problematic digit by one. Now, 13 → 21 is advanced. I'll fix the code later because is_lunlun is a crap that returns a number instead of a boolean.

K = int(input())


def is_lunlun(i):
    result = -1
    n = [ord(c) - 48 for c in str(i)]
    for j in range(len(n) - 1):
        if abs(n[j] - n[j + 1]) <= 1:
            continue
        if n[j] < n[j + 1]:
            for k in range(j + 1, len(n)):
                n[k] = 0
            result = int(''.join(str(k) for k in n))
            result += 10 ** (len(n) - (j + 1))
        else:
            result = int(''.join(str(k) for k in n))
            result += 10 ** (len(n) - (j + 2))
        break
    return result


i = 1
while True:
    # print(i)
    t = is_lunlun(i)
    if t == -1:
        K -= 1
        if K == 0:
            print(i)
            exit()
        i += 1
    else:
        i = t

ABC161E - Yutori

I passed because F seems to be obviously easier to look at the standings.

ABC161F - Division or Substraction

I couldn't break through.

Postscript: I added about 30 minutes and solved it. Total about 1 hour? N ≤ 10 12 </ sup>, so if you turn the loop obediently, TLE is inevitable. When N becomes 1, N = K a </ sup> * (b * K + 1) (a, b ≥ 0). In the region of K * K> N, N = a * K + 1 (excluding K = N, N -1) There is only a pattern of a ≥ 2). Candidates are K of 2 or more and sqrt (N) or less, and (N -1) / K when N -1 is divisible by K. It is at most 2 * to check all candidates. 10 6 </ sup> so it's in time.

N = int(input())

if N == 2:
    # K = 2
    print(1)
    exit()

result = 2  # K = N - 1, N
for K in range(2, int(N ** 0.5 + 1)):
    t = N
    while t >= K and t % K == 0:
        t //= K
    if t % K == 1:
        result += 1

    if (N-1) % K == 0 and (N-1) // K > K:
        result += 1
print(result)

Recommended Posts

AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 161 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 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 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 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review