fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Main
  9. {
  10. static char map[][] = new char[7][7];
  11. static ArrayList<String>checked = new ArrayList<>();
  12.  
  13. static public void set(){
  14. Scanner sc = new Scanner(System.in);
  15. for(int i = 0;i<7;i++){
  16. String st = sc.nextLine();
  17. for(int j = 0;j<7;j++){
  18. map[i][j] = st.charAt(j);
  19. }
  20. }
  21. }
  22. public static void search(ArrayList<String>now,ArrayList<String>next){
  23. for(String s:now){
  24. String st[] = s.split(" ");
  25. int x = Integer.parseInt(st[1]);
  26. int y = Integer.parseInt(st[0]);
  27. j_s(x+1,y,next);
  28. j_s(x,y+1,next);
  29. j_s(x-1,y,next);
  30. j_s(x,y-1,next);
  31.  
  32. }
  33. }public static void j_s(int a,int b,ArrayList<String>next){
  34. if(0<=a&&a<7&&0<=b&&b<7){
  35. if(!next.contains(a+" "+b)&&map[b][a]=='o'){
  36. next.add(a+" "+b);
  37. }
  38. }
  39. }
  40.  
  41. public static void set_now(ArrayList<String>now,ArrayList<String>next){
  42. now.clear();
  43. for(String s:next){
  44. now.add(s);
  45. }
  46. }
  47. public static void main (String[] args) throws java.lang.Exception
  48. {
  49. set();
  50. map[0][0] = 'o';
  51. map[3][3] = 'o';
  52. int day = 0;
  53. ArrayList<String>now = new ArrayList<>();
  54. now.add(0+" "+0);
  55. checked.add("0 0");
  56. while(day<15){
  57. day++;
  58. ArrayList<String>next= new ArrayList<>();
  59. search(now,next);
  60. if(next.contains("3 3")){
  61. System.out.println("yes");break;
  62. }if(next.size()==0||day==15){
  63. System.out.println("no");break;
  64. }set_now(now,next);
  65. }
  66. }
  67. }
Success #stdin #stdout 0.12s 29492KB
stdin
*oxxooo
oooooxo
oxxxxoo
oxo*xox
oooxxox
xxoooox
oooxxoo
stdout
no