20240603

1732B. Ugu

for _ in range(int(input())):
    n = int(input())
    s = input()

    count = 0
    i = 0
    while i < n - 1 and s[i] == "0":
        i += 1

    while i < n - 1:
        if s[i] != s[i + 1]:
            count += 1
        i += 1

    print(count)

1709B. Also Try Minecraft

Sum Array (?) is a popular technique to solve this sort of problem.

n, m = map(int, input().split())
a = list(map(int, input().split()))

sum_arr: list[int] = [0] * n
for i in range(n):
    if i == 0:
        continue
    sum_arr[i] = sum_arr[i - 1] + max(a[i - 1] - a[i], 0)

sum_arr_rev: list[int] = [0] * n
for i in range(n - 1, -1, -1):
    if i == n - 1:
        continue
    sum_arr_rev[i] = sum_arr_rev[i + 1] + max(a[i + 1] - a[i], 0)

for i in range(m):
    s, t = map(int, input().split())
    if s < t:
        print(sum_arr[t - 1] - sum_arr[s - 1])
    else:
        print(sum_arr_rev[t - 1] - sum_arr_rev[s - 1])

Sushi 800 Lunchable 300 yogurt 800

Total 1900 kcal

6km Run


TODO:


index 20240602 20240604