20241028 ◎

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.

2033C. Sakurako’s Field Trip - 1400

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:
    count: int = 0
    for i in range(len(a) - 1):
        if a[i] == a[i + 1]:
            count += 1
    return count


def minimize_disturbance(a: list[int]) -> int:
    n: int = len(a)
    for i in range(n - 1):
        if a[i] == a[i + 1] or a[n - i - 1] == a[n - i - 2]:
            a[i + 1], a[n - i - 2] = a[n - i - 2], a[i + 1]


for _ in range(int(input())):
    _n: int = int(input())
    a: list[int] = list(map(int, input().split()))

    minimize_disturbance(a)

    disturbance: int = count_disturbance(a)
    print(disturbance)

Udon 1000 Corn 100 Protein shake 300 Rice 400

Total 1800 kcal


MUST:

TODO:


index 20241027 20241029