Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by Savva Morev 2019
- //
- #define _CRT_SECURE_NO_WARNINGS
- #pragma GCC optimize("Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cmath>
- #include <limits>
- #include <ctime>
- #include <cassert>
- #include <map>
- #include <set>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <functional>
- #include <fstream>
- #include <sstream>
- #include <stack>
- #include <queue>
- #include <numeric>
- #include <iterator>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define sz(c) ((int)c.size())
- #define pb push_back
- #define pf push_front
- #define fi first
- #define se second
- #define all(x) (x).begin(), (x).end()
- #define endl "\n"
- #define x first
- #define y second
- typedef long double ld;
- typedef long long ll;
- typedef pair <int, int> pii;
- const int N = int(1e6) + 111;
- const int INF = int(1e9) + 111;
- const ll LINF = ll(1e18) + 111;
- const ld EPS = 1e-7;
- const ld PI = 3.141592653589793238462643;
- const ll MOD = 1e9 + 7;
- const int M = int(1e6) + 111;
- const int P = int(1e6) + 3;
- template<class T> void chmin(T& a, const T& b) { if (a > b) a = b; }
- template<class T> void chmax(T& a, const T& b) { if (a < b) a = b; }
- template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
- template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
- template<class T> T abs(T a) { return a >= 0 ? a : -a; }
- int n, m;
- vector <vector <char>> a;
- int _n, _m;
- vector <vector <char>> b;
- bool check(int x, int y) {
- for (int i = x; i < x + _n; i++) {
- for (int j = y; j < y + _m; j++) {
- if (b[i - x][j - y] != a[i][j])
- return 0;
- }
- }
- return 1;
- }
- bool check() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (i + _n > n || j + _m > m) continue;
- if (check(i, j)) {
- return 1;
- }
- }
- }
- return 0;
- }
- void rotate() {
- vector <vector <char>> tmp(_m, vector <char> (_n));
- for (int i = 0; i < _n; i++)
- for (int j = 0; j < _m; j++) {
- tmp[j][_n - 1 - i] = b[i][j];
- }
- b = tmp;
- swap(_n, _m);
- }
- void print() {
- for (int i = 0; i < _n; i++) {
- for (int j = 0; j < _m; j++) {
- cout << b[i][j] << " ";
- }
- cout << endl;
- }
- }
- vector <vector<char>> cut(int x, int y, int _x, int _y) {
- _n = _x - x + 1;
- _m = _y - y + 1;
- vector <vector<char>> tmp(_n, vector <char>(_m));
- for (int i = x; i <= _x; i++) {
- for (int j = y; j <= _y; j++) {
- tmp[i - x][j - y] = b[i][j];
- }
- }
- return tmp;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- //ifstream cin("levenshtein.in");
- //ofstream cout("levenshtein.out");
- cin >> n >> m;
- a.resize(n, vector <char> (m));
- bool f = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cin >> a[i][j];
- f |= (a[i][j] == '*');
- }
- }
- cin >> _n >> _m;
- b.resize(_n, vector <char> (_m));
- int x, y;
- int _x, _y;
- x = y = _x = _y = -1;
- for (int i = 0; i < _n; i++) {
- for (int j = 0; j < _m; j++) {
- cin >> b[i][j];
- if (b[i][j] == '*') {
- if (x == -1) {
- x = _x = i;
- y = _y = j;
- }
- x = min(x, i);
- y = min(y, j);
- _x = max(_x, i);
- _y = max(_y, j);
- }
- }
- }
- if (x == -1) {
- cout << (f ? "NO" : "YES");
- return 0;
- }
- b = cut(x, y, _x, _y);
- for (int it = 0; it < 4; it++) {
- print();
- if (check()) {
- cout << "YES";
- return 0;
- }
- rotate();
- }
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement