Advertisement
vov44k

t200

Feb 1st, 2023
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class t200 {
  4.     static Scanner in = new Scanner(System.in);
  5.     static int n = in.nextInt();
  6.     static int [][] a = new int [n+2][n+2];
  7.     static int k = 1;
  8.    
  9.     public static void dfs(int s, int e) {
  10.         a[s][e] = 0;
  11.         if(a[s-1][e] == 1) {
  12.             k++;
  13.             dfs(s-1, e);
  14.         }
  15.         if(a[s+1][e] == 1) {
  16.             k++;
  17.             dfs(s+1, e);
  18.         }
  19.         if(a[s][e-1] == 1) {
  20.             k++;
  21.             dfs(s, e-1);
  22.         }
  23.         if(a[s][e+1] == 1) {
  24.             k++;
  25.             dfs(s, e+1);
  26.         }
  27.        
  28.        
  29.     }
  30.    
  31.    
  32.     public static void main(String[] args) {
  33.         String command;
  34.         for (int i = 1; i < n+1; i++) {
  35.             command = in.next();
  36.             char [] chArray = command.toCharArray();
  37.             for (int j = 0; j < n; j++) {
  38.                 if(chArray[j] == '.')
  39.                     a[i][j+1] = 1;
  40.                 else
  41.                     a[i][j+1] = 0;
  42.             }
  43.            
  44.         }
  45.        
  46.         int s = in.nextInt();
  47.         int e = in.nextInt();
  48.         dfs(s, e);
  49.         System.out.println(k);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement