Advertisement
ahmed-smara

Untitled

Nov 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. #define endl '\n'
  5. #define m3lsh return 0;
  6. typedef long long ll;
  7. typedef unsigned long long ull;
  8.  
  9. ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
  10. ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
  11.  
  12. int  dix[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
  13. int  diy[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
  14. int main() {
  15.     fast;
  16.     char grid[100][100];
  17.     int n, m;
  18.     cin >> n >> m;
  19.     for (int i = 0; i < n; i++)
  20.         for (int j = 0; j < m; j++)
  21.             cin >> grid[i][j];
  22.     bool ok = 0;
  23.     string ch = "bay";
  24.     for (int i = 0; i < n; i++) {
  25.         string procss = "";
  26.         for (int j = 0; j < m - 2; j++) {
  27.             procss = char(grid[i][j]);
  28.             procss += char(grid[i][j + 1]);
  29.             procss += char(grid[i][j + 2]);
  30.             if (procss == ch)ok = 1;
  31.             reverse(procss.begin(), procss.end());
  32.             if (procss == ch)ok = 1;
  33.         }
  34.     }
  35.     for (int i = 0; i < m; i++) {
  36.         string procss = "";
  37.         for (int j = 0; j < n - 2; j++) {
  38.             procss = grid[j][i];
  39.             procss += grid[j + 1][i];
  40.             procss += grid[j + 2][i];
  41.             if (procss == ch)ok = 1;
  42.             reverse(procss.begin(), procss.end());
  43.             if (procss == ch)ok = 1;
  44.         }
  45.     }
  46.     for (int i = 0; i < min(n, m) - 2; i++) {
  47.         string procss = "";
  48.         procss = grid[i][i];
  49.         procss += grid[i + 1][i + 1];
  50.         procss += grid[i + 2][i + 2];
  51.         if (ch == procss)ok = 1;
  52.         reverse(procss.begin(), procss.end());
  53.         if (procss == ch)ok = 1;
  54.     }
  55.     int row = 0;
  56.     for (int i = m - 1; i >= 2; i--) {
  57.         string procss = "";
  58.         if (row < n - 2) {
  59.             procss = grid[row][i];
  60.             procss += grid[row + 1][i - 1];
  61.             procss += grid[row + 2][i - 2];
  62.             if (procss == ch)ok = 1;
  63.             reverse(procss.begin(), procss.end());
  64.             if (ch == procss)ok = 1;
  65.             row--;
  66.         }
  67.     }
  68.     if (ok)cout << "YES" << endl;
  69.     else cout << "NO" << endl;
  70.     m3lsh;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement