ABC159A - The Number of Even Pairs
Break through in 3 and a half minutes. Odd or even pairs are the answer. If you know k </ sub> C 2 </ sub> = k (k-1) / 2 The rest is just writing, but it's difficult for A problem, this.
N, M = map(int, input().split())
print(N * (N - 1) // 2 + M * (M - 1) // 2)
Break through in 12 minutes. It took too long orz. Write a check routine, then convert 1-indexed to 0-indexed and check as told. It's difficult for B problem, isn't it? this.
S = input()
def is_palindrome(s):
return s == s[::-1]
N = len(S)
if not is_palindrome(S):
print('No')
exit()
if not is_palindrome(S[:(N - 1) // 2]):
print('No')
exit()
if not is_palindrome(S[(N + 3) // 2 - 1:]):
print('No')
exit()
print('Yes')
Break through in 2 minutes. A Isn't this a mistake?
L = int(input())
print((L / 3) ** 3)
Break through in 10 minutes. Of course, if you recalculate all the numbers when the kth ball is excluded, TLE. For the time being, calculate the number when you do not pull out, and adjust the number for the kth value and answer. ..
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
if a in d:
d[a] += 1
else:
d[a] = 1
s = 0
for k in d:
s += d[k] * (d[k] - 1) // 2
for i in range(N):
t = d[A[i]]
print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)
Lost. Cumulative sum reduced the number of white chocolates from * O * (* HW ) to * O * ( H *) and brute force with recursive function, but it was TLE & WA. So there is a bug in the implementation somewhere ...
Recommended Posts