20241015 ◎

瞬時にやる気を燃やす31の心理技術 by ゆうきゆう

Retried 2008B. Square or Not

I could not think of the optimal answer :cry:

2008B. Square or Not

Assume that string was created from the beautiful binary matrix with size r * c.

If r <= 2 or c <= 2, then the whole matrix consists of ‘1’. THis means that the string will have only one character and this is the only case such happening. So, If the whole string is constructed out of ‘1’, we print “Yes” only if the size of the string is 4, since only r = c = 2 is a good matrix for us.

It makese sense so far.

Otherwise, we have at least one ‘0’ in the string.

Let's look at what is the index of the first ‘0’.

If it has index r + 1, since the whole first line and the first character of the first line equal to ‘1’, so now, we have a fixed value of r (index of the first ‘0’ minus 1) and the answer is “Yes” only if r is the square root of n.

I think I now understand the solution.

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

    if len(s) < 4:
        print("No")
        continue

    if len(s) == 4:
        print("Yes")
        continue

    edge: int = s.find("0") - 1
    if edge * edge == n:
        print("Yes")
    else:
        print("No")

O(n)


Protein snacks 200 Yogurt 300 Tajin gummies 800 Chips 600 M&M's 100

Total 2000 kcal


MUST:

TODO:


index 20241014 20241016