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