20240710

灼熱カバディの最新刊アツすぎだろ!

Bourne-Again Shell, bash

Andrew S. Tanenbaum, MINIX

1983B. Corner Twist

I could not solve this problem during the contest. As I checked the solution, I noticed that I was very close to the answer.

2*2 square can be used to generate the same result as the operation applied on any rectangle.

So, I can focus on applying 2*2 square to a to make it b (?), i.e., thinking about applying 2*2 square [[1, 2], [2, 1]] or [[2, 1], [1, 2]] should be enough to consider applying i*j square.

To convert a into b, I can iterate through 1…n-1 for rows and 1…m-1 for columns, applying [[1, 2], [2, 1]] or [[2, 1], [1, 2]].

Feedback 215 Good problem 19 Average problem 292 Bad problem 37 Did not solve

It's interesting the community seems not to like the problem. I have little experience in competitive programming and don't know what determines whether a problem is good, and I'm grateful to the author for making the contest happen.

We can make the first n - 1 rows and m - 1 columns equal by doing that, but we need to check if the last row and column of a (modified) and b equal.

Note that the sum of each row and each column stays constant after each operation.

both rows and columns will get (1 + 2) mod 3 by applying the 2*2 square, so any number of operations don't change the sum mod 3 for rows and columns.

That being said, the nth row and mth column of a (modified) and b need to have the same value after the operations <=> Every row and colum need to have the same value (mod 3).

def possible(n: int, m: int, a: list[int], b: list[int]) -> bool:
    for rowi in range(n):
        if sum(a[rowi]) % 3 != sum(b[rowi]) % 3:
            return False

    for coli in range(m):
        asum: int = 0
        bsum: int = 0
        for rowi in range(n):
            asum = (asum + a[rowi][coli]) % 3
            bsum = (bsum + b[rowi][coli]) % 3
        if asum != bsum:
            return False

    return True


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

    if possible(n, m, a, b):
        print("YES")
    else:
        print("NO")

I'm still not quite sure if I understand this problem properly.


Snacks 20g Protein shake 20g

Total carbohydrate 40g


MUST:

TODO:


index 20240709 20240711