20240616

I'm motivated to work as I recharged during the weekend, but I'll pay attention to not going full throttle to avoid burnout. Oh, I think this Wednesday is a holiday.

It still takes a long time to solve Codeforces problems with difficulty 800. Maybe I can focus on the 800 problems this week.

On second thought, I might want to contine tackling problems with difficulty 900. I solved many 800 problems, but I felt that they were too easy. I cannot say that I solved them instantly tho.

Fixed the dependencies group in Poetry, adding a group for development.

1956A. Nene’s Game

We need to count the indexes in the [0..n] range for each round. Binary search can be used to find the largest index that fits in the range, and we can subtract the counts in the range from the players.

def brute_force(t: int, l: list[int]):
    li = 0
    while li < len(l) and t >= l[li]:
        li += 1
    return li


def binary_search(t: int, l: list[int]):
    li = 0
    ri = len(l)
    while ri - li > 1:
        mi = (li + ri) // 2
        if l[mi] == t:
            return mi + 1
        elif l[mi] < t:
            li = mi
        else:  # l[mi] > t
            ri = mi
    assert li + 1 == ri
    return li + 1


def solve(ni: int, a: list[int]) -> int:
    while ni >= a[0]:
        # rm = brute_force(ni, a)
        rm = binary_search(ni, a)
        ni -= rm

    return ni


for _ in range(int(input())):
    k, q = map(int, input().split())
    a = list(map(int, input().split()))
    n = list(map(int, input().split()))
    res: list[str] = []
    for ni in n:
        res.append(str(solve(ni, a)))
    print(" ".join(res))

1955A. Yogurt Sale

for _ in range(int(input())):
    n, a, b = map(int, input().split())
    if a * 2 <= b:
        print(n * a)
    else:
        if n % 2 == 0:
            print(n // 2 * b)
        else:
            print(n // 2 * b + a)

1950C. Clock Conversion

The conversion 12:00 -> 12:00 PM and 0:00 -> 12:00 AM are always confusing.

def convert_time(s: str) -> str:
    hh, mm = s.split(":")
    if hh == "00":
        return f"12:{mm} AM"
    elif hh == "12":
        return f"12:{mm} PM"
    elif 0 < int(hh) < 12:
        return f"{hh}:{mm} AM"
    else:  # 12 < int(hh) < 24
        return f"{str((int(hh) - 12)).zfill(2)}:{mm} PM"


for _ in range(int(input())):
    s = input()
    print(convert_time(s))

1950B. Upscaling

It took some time to implement this, but I could not deduct something reproducible.

for _ in range(int(input())):
    n = int(input())
    for i in range(n):
        s = ""
        for j in range(n):
            if j % 2 == 0:
                s += "##" if i % 2 == 0 else ".."
            else:
                s += ".." if i % 2 == 0 else "##"

        print(s)
        print(s)

1950A. Stair, Peak, or Neither?

for _ in range(int(input())):
    a, b, c = map(int, input().split())
    if a < b < c:
        print("STAIR")
    elif b > a and b > c:
        print("PEAK")
    else:
        print("NONE")

Pho Ga 1200 Bubble tea 500 Rolls 300

Total 2000 kcal

4km run (The new shoes don't fit still) push ups


TODO:


index 20240615 20240617