Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define endl '\n'
- #define m3lsh return 0;
- typedef long long ll;
- typedef unsigned long long ull;
- ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
- ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
- int dix[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
- int diy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
- int main() {
- fast;
- char grid[100][100];
- int n, m;
- cin >> n >> m;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- cin >> grid[i][j];
- bool ok = 0;
- string ch = "bay";
- for (int i = 0; i < n; i++) {
- string procss = "";
- for (int j = 0; j < m - 2; j++) {
- procss = char(grid[i][j]);
- procss += char(grid[i][j + 1]);
- procss += char(grid[i][j + 2]);
- if (procss == ch)ok = 1;
- reverse(procss.begin(), procss.end());
- if (procss == ch)ok = 1;
- }
- }
- for (int i = 0; i < m; i++) {
- string procss = "";
- for (int j = 0; j < n - 2; j++) {
- procss = grid[j][i];
- procss += grid[j + 1][i];
- procss += grid[j + 2][i];
- if (procss == ch)ok = 1;
- reverse(procss.begin(), procss.end());
- if (procss == ch)ok = 1;
- }
- }
- for (int i = 0; i < min(n, m) - 2; i++) {
- string procss = "";
- procss = grid[i][i];
- procss += grid[i + 1][i + 1];
- procss += grid[i + 2][i + 2];
- if (ch == procss)ok = 1;
- reverse(procss.begin(), procss.end());
- if (procss == ch)ok = 1;
- }
- int row = 0;
- for (int i = m - 1; i >= 2; i--) {
- string procss = "";
- if (row < n - 2) {
- procss = grid[row][i];
- procss += grid[row + 1][i - 1];
- procss += grid[row + 2][i - 2];
- if (procss == ch)ok = 1;
- reverse(procss.begin(), procss.end());
- if (ch == procss)ok = 1;
- row--;
- }
- }
- if (ok)cout << "YES" << endl;
- else cout << "NO" << endl;
- m3lsh;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement