Codeforces-1475F Unusual Matrix


Problem

Portal


Thoughts


Accepted Code

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1010;

int n, row[N], col[N];
char a[N][N], b[N][N];

bool check()
{
    for(int i = 1 ; i <= n ; i ++ )
        for(int j = 1 ; j <= n ; j ++ )
        {
            if(a[i][j] == b[i][j] && (row[i]+col[j])&1) return false;
            if(a[i][j] != b[i][j] && ((row[i]+col[j])&1) == 0) return false;
        }
    return true;
}

signed main()
{
    int T; cin >> T;
    while(T -- )
    {
        cin >> n;
        for(int i = 1 ; i <= n ; i ++ ) cin >> a[i]+1;
        for(int i = 1 ; i <= n ; i ++ ) cin >> b[i]+1;
        row[1] = 0; // even
        for(int i = 1 ; i <= n ; i ++ ) 
        {
            if(a[1][i] == b[1][i]) col[i] = 0;
            else col[i] = 1;
        }
        for(int i = 2 ; i <= n ; i ++ )
        {
            if(a[i][1] == b[i][1]) row[i] = col[1];
            else row[i] = col[1] ^ 1;
        }
        if(check()) {puts("yes"); continue;}
        row[1] = 1; // odd
        for(int i = 1 ; i <= n ; i ++ )
        {
            if(a[1][i] == b[1][i]) col[i] = 1;
            else col[i] = 0;
        }
        for(int i = 2 ; i <= n ; i ++ )
        {
            if(a[i][1] == b[i][1]) row[i] = col[1];
            else row[i] = col[1] ^ 1;
        }
        if(check()) puts("yes");
        else puts("no");
    }                                        

    return 0;
}

Author: Mrhh
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Mrhh !
评论
 Previous
Codeforces-1475G Strange Beauty Codeforces-1475G Strange Beauty
ProblemPortal Meaning给定一个数组,问最少删去几个数组中的元素,使得数组中剩下的元素两两之间,大数是小数的倍数。 Accepted Code $O(NlogN)$#include <bits/stdc++.h>
Next 
Codeforces-1475D Cleaning the Phone Codeforces-1475D Cleaning the Phone
ProblemPortal Thoughts显然对于相同cp的app,我们优先选择更大的体积的app最优。 Accepted Code#include <bits/stdc++.h> #define int long long #
  TOC