20241103 ◎

2036A. Quintomania - 800

Nothing to note

for _ in range(int(input())):
    n: int = int(input())
    a: list[int] = list(map(int, input().split()))
    for i in range(n - 1):
        if abs(a[i + 1] - a[i]) not in (5, 7):
            print("NO")
            break
    else:
        print("YES")

2036B. Startup - 800

My submission has been hacked and exceeded the time limit.

#1097423

from collections import defaultdict


for _ in range(int(input())):
    n, k = map(int, input().split())

    d = defaultdict(int)
    for _ in range(k):
        b, c = map(int, input().split())
        d[b] += c

    print(sum(sorted(d.values(), reverse=True)[:n]))

but my solution seems to be the same as the one on the editorial, and its time complexity should be O(klogk). sorted() uses Timsort…

I tried to browse others' solutions, but Codeforces does not offer a convenient UI for that.

My gut feeling is that there is a pitfall when using Python, as Python is not a good language for competitive programming, but it may not be that important for me right now. I want to focus on data structures & algorithms, not useful techniques for competitive programming.

2036D. I Love 1543 - 900

The approach to breaking down the problem and thinking about functions I would want to use worked this time. I feel that I broke a wall with this problem.

Just the same as everyday programming (and all other matters in life), breaking down a big problem into smaller ones and dealing with them one by one worked.

def count_occurrance(a: list[str], t) -> int:
    count: int = 0
    for i in range(len(a) - 3):
        if "".join(a[i : i + 4]) == t:
            count += 1
    return count


def flatten_layer(mat: list[list[str]], n: int, m: int, layer: int) -> list[str]:
    assert layer >= 0

    result: list[str] = []
    # up, excluding two edges
    for col_i in range(layer + 1, m - layer - 1):
        result.append(mat[layer][col_i])
    # right
    for row_i in range(layer, n - layer):
        result.append(mat[row_i][m - layer - 1])

    # bottom, excluding two edges
    for col_i in range(m - layer - 2, layer, -1):
        result.append(mat[n - layer - 1][col_i])
    # left
    for row_i in range(n - layer - 1, layer - 1, -1):
        result.append(mat[row_i][layer])

    # circulate
    result.extend(result[:3])

    return result


for _ in range(int(input())):
    n, m = map(int, input().split())
    mat = []
    for _ in range(n):
        mat.append(list(input()))

    res: int = 0
    for i in range(min(n // 2, m // 2)):
        flat_layer: list[str] = flatten_layer(mat, n, m, i)
        res += count_occurrance(flat_layer, "1543")

    print(res)

Protein bars 450 Protein chips 150 Sushi bowl 800 Salad 200 Pocky 200

Total 1800 kcal


MUST:

TODO:


index 20241102 20241104