fork(1) download
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <assert.h>
  4. #include <set>
  5. #include <map>
  6. #include <complex>
  7. #include <iostream>
  8. #include <time.h>
  9. #include <math.h>
  10. #include <stack>
  11. #include <stdlib.h>
  12. #include <memory.h>
  13. #include <bitset>
  14. #include <math.h>
  15. #include <string>
  16. #include <string.h>
  17. #include <queue>
  18. #include <vector>
  19.  
  20. using namespace std;
  21.  
  22. const int MaxN = 1e5 + 10;
  23. const int INF = 1e9;
  24. const int MOD = 1e9 + 7;
  25.  
  26. const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
  27. const int dy[] = {-1, 0, 1, -1, 1, 0, -1, 1};
  28.  
  29. int main() {
  30. // freopen("input.txt", "r", stdin);
  31. ios::sync_with_stdio(false);
  32. cin.tie(NULL);
  33. int t;
  34. cin >> t;
  35. for (int ti = 0; ti < t; ++ti) {
  36. int n, k;
  37. cin >> n >> k;
  38. vector < string > s(n);
  39. for (int i = 0; i < n; ++i) {
  40. cin >> s[i];
  41. }
  42. bool ok = false;
  43. for (int i = 0; i < n; ++i) {
  44. for (int j = 0; j < n; ++j) {
  45. if (s[i][j] == '.') {
  46. for (int dir = 0; dir < 4; ++dir) {
  47. int cnt = 0;
  48. {
  49. int x = i, y = j;
  50. for (int l = 0; l < k - 1; ++l) {
  51. x += dx[dir];
  52. y += dy[dir];
  53. if (x < 0 || x >= n || y < 0 || y >= n || s[x][y] != 'X') {
  54. break;
  55. }
  56. cnt++;
  57. }
  58. }
  59. {
  60. int x = i, y = j;
  61. for (int l = 0; l < k - 1; ++l) {
  62. x += dx[dir + 4];
  63. y += dy[dir + 4];
  64. if (x < 0 || x >= n || y < 0 || y >= n || s[x][y] != 'X') {
  65. break;
  66. }
  67. cnt++;
  68. }
  69. }
  70. if (cnt >= k - 1) {
  71. ok = true;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. cout << (ok == true ? "YES" : "NO") << endl;
  78. }
  79. return 0;
  80. }
Time limit exceeded #stdin #stdout 5s 528896KB
stdin
Standard input is empty
stdout
Standard output is empty