20240826

2003A. Turtle and Good Strings - 800

My idea

k = 2 is the simplest scenario, and if it's impossible with k = 2, it's also impossible with k >= 3.

When we think about k = 3, the first character of t1 must be different from last characters of t2 and t3, but the condition is more strict than thinking about only t1 v.s. t2. Therefore, I only consider k = 2 for simplicity's sake. (not very confident about the explanation).

When k = 2, we just have to check if there is a pair of (t1, t2) where t1[0] != t2[-1] and t1[-1] != t2[0].

def possible(n: int, s: list[str]) -> bool:
    for i in range(n - 1):
        if s[i] != s[i + 1]:
            return s[0] != s[n - 1]
    return False


for _ in range(int(input())):
    n: int = int(input())
    s: list[str] = list(input())
    if possible(n, s):
        print("YES")
    else:
        print("NO")

The answer from the editorial

Codeforces Round 968 (Div. 2) Editorial

A necessary condition for s to be good is that s1 != sn.

For a string s where s1 != sn, let t1 be a string composed of just the simple character s1, and let t2 be a string composed of the n - 1 characters from s2 to sn.

In this way, the condition is satisfied.

Therefore, if s1 != sn, the answer is “Yes”; otherwise, the answer is “No”.

I misunderstood the problem. I thought t2's first character must not be equal to t1's last character, but the condition is

For all 1 <= i < j <= k, the first character of ti isn't equal to the last character of tj. We only have to compare the first character of ti with the last characters of strings come after ti.

The answer is as simple as

for _ in range(int(input())):
    n: int = int(input())
    s: str = input()
    if s[0] != s[-1]:
        print("YES")
    else:
        print("NO")

News: Python Software Foundation suspended Tim Peters for three months

discuss.python.org: Three month suspensions for a Core Developer

Lunduke’s blog: Python Bans Prominent Dev for Enjoying the Wrong Old SNL Sketch

Chris’s Blog

When Tim Peters won the 2017 Python Distinguished Service Award, he had already been working on Python for over 20 years.

I didn't know that Tim has such a long history with the Python community.

The Register: Core Python developer suspended for three months

Python's sorting algorithm is known as Timsort, which is a combination of Merge sort and Insertion sort. The best-case time complexity of the Insertion Sort is O(n), and leveraging the fact improves the time complexity of Merge Sort, which is O(nlogn) at best. As I remember correctly, the reason why Quick Sort is not used is that Quick Sort does not retain the order of elements.

Quicksort - Wikipedia

Most implementations of quicksort are not stable, meaning that the relative order of equal sort items is not preserved.

Even an amateur programmer like myself knows the name Tim Peters, who is the inventor of Timsort. Also, he is known as an author of “Zen of Python,” which heavily impacted my life as a programmer.

It's surprising to know that he has been suspended from the Python council.

Most of the communications happening seem to be private, but as far as I read the Chris's blog and Lunduke's one, the suspension of Tim seems to be unreasonable.

I don't have enough information to judge the situation, and I also don't have the power to influence the community, but I just hope the Python community and its ecosystem will not fall apart.


Rice 400 Meat and Potatos 500 Protein bars 400 Protein shake 200 Salad 400 Yogurt 200

Total 2100 kcal

10k walking


MUST:

TODO:


index 20240825 20240827