跳到正文

题解

CF1983B 题解

Vitamin_B约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年7月8日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟
获赞
1
题目
CF1983B

版本

  1. v1当前

思路

显然,不管如何操作,每行、每列之和除以 33 的余数始终不变。所以,我们只要枚举每行、每列,看看和除以 33 的余数是否相同就行。

代码

C++
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n, m;
string a[505], b[505];
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> n >> m;
		for (int i = 0; i < n; ++ i)
			cin >> a[i];
		for (int i = 0; i < n; ++ i)
			cin >> b[i];
		for (int i = 0, s1, s2; i < n; ++ i) {
			s1 = s2 = 0;
			for (int j = 0; j < m; ++ j)
				s1 += a[i][j] - '0', s2 += b[i][j] - '0';
			if (s1 % 3 != s2 % 3)
				goto no;
		}
		for (int j = 0, s1, s2; j < m; ++ j) {
			s1 = s2 = 0;
			for (int i = 0; i < n; ++ i)
				s1 += a[i][j] - '0', s2 += b[i][j] - '0';
			if (s1 % 3 != s2 % 3)
				goto no;
		}
		cout << "Yes\n";
		continue ;
no:
		cout << "No\n";
	}
	return 0;
}
原文
存档评论2 条抓取于