1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include "bits/stdc++.h" #include "iomanip"
using namespace std;
#define fastIO() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define pb push_back #define judge(x) if (x) cout << "Yes" << endl; else cout << "No" << endl #define loop(t) while (t-- > 0) #define enhanceFor(t) for (auto it: t) #define all(a) a.begin(),a.end() #define rall(a) rbegin(a), rend(a) #define put(a) for (auto &_x: a) cin >> _x;
using vl = vector<ll>; using vvl = vector<vl>;
static bool check(vl a, vl b) { int p = 0; for (int i = 0; i < a.size() && p < b.size(); ++i) { if (a[i] == b[p])++p; } return p == b.size(); }
bool checks(vl a, vl b){ for (int i = 0; i < a.size(); ++i) { if (a[i]!=b[i])return 0; } return 1; }
static bool check(vvl a, vvl b, int start, set<int> set) { int p = 1; for (int i = start; i < a.size() && p < b.size(); ++i) { vl aa=a[i]; vl aaa; for (int v:set){ aaa.pb(aa[v]); } if (checks(aaa,b[p]))++p; } return p == b.size(); }
bool flag = 0;
bool confirm(vl a, vl b, set<int> &set) { int p = 0; for (int i = 0; i < a.size() && p < b.size(); ++i) { if (a[i] == b[p]) set.insert(i), ++p; } return p == b.size(); }
int main() { fastIO(); int h1, w1, h2, w2; cin >> h1 >> w1; vvl a(h1, vl(w1));
for (int i = 0; i < h1; ++i) { put(a[i]); } cin >> h2 >> w2; vvl b(h2, vl(w2)); for (int i = 0; i < h2; ++i) { put(b[i]); } vl bb = b[0]; for (int i = 0; i < h1 && !flag; ++i) { vl aa = a[i]; set<int> set; if (confirm(aa, bb, set)) { if (check(a, b, i + 1, set)) flag = 1; } } judge(flag); }
|