Just go around the loop, find the unmatched indexes, and print XtoY.
S = input()
for i in range(26):
a = chr(i + ord('a'))
if S[i] == a:
continue
print('%sto%s' % (a, S[i]))
break
B 1218 Something Like a Theorem
Even if I searched all over without thinking about anything, it didn't become TLE, and that was it.
n, z = map(int, input().split())
for x in range(1, z + 1):
for y in range(x, z + 1):
if x ** n + y ** n == z ** n:
print('Yes')
exit()
print('No')
As an operation, A i </ sub> = i on the far left is operated and repeated, but of course if you implement it naively to simulate it, it will be TLE (Note that it is implemented with heapq and experienced Orz). If you think about it carefully, add up the number of times you erased A i + 1 </ sub> to A N </ sub> to the right of A i </ sub>. Therefore, when the stacking is c, c + A i </ sub> should be a multiple of i. When scanning from the right while stacking c, * O * (* N *) is displayed. Can be solved.
N, *A = map(int, open(0).read().split())
c = 0
for i in range(N - 1, -1, -1):
if (A[i] + c) % (i + 1) != 0:
print('No')
break
c += (A[i] + c) // (i + 1)
else:
print('Yes')
Recommended Posts