题解:【ARC227】D - Median of Binary Strings
题解:ARC227 - D
题面:Median of Binary Strings。
解题思路
先分析一下操作:选
把它拆分一下,取任意两个位置
也就是说,对于一个
所以如果所有
因为要标记每一个组合,因此时间复杂度为
代码实现
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <atcoder/all>
#define endl '\n'
using namespace std;
typedef long long ll;
int main(int argc, char* argv[]) {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n, m, times;
cin >> n >> m >> times;
// 记录所有出现的组合,第三维表示四种组合情况
vector<vector<array<bool, 4>>> fg(m, vector<array<bool, 4>>(m));
for (int k = 0; k < n; k++) {
string s; cin >> s;
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++) {
fg[i][j][(s[i] - '0') * 2 + s[j] - '0'] = true;
}
}
for (int k = 0; k < times; k++) {
string s; cin >> s;
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++) {
if (!fg[i][j][(s[i] - '0') * 2 + s[j] - '0']) {
cout << "No" << endl;
goto nxt;
}
}
cout << "Yes" << endl; nxt:;
}
return 0;
}