Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <string>
- using namespace std;
- int n, m;
- string a[1010];
- bool ans = 0;
- char c;
- bool check(int x, int y)
- {
- if (x < 0 || x >= n || y < 0 || y >= m)
- return false;
- return a[x][y] == c;
- }
- bool solve(int x, int y)
- {
- c = a[x][y];
- bool g;
- g = 1;
- for (int i = 0; i < 5; i++)
- g &= check(x, y + i);
- if (g)
- return true;
- g = 1;
- for (int i = 0; i < 5; i++)
- g &= check(x + i, y);
- if (g)
- return true;
- g = 1;
- for (int i = 0; i < 5; i++)
- g &= check(x + i, y + i);
- if (g)
- return true;
- g = 1;
- for (int i = 0; i < 5; i++)
- g &= check(x + i, y - i);
- if (g)
- return true;
- return false;
- }
- int main()
- {
- freopen("tic-tac-toe.in", "r", stdin);
- freopen("tic-tac-toe.out", "w", stdout);
- cin >> n >> m;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int x = 0; x < n; x++)
- for (int y = 0; y < m; y++)
- {
- if (a[x][y] == '.')
- continue;
- ans |= solve(x, y);
- }
- if (ans)
- printf("Yes\n");
- else
- printf("No\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement