Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int h1, w1, h2, w2;
- int a[1 << 4][1 << 4], b[1 << 4][1 << 4];
- int ans = 0;
- void GospersHack(int k, int n, const function<void(int)> &f)
- {
- if (k == 0) {
- f(0);
- return;
- }
- int s = (1 << k) - 1;
- int limit = (1 << n);
- while (s < limit) {
- f(s);
- int c = s & -s;
- int r = s + c;
- s = (((r ^ s) >> 2) / c) | r;
- }
- }
- int main(int argc, char **argv)
- {
- scanf("%d%d", &h1, &w1);
- for (int i = 0; i < h1; ++i)
- for (int j = 0; j < w1; ++j)
- scanf("%d", &a[i][j]);
- scanf("%d%d", &h2, &w2);
- for (int i = 0; i < h2; ++i)
- for (int j = 0; j < w2; ++j)
- scanf("%d", &b[i][j]);
- int hd = h1 - h2, wd = w1 - w2;
- auto alltest = [wd, w1](int rs) {
- auto ctest = [](int rs, int cs) {
- int work = 1;
- for (int ai = 0, bi = 0; ai < h1; ++ai) {
- if ((1 << ai) & rs)
- continue;
- for (int aj = 0, bj = 0; aj < w1; ++aj) {
- if ((1 << aj) & cs)
- continue;
- if (a[ai][aj] != b[bi][bj]) {
- work = 0;
- return;
- }
- ++bj;
- }
- ++bi;
- }
- ans = max(ans, work);
- };
- auto cbind = bind(ctest, rs, placeholders::_1);
- GospersHack(wd, w1, cbind);
- };
- GospersHack(hd, h1, alltest);
- printf("%s\n", ans == 1 ? "Yes" : "No");
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement