fork download
  1. //TITLE :
  2. //DATE:
  3. //Platform:
  4. import java.io.*;
  5. import java.math.*;
  6. import java.util.*;
  7. class Solution
  8. {
  9. public static int temp=0,k;
  10. public static void main (String[] args)throws IOException
  11. {
  12. try{
  13. int t=Integer.parseInt(br.readLine());
  14. while(t!=0)
  15. {
  16. temp=0;
  17. String ip[]=new String[2];
  18. ip=br.readLine().split(" ");
  19. int n=Integer.parseInt(ip[0]);
  20. k=Integer.parseInt(ip[1]);
  21.  
  22. char arr[][]=new char[n][n];
  23.  
  24. int i,j;
  25. i=0;
  26. while(i<n){
  27. String st=br.readLine();
  28. for(j=0;j<n;j++){
  29. arr[i][j]=st.charAt(j);
  30. }
  31. i++;
  32. }
  33.  
  34. checkrow(arr,n);
  35. if(temp==1)
  36. System.out.println("YES");
  37. else{
  38. checkcol(arr,n);
  39. if(temp==1)
  40. System.out.println("YES");
  41. else{
  42. checkmaind(arr,n);
  43. if(temp==1)
  44. System.out.println("YES");
  45. else{
  46. checkantid(arr,n);
  47. if(temp==1)
  48. System.out.println("YES");
  49. else
  50. System.out.println("NO");
  51. }
  52. }
  53. }
  54. t--;
  55. }
  56.  
  57. }catch(Exception e)
  58. {return;}
  59. }
  60. public static void checkrow(char a[][], int n){
  61. int i,j,count=0,free=0;
  62. for(i=0;i<n;i++){
  63. count=0;
  64. free=0;
  65. for(j=0;j<n;j++){
  66. if(a[i][j]=='X')
  67. count++;
  68. if(a[i][j]=='O')
  69. count=0;
  70. if(a[i][j]=='.'){
  71. free++;
  72. count++;
  73. }
  74. if(free>1){
  75. count=1;
  76. free=1;
  77. }
  78. if(count==k){
  79. temp=1;
  80. return;
  81. }
  82. }
  83. }
  84. }
  85. public static void checkcol(char a[][], int n){
  86. int i,j,count=0,free=0;
  87. for(i=0;i<n;i++){
  88. count=0;
  89. free=0;
  90. for(j=0;j<n;j++){
  91. if(a[j][i]=='X')
  92. count++;
  93. if(a[j][i]=='O')
  94. count=0;
  95. if(a[j][i]=='.'){
  96. free++;
  97. count++;
  98. }
  99. if(free>1){
  100. count=1;
  101. free=1;
  102. }
  103. if(count==k){
  104. temp=1;
  105. return;
  106. }
  107. }
  108. }
  109. }
  110. public static void checkmaind(char a[][], int n){
  111. int i,j,count=0,free=0,p=0;
  112. for(p=n-1;p>=-(n-1);p--){
  113. free=0;
  114. count=0;
  115. for(i=0;i<n;i++){
  116.  
  117. for(j=0;j<n;j++){
  118. if((i-j)==p){
  119. if(a[j][i]=='X')
  120. count++;
  121. if(a[j][i]=='O')
  122. count=0;
  123. if(a[j][i]=='.'){
  124. free++;
  125. count++;
  126. }
  127. if(free>1){
  128. count=1;
  129. free=1;
  130. }
  131. if(count==k){
  132. temp=1;
  133. return;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. public static void checkantid(char a[][], int n){
  141. int i,j,count=0,free=0,p=0;
  142. for(p=0;p<=(2*n-2);p++){
  143. free=0;
  144. count=0;
  145. for(i=0;i<n;i++){
  146.  
  147. for(j=0;j<n;j++){
  148. if((i+j)==p){
  149. if(a[j][i]=='X')
  150. count++;
  151. if(a[j][i]=='O')
  152. count=0;
  153. if(a[j][i]=='.'){
  154. free++;
  155. count++;
  156. }
  157. if(free>1){
  158. count=1;
  159. free=1;
  160. }
  161. if(count==k){
  162. temp=1;
  163. return;
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }//class
  171. //status:
  172.  
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty