I finished the E problem in 20 minutes, and I thought that this was the first completeness !? I was supposed to watch for 80 minutes.
Break through in one and a half minutes. Just write.
A = input()
if A.isupper():
print('A')
else:
print('a')
Break through in one and a half minutes. Just write. Isn't it rare that sort appears in B problem?
N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K]))
ABC171C - One Quadrillion and One Dalmatians
It broke through in 5 and a half minutes. I had written a bidirectional conversion of EXCEL column names and numbers in the past, so I pulled it out and dropped it in Python.
N = int(input())
t = []
while N > 0:
N -= 1
t.append(chr(N % 26 + ord('a')))
N //= 26
print(''.join(t[::-1]))
Break through in 6 minutes. I remembered last week's ABC170E --Count Median. Looping the operation of subtracting the current value and adding the new value Is similar. If you calculate the total value for each loop, it will be * O * (* NQ ), but the amount of calculation will be * O * ( N * + * Q *) by subtracting and adding. ) Can be solved.
from sys import stdin
readline = stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
t = [0] * (10 ** 5 + 1)
s = sum(A)
for a in A:
t[a] += 1
for _ in range(Q):
B, C = map(int, readline().split())
s -= B * t[B]
s += C * t[B]
t[C] += t[B]
t[B] = 0
print(s)
It broke through in 5 minutes. It was too easy at first glance, and I thought it was a misreading for a moment. From the characteristics of xor, I know that I will come out if I xor all xor other than myself and all xor including myself. And you can see that if you xor all a, you can do all xor including yourself.
N = int(input())
a = list(map(int, input().split()))
t = 0
for e in a:
t ^= e
print(*[e ^ t for e in a])
I don't know at all. Thank you very much. Even if I insert one o in the oof of the input example, it doubles three, but I can't think of how to remove this duplication.
Postscript: I implemented it according to the explanation video. I posted it without thinking and became TLE, but I was asked, but since I made a table of 10 12 </ sup>, of course I mean, don't pass PyPy well, even though it's barely possible, this .... However, the mjd feeling at the moment when I heard the explanation that both abc and aaa are actually the same. The experience value gained from this problem was amazing. I think it was expensive.
K = int(input())
S = input()
m = 1000000007
def make_factorial_table(n):
result = [0] * (n + 1)
result[0] = 1
for i in range(1, n + 1):
result[i] = result[i - 1] * i % m
return result
def mcomb(n, k):
if n == 0 and k == 0:
return 1
if n < k or k < 0:
return 0
return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m
fac = make_factorial_table(len(S) - 1 + K)
result = 0
for i in range(K + 1):
result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
result %= m
print(result)
Recommended Posts