I was debugging issues, blaming libraries, and checking code in GitHub hectically, only to find out that I was making a stupid mistake. I'm tired.
It's tagged as “1400”, so I won't try to understand it completely or expect me to solve the problem in a contest.
I skimmed the editorial and noticed that my algorithm was not far
from the solution. What I was missing is the part
or a[n - i - 1] == a[n - i - 2]
.
But to be honest, I cannot explain how to replicate the solution.
def count_disturbance(a: list[int]) -> int:
int = 0
count: for i in range(len(a) - 1):
if a[i] == a[i + 1]:
+= 1
count return count
def minimize_disturbance(a: list[int]) -> int:
int = len(a)
n: for i in range(n - 1):
if a[i] == a[i + 1] or a[n - i - 1] == a[n - i - 2]:
+ 1], a[n - i - 2] = a[n - i - 2], a[i + 1]
a[i
for _ in range(int(input())):
int = int(input())
_n: list[int] = list(map(int, input().split()))
a:
minimize_disturbance(a)
int = count_disturbance(a)
disturbance: print(disturbance)
Udon 1000 Corn 100 Protein shake 300 Rice 400
Total 1800 kcal
MUST:
TODO: